Skip to content

Commit d9feb52

Browse files
committed
Refactoring
1 parent 0871ac7 commit d9feb52

File tree

14 files changed

+274
-239
lines changed

14 files changed

+274
-239
lines changed

examples/pydantic_ai_examples/chat_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def options_chat():
9696
@app.post('/api/chat')
9797
async def get_chat(request: Request, database: Database = Depends(get_db)) -> Response:
9898
return await VercelAIAdapter[Deps].dispatch_request(
99-
chat_agent, request, deps=Deps(database, 123)
99+
request, agent=chat_agent, deps=Deps(database, 123)
100100
)
101101

102102

pydantic_ai_slim/pydantic_ai/ag_ui.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ async def handle_ag_ui_request(
9696
A streaming Starlette response with AG-UI protocol events.
9797
"""
9898
return await AGUIAdapter[AgentDepsT].dispatch_request(
99-
agent,
10099
request,
100+
agent=agent,
101101
deps=deps,
102102
output_type=output_type,
103103
message_history=message_history,
@@ -112,7 +112,7 @@ async def handle_ag_ui_request(
112112
)
113113

114114

115-
async def run_ag_ui(
115+
def run_ag_ui(
116116
agent: AbstractAgent[AgentDepsT, Any],
117117
run_input: RunAgentInput,
118118
accept: str = SSE_CONTENT_TYPE,
@@ -153,8 +153,8 @@ async def run_ag_ui(
153153
Yields:
154154
Streaming event chunks encoded as strings according to the accept header value.
155155
"""
156-
adapter = AGUIAdapter(agent=agent, request=run_input)
157-
async for event in adapter.encode_stream(
156+
adapter = AGUIAdapter(agent=agent, run_input=run_input, accept=accept)
157+
return adapter.encode_stream(
158158
adapter.run_stream(
159159
output_type=output_type,
160160
message_history=message_history,
@@ -168,6 +168,4 @@ async def run_ag_ui(
168168
toolsets=toolsets,
169169
on_complete=on_complete,
170170
),
171-
accept=accept,
172-
):
173-
yield event
171+
)

pydantic_ai_slim/pydantic_ai/agent/abstract.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,8 @@ def to_ag_ui(
999999
*,
10001000
# Agent.iter parameters
10011001
output_type: OutputSpec[OutputDataT] | None = None,
1002+
message_history: Sequence[_messages.ModelMessage] | None = None,
1003+
deferred_tool_results: DeferredToolResults | None = None,
10021004
model: models.Model | models.KnownModelName | str | None = None,
10031005
deps: AgentDepsT = None,
10041006
model_settings: ModelSettings | None = None,
@@ -1045,6 +1047,8 @@ def to_ag_ui(
10451047
output_type: Custom output type to use for this run, `output_type` may only be used if the agent has
10461048
no output validators since output validators would expect an argument that matches the agent's
10471049
output type.
1050+
message_history: History of the conversation so far.
1051+
deferred_tool_results: Optional results for deferred tool calls in the message history.
10481052
model: Optional model to use for this run, required if `model` was not set when creating the agent.
10491053
deps: Optional dependencies to use for this run.
10501054
model_settings: Optional settings to use for this model's request.
@@ -1080,6 +1084,8 @@ def to_ag_ui(
10801084
agent=self,
10811085
# Agent.iter parameters
10821086
output_type=output_type,
1087+
message_history=message_history,
1088+
deferred_tool_results=deferred_tool_results,
10831089
model=model,
10841090
deps=deps,
10851091
model_settings=model_settings,

0 commit comments

Comments
 (0)