
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@ag-ui/pydantic-ai
Advanced tools
Implementation of the AG-UI protocol for [Pydantic AI](https://ai.pydantic.dev/).
Implementation of the AG-UI protocol for Pydantic AI.
For more information on the Pydantic AI implementation see the Pydantic AI AG-UI docs.
This example uses a Pydantic AI agent using an OpenAI model and the AG-UI dojo.
To run this integration you need to:
Clone the AG-UI repository
git clone https://github.com/ag-ui-protocol/ag-ui.git
Change into the typescript-sdk/integrations/pydantic-ai directory
cd typescript-sdk/integrations/pydantic-ai
Install the pydantic-ai-examples package, for example:
pip install pydantic-ai-examples
or:
uv venv
uv pip install pydantic-ai-examples
Run the example dojo server
export OPENAI_API_KEY=<your api key>
python -m pydantic_ai_examples.ag_ui
or:
export OPENAI_API_KEY=<your api key>
uv run python -m pydantic_ai_examples.ag_ui
Open another terminal in root directory of the ag-ui repository clone
Start the integration ag-ui dojo:
cd typescript-sdk
pnpm install && pnpm run dev
Select View Pydantic AI from the sidebar
This demonstrates a basic agent interaction including Pydantic AI server side tools and AG-UI client side tools.
View the Agentic Chat example.
time - Pydantic AI tool to check the current time for a time zonebackground - AG-UI tool to set the background color of the client windowWhat is the time in New York?
Change the background to blue
A complex example which mixes both AG-UI and Pydantic AI tools:
Perform the following steps, waiting for the response of each step before continuing:
1. Get the time
2. Set the background to red
3. Get the time
4. Report how long the background set took by diffing the two times
Demonstrates a long running task where the agent sends updates to the frontend to let the user know what's happening.
View the Agentic Generative UI example.
Create a plan for breakfast and execute it
Demonstrates simple human in the loop workflow where the agent comes up with a plan and the user can approve it using checkboxes.
generate_task_steps - AG-UI tool to generate and confirm stepsGenerate a list of steps for cleaning a car for me to review
Demonstrates how to use the predictive state updates feature to update the state of the UI based on agent responses, including user interaction via user confirmation.
View the Predictive State Updates example.
write_document - AG-UI tool to write the document to a windowdocument_predict_state - Pydantic AI tool that enables document state
prediction for the write_document toolThis also shows how to use custom instructions based on shared state information.
Starting document text
Bruce was a good dog,
Agent prompt
Help me complete my story about bruce the dog, is should be no longer than a sentence.
Demonstrates how to use the shared state between the UI and the agent.
State sent to the agent is detected by a function based instruction. This then validates the data using a custom pydantic model before using to create the instructions for the agent to follow and send to the client using a AG-UI tool.
View the Shared State example.
display_recipe - AG-UI tool to display the recipe in a graphical formatImprove with AIDemonstrates customised rendering for tool output with used confirmation.
View the Tool Based Generative UI example.
generate_haiku - AG-UI tool to display a haiku in English and JapaneseGenerate a haiku about formula 1
FAQs
Implementation of the AG-UI protocol for [Pydantic AI](https://ai.pydantic.dev/).
We found that @ag-ui/pydantic-ai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.