Skip to content

feat: Pydantic AI support #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2025
Merged

Conversation

stevenh
Copy link
Contributor

@stevenh stevenh commented Jun 26, 2025

Add support for the Pydantic AI integration.

Add missing background change confirmation.

Increase agentic generation ui page size to allow it to display results from the Pydantic AI integration better.

Add a description for the human in the loop generate_task_steps tool, so the Pydantic AI example works as expected.

Merge write_document and confirm_changes tool into one, which allows it work correctly with the Pydantic AI example, without the need for the agent to perform two separate tool calls.

Sort the features, so they are easier to find when reading the code and implementing new integrations.

Fixes: #5

@frederikhendrix
Copy link

How far allong is this fully functioning for PydanticAI? When can we expect it to be added to the supported Frameworks?

@stevenh
Copy link
Contributor Author

stevenh commented Jul 6, 2025

Making good progress @frederikhendrix, have been working with the pydantic-ai team to layer it on top of the new toolset support they are adding. It got a review Friday and I'll be working on addressing the feedback next week. You can follow along here.

@frederikhendrix
Copy link

Thank you for letting me know @stevenh . Can users expect that once this is done they can use "CopilotKit" for the UI, AG-UI as the bridge between frontend and API and Pydantic-AI as their AI model running in for example a FastAPI project. I notice missing documentation from a lot of these "open-source frameworks" in relation to building the full stack using these options.

In my mind I think they empower eachother. And it would be amazing if this is how it could work.

@stevenh
Copy link
Contributor Author

stevenh commented Jul 7, 2025

Yes this PR plus the one on the PydanticAI side provide end to end examples using the dojo which uses copilotkit on the client side

@tylerslaton tylerslaton moved this to In progress in Road Map Jul 10, 2025
@tylerslaton tylerslaton removed this from Road Map Jul 10, 2025
@stevenh stevenh force-pushed the feat/pydantic-ai branch 3 times, most recently from d3a2bd8 to e802fdb Compare July 11, 2025 10:37
@stevenh stevenh marked this pull request as ready for review July 17, 2025 18:45
@stevenh
Copy link
Contributor Author

stevenh commented Jul 17, 2025

@mme @maxkorp @NathanTarbert we're looking to get PydanticAI PR merged very shortly so would be good get some eyes on this.

@stevenh stevenh force-pushed the feat/pydantic-ai branch from e802fdb to 439448f Compare July 17, 2025 21:12
@maxkorp
Copy link

maxkorp commented Jul 18, 2025

I'd like to get approval from @mme as well, but all in all this looks really good and everything works nicely for me.

@stevenh stevenh force-pushed the feat/pydantic-ai branch 2 times, most recently from 54996ee to 0f7dc73 Compare July 18, 2025 10:09
@stevenh stevenh requested a review from DouweM July 18, 2025 10:22
@stevenh stevenh force-pushed the feat/pydantic-ai branch 4 times, most recently from 8797709 to 87a2a31 Compare July 18, 2025 10:32
@stevenh stevenh force-pushed the feat/pydantic-ai branch from 87a2a31 to 7c87799 Compare July 18, 2025 10:43
@stevenh stevenh changed the title feat: PydanticAI support feat: Pydantic AI support Jul 18, 2025
@stevenh stevenh force-pushed the feat/pydantic-ai branch from 7c87799 to c72eb0c Compare July 18, 2025 11:57
@DouweM
Copy link

DouweM commented Jul 18, 2025

The Pydantic AI side of this has been merged! pydantic/pydantic-ai#2223

Copy link

@maxkorp maxkorp Jul 18, 2025

Choose a reason for hiding this comment

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

Ok so this does in fact break the langgraph versions of this demo. Is this necessary? Is there a way to implement the Pydantic demo to work with this how it is without the change? After talking with @mme I think we'd prefer to leave this demo alone if it's not strictly necessary (and if it is, let's figure out why). I'm happy to help here or pair up if needed.

Copy link

Choose a reason for hiding this comment

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

CC @DouweM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a few issues, it's been a while so some may have already been addressed.

Looking at it again now this is what I recall:

  1. Requiring the LLM to perform multiple tool calls for a single action was unreliable
  2. Missing description, required strong server side prompts to correct the behaviour, compounded the above
  3. Confirmation dialog remained active, allowing user to click multiple times
  4. AG-UI isn't actually advertising a write_document tool, all the other examples appeared to hard coding it to get around this.

The most important one is 4, as without the tool being advertised Pydantic AI won't know the tool exists. It's possible we could fake it like the others, but that doesn't feel like the right way to go.

Copy link

Choose a reason for hiding this comment

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

Huh, ok. Let me roll that back locally and try playing with it a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it helps, I just reverted the name change locally and set a breakpoint on the line 264 of pydantic_ai_slim/pydantic_ai/ag_ui.py in the python if run_input.tools: inspected the provided tools and confirmed AG-UI is not advertising write_document.

Copy link

Choose a reason for hiding this comment

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

Ok after digging a bit, the changes do for sure break the langgraph demo, but the Pydantic demo doesn't seem to work at all with or without them, which I could have sworn it was before.

If I ask it "write a few sentences about cheese" it will just write them out to the chat box, it never updates the markdown field state or offers to accept/reject.

Copy link
Contributor Author

@stevenh stevenh Jul 19, 2025

Choose a reason for hiding this comment

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

Update with some observations after a debugging session with Max last night.

  • Confirmed that other integrations have manually hardcoded their tool use for the state prediction example
  • langraph is always sending a state snapshot at the end of run which doesnt always correspond to the in flight status.
  • langraph requires special handling on the client side which ideally wouldn't be the case as it means you can't just swap out the backend, which is one of the potential benefits of AG-UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxkorp have a look at the latest change, I renamed the existing local tools to have an _local prefix and restored the confirm_changes tool, so existing examples should continue to work until they are updated to use the AG-UI defined tool.

stevenh added 2 commits July 21, 2025 13:18
Add support for the Pydantic AI integration.

Add missing background change confirmation.

Increase agentic generation ui page size to allow it to display results
from the Pydantic AI integration better.

Add a description for the human in the loop generate_task_steps tool, so
the Pydantic AI example works as expected.

Merge write_document and confirm_changes tool into one, which allows it
work correctly with the Pydantic AI example, without the need for the
agent to perform two separate tool calls.

Sort the features, so they are easier to find when reading the code and
implementing new integrations.

Fixes: ag-ui-protocol#5
Revert the sorting of features, as per review feedback.
@stevenh stevenh force-pushed the feat/pydantic-ai branch from ea756c0 to 06c2e79 Compare July 21, 2025 12:18
@stevenh stevenh force-pushed the feat/pydantic-ai branch from 06c2e79 to 3c2c471 Compare July 22, 2025 17:25
Fix predictive state examples by renaming the `write_document` tool to
`write_document_local` and updating the metadata accordingly. This
ensures that the examples correctly reflect the intended functionality
of the predictive state updates, while still allowing the Pydantic AI
example to leverage the AG-UI defined `write_document` tool.

Restore the `confirm_changes` tool to enable the confirmation of
changes for existing examples.
@stevenh stevenh force-pushed the feat/pydantic-ai branch from 3c2c471 to fc29b33 Compare July 22, 2025 17:27
Copy link

@maxkorp maxkorp left a comment

Choose a reason for hiding this comment

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

Beautiful, thanks for all of the hard work!

@maxkorp maxkorp merged commit 2554a8d into ag-ui-protocol:main Jul 22, 2025
2 checks passed
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.

PydanticAI support
4 participants