Skip to content

Commit 019563d

Browse files
Add deps
Signed-off-by: Luis Valdes <[email protected]>
1 parent fd8be8c commit 019563d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

typescript-sdk/integrations/pydantic-ai/examples/server/api/agentic_chat.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77
from typing import Any
88
from zoneinfo import ZoneInfo
99

10-
from pydantic_ai import Agent
10+
from pydantic_ai import Agent, RunDeps
1111

1212

1313
@dataclass
14-
class ChatState:
15-
"""State handler for the agentic chat agent."""
16-
state: dict[str, Any]
14+
class State:
15+
pass
1716

1817

19-
# Create agent with proper dependency type
20-
agent = Agent('openai:gpt-4o-mini', deps_type=ChatState)
18+
@dataclass
19+
class Deps(RunDeps):
20+
"""Dependencies that implement StateHandler protocol."""
21+
state: State
2122

22-
# Create AG-UI app with default state
23-
def create_deps() -> ChatState:
24-
"""Create default dependencies for the agent."""
25-
return ChatState(state={})
2623

27-
app = agent.to_ag_ui(deps=create_deps)
24+
# Create agent with proper dependency type
25+
agent = Agent[str, Deps]('openai:gpt-4o-mini', deps_type=Deps)
26+
27+
# Create AG-UI app with proper dataclass instance
28+
deps_instance = Deps(state=State())
29+
app = agent.to_ag_ui(deps=deps_instance)
2830

2931

3032
@agent.tool_plain

0 commit comments

Comments
 (0)