-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: AG-UI adapter (toolsets) #2101
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
base: toolsets
Are you sure you want to change the base?
Conversation
PR Change SummaryImplemented the AG-UI adapter for seamless integration with the AG-UI protocol, enhancing user interaction capabilities for PydanticAI agents.
Modified Files
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
caddcc0
to
6671164
Compare
Hey! I know this is still a draft, but have been following the development of ag-ui support since I wish to build my MVP with pydantic-ai & ag-ui. Did a test run today on this branch, dropping my findings in case they are helpful:
|
Great info, keep it coming! |
a391a93
to
2995d59
Compare
There's been some changes on toolset PR, which this depends on and has been updated, can you retest to see if these are fixed now @dorukgezici |
@stevenh concurrent tool calls worked well now! |
2995d59
to
78da22f
Compare
Could you clarify what you mean by wasn't aware of the tool? Do you mean an AG-UI tool wasn't available? |
78da22f
to
1bad3e5
Compare
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.
@stevenh Looking good! Left some questions and suggestions
|
||
# Enums. | ||
# TODO(steve): Remove this and all uses once https://github.com/ag-ui-protocol/ag-ui/pull/49 is merged. | ||
class Role(str, Enum): |
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.
I think we can drop this and just hard-code string values, they're defined as Literals on the event classes so they're type-checked for validity anyway
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.
We could but that results in repeated values, which is less efficient. I was hoping we could get these eliminated before we merge.
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 we get them eliminated even better, but if not we prefer literals as @Viicos explained here: #2024 (comment)
examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.py
Outdated
Show resolved
Hide resolved
1db1afb
to
639d60b
Compare
639d60b
to
d8c6cb5
Compare
examples/pydantic_ai_ag_ui_examples/api/predictive_state_updates.py
Outdated
Show resolved
Hide resolved
633ee32
to
5170a39
Compare
examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.py
Outdated
Show resolved
Hide resolved
caefce5
to
f33c0c5
Compare
AG-UI adapter enabling integration with the AG-UI protocol via the Agent.to_ag_ui() method. This includes a full example for all features in the AG-UI dojo. Fixes: ag-ui-protocol/ag-ui/issues/5
Move pydantic_ai_ag_ui to pydantic_ai_slim as ag_ui, updating references and documentation accordingly.
Refactor to_ag_ui so it now returns a ASGI compatible server based off starlette. This makes it easier for users setup apps with minimal code. Fix some invalid references missed in the package refactor for cli and examples. Made enums, and exceptions private to the package, so they are not exposed in the public API.
Eliminate the use of match statement and dataclass(kw_only=True) to ensure compatibility with Python 3.9. Remove duplicate import of starlette outside try block, causing tests to fail when it's not installed.
Disable the deprecation warning for model_fields in Mistral.
Remove invalid no cover comment from Mistral model flagged by strict-no-cover check.
Add support for the new tool call returns and thinking parts to the AG UI adapter. This eliminates the need to build a message snapshot while sill providing the necessary information for the UI.
Allow the agent path to be specified when using to_ag_ui.
Reduce the log level for the request done message in the AG-UI adapter to debug level.
Add missing `from __future__ import annotations` imports to ensure ensure that only relevant type annotations are processed at runtime. Fix incorrect import of `dataclass` in `args.py`.
Switch from additional tools to the new toolset system.
* Update examples to use `to_ag_ui` * Use relative imports where appropriate * Remove `path` and `logger` parameters from `to_ag_ui` and dependencies * Clean up import failure messages * Improve FastAGUI doc comment * Use `PrefixedToolset` eliminating manual tool prefixing * Use CallToolsNode to handle tool calls Also make StateDeps more strict, to avoid runtime failures.
Add some no cover pragmas in existing code to avoid coverage check failure. Correct raise to avoid resetting traceback in `AgentGraph`.
* Split out coverage fixes to separate PRs * Rename FastAGUI to AGUIApp * Add thinking part delta test * Remove example agent helper * Use dedent to help create clean instructions * Remove logging from examples * Restore explicit re-raise variable * Eliminate agent_to_ag_ui * Ensure user toolsets are not overwritten incorrectly * Use temporary vars to reduce repetitive indirection * Raise ToolCallNotFoundError if tool result without matching call
Update to support the new `toolsets` behaviour which is now additional instead of replacing the existing toolsets.
* Remove logging * Remove load_dotenv * Make Agent private * Remove unnecessary type hints * Use 422 instead of 400 for validation errors
Switch the tests from TestModel to FunctionModel, which only needs less changes to provide the same functionality. Also use `IsStr`` and `snapshot`` to improve test readability and maintainability. This adds `ThinkingPart`` support to the `FunctionModel` via the new `DeltaThinkingCall` class.
f33c0c5
to
cc1b6cb
Compare
AG-UI adapter enabling integration with the AG-UI protocol via the Agent.to_ag_ui() method.
This includes examples for all features in the AG-UI dojo.
Fixes: ag-ui-protocol/ag-ui#5