Skip to content

Conversation

@samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Sep 16, 2025

To do:


This adds support for Vercel AI Elements streams to Pydantic AI.

There's an example frontend in a separate repo github.com/pydantic/pydantic-ai-chat the plan is to either make that into a more complete template, or release a pydantic-ai-chat python library which contains a pre-built react frontend.

@DouweM we should rename this to use the proper terminology of the "Vercel AI Data Stream Protocol"

Here's a demo of basic usage:

pydantic-ai-chat.mp4

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

Docs Preview

commit: e770176
Preview URL: https://b30d1e83-pydantic-ai-previews.pydantic.workers.dev

@DouweM DouweM self-assigned this Sep 16, 2025
@edwinjosechittilappilly

This would be a wonderful addon, looking forward to see it soon in main.

@edwinjosechittilappilly

@samuelcolvin can you add it to docs such that it would be integrated as chat service in existing Fullstack apps that uses pydantic-ai as Agent stack.

Copy link

@183amir 183amir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this! I left some comments on the code and I will try to test this and get back.

@DouweM DouweM added this to the October 2025 milestone Sep 30, 2025
DouweM added 3 commits October 8, 2025 10:19
# Conflicts:
#	examples/pydantic_ai_examples/chat_app.py
#	pydantic_ai_slim/pydantic_ai/agent/abstract.py
#	pydantic_ai_slim/pydantic_ai/run.py
@DouweM DouweM changed the title Vercel AI Elements types Support Vercel AI Data Stream Protocol Oct 8, 2025
@DouweM DouweM enabled auto-merge (squash) October 29, 2025 22:24
@DouweM DouweM merged commit e300251 into main Oct 29, 2025
30 checks passed
@DouweM DouweM deleted the vercel-ai-chat branch October 29, 2025 22:32
jhammarstedt added a commit to jhammarstedt/pydantic-ai that referenced this pull request Nov 18, 2025
Implements a classmethod to convert Pydantic AI messages to AG-UI format,
providing the reverse operation of the existing load_messages() method.

This addresses PR pydantic#3068 feedback to use the new AGUIAdapter pattern
introduced in PR pydantic#2923 instead of a standalone function.

Changes:
- Add AGUIAdapter.dump_messages() classmethod in ui/ag_ui/_adapter.py
- Create helper functions: _convert_request_part(), _convert_response_parts(), _get_builtin_tool_call_id()
- Handle all message part types: UserPromptPart, SystemPromptPart, ToolReturnPart, RetryPromptPart, TextPart, ToolCallPart, BuiltinToolCallPart, BuiltinToolReturnPart, ThinkingPart
- Use part.model_response_str() for tool return content
- Use part.args_as_json_str() for tool call arguments
- Use part.model_response() for retry prompt content
- Combine ToolCallPart and BuiltinToolCallPart handling using BaseToolCallPart
- Handle text flow interruption by builtin tools (add \n\n separator)
- Skip ThinkingPart in message history conversion
- Add comprehensive test coverage with 3 new tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModelRetry bug with pydantic AI, AG-UI, and Open AI

9 participants