Skip to content

Commit 86d70b5

Browse files
ChuckJonasDouweM
andauthored
Fix: AG-UI assistant text and tool call order (#2328)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 33aaef1 commit 86d70b5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pydantic_ai_slim/pydantic_ai/ag_ui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ def _messages_from_ag_ui(messages: list[Message]) -> list[ModelMessage]:
486486
if isinstance(msg, UserMessage):
487487
result.append(ModelRequest(parts=[UserPromptPart(content=msg.content)]))
488488
elif isinstance(msg, AssistantMessage):
489+
if msg.content:
490+
result.append(ModelResponse(parts=[TextPart(content=msg.content)]))
491+
489492
if msg.tool_calls:
490493
for tool_call in msg.tool_calls:
491494
tool_calls[tool_call.id] = tool_call.function.name
@@ -502,9 +505,6 @@ def _messages_from_ag_ui(messages: list[Message]) -> list[ModelMessage]:
502505
]
503506
)
504507
)
505-
506-
if msg.content:
507-
result.append(ModelResponse(parts=[TextPart(content=msg.content)]))
508508
elif isinstance(msg, SystemMessage):
509509
result.append(ModelRequest(parts=[SystemPromptPart(content=msg.content)]))
510510
elif isinstance(msg, ToolMessage):

0 commit comments

Comments
 (0)