Skip to content

Add a Pydantic AI example Bot - #56

Open
andreolf wants to merge 1 commit into
CopilotKit:mainfrom
andreolf:feat/pydantic-ai-example
Open

Add a Pydantic AI example Bot#56
andreolf wants to merge 1 commit into
CopilotKit:mainfrom
andreolf:feat/pydantic-ai-example

Conversation

@andreolf

Copy link
Copy Markdown

What this changes

A third framework example beside examples/langgraph-bot and examples/mastra-bot, and the first in another language. A real Pydantic AI agent served over AG-UI: the surface's tools arrive per run in RunAgentInput.tools, Pydantic AI exposes them to the model as external tools, and their calls stream back to OpenBot to run through the governed gateway — so the process drives a browser it has no direct access to, the same contract as the Bot in the box and the two existing examples.

Worth doing because the README names Pydantic AI among the frameworks a Bot can be written in, and the strongest evidence that OpenBot is framework- and language-agnostic is a working example in a language that is not TypeScript.

Self-contained: its own pyproject.toml outside the Bun workspaces, so it does not touch the JS build. It imports the AG-UI helper from whichever module path the installed pydantic-ai exposes (pydantic_ai.ui.ag_ui in current releases, pydantic_ai.ag_ui in earlier ones) and answers /health like the other examples.

Where it runs

A customer's own agent process, exactly like langgraph-bot and mastra-bot — reached by OpenBot only as an AG-UI endpoint URL. It holds no OpenBot state; the tool loop stays on the OpenBot client.

  • New state that outlives a request? None. The agent is stateless between runs; conversation history arrives in each RunAgentInput.
  • What happens on the second replica? This is an example Bot, not an OpenBot replica. Multiple instances behind one endpoint are independent, as with the other example Bots.
  • Anything serialised? None.
  • Anything fanned out to a browser? No. It emits AG-UI events on its own response stream; it never touches an OpenBot socket.
  • New listener, port, or schedule? A dev server on PORT (default 4202), run by the developer the same way the other examples are; not part of the deployed ingress.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act. Yes — this Bot executes no tools; it emits tool calls and OpenBot runs them through the gateway, identical to the existing examples.
  • New refusals and new failures each write a row. N/A — no acting code.
  • Nothing new is trusted from the client that the server can resolve itself. N/A.

Proof

$ python3 -m py_compile examples/pydantic-ai-bot/src/app.py   # compiles

Note for reviewers: I have not yet run this against a live model end-to-end. If you'd prefer the hand-emitted @ag-ui/encoder-style SSE the TS examples use over Pydantic AI's native AG-UI app, say so and I'll switch it.

A third framework example beside LangGraph and Mastra, and the first in another
language. A real Pydantic AI agent served over AG-UI: the surface's tools arrive
per run and their calls stream back to OpenBot to run through the gateway, so the
process drives a governed browser it has no direct access to, the same contract
as the Bot in the box.

Self-contained (its own pyproject.toml, outside the Bun workspaces), imports the
AG-UI helper from whichever module path the installed pydantic-ai exposes, and
answers /health like the other examples.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant