-
Notifications
You must be signed in to change notification settings - Fork 966
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
Conversation
|
How far allong is this fully functioning for PydanticAI? When can we expect it to be added to the supported Frameworks? |
|
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. |
|
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. |
|
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 |
d3a2bd8 to
e802fdb
Compare
|
@mme @maxkorp @NathanTarbert we're looking to get PydanticAI PR merged very shortly so would be good get some eyes on this. |
e802fdb to
439448f
Compare
|
I'd like to get approval from @mme as well, but all in all this looks really good and everything works nicely for me. |
54996ee to
0f7dc73
Compare
8797709 to
87a2a31
Compare
87a2a31 to
7c87799
Compare
7c87799 to
c72eb0c
Compare
|
The Pydantic AI side of this has been merged! pydantic/pydantic-ai#2223 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @DouweM
There was a problem hiding this comment.
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:
- Requiring the LLM to perform multiple tool calls for a single action was unreliable
- Missing description, required strong server side prompts to correct the behaviour, compounded the above
- Confirmation dialog remained active, allowing user to click multiple times
- AG-UI isn't actually advertising a
write_documenttool, 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.
ea756c0 to
06c2e79
Compare
typescript-sdk/integrations/langgraph/examples/agents/predictive_state_updates/agent.py
Show resolved
Hide resolved
06c2e79 to
3c2c471
Compare
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.
3c2c471 to
fc29b33
Compare
maxkorp
left a comment
There was a problem hiding this 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!
* feat: Pydantic AI support 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 * chore: revert sorting of features Revert the sorting of features, as per review feedback. * fix: predictive state examples 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.
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