Skip to content

Add Pydantic AI plugin samples - #358

Open
brianstrauch wants to merge 9 commits into
mainfrom
pydantic-ai-plugin-samples
Open

brianstrauch wants to merge 9 commits into
mainfrom
pydantic-ai-plugin-samples

Conversation

@brianstrauch

@brianstrauch brianstrauch commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add runnable Pydantic AI Temporal examples for chat, tools, stateless MCP, Workflow Streams, human approval, structured output, multiple agents, and Logfire observability
  • provide credential-free TestModel execution plus an optional Pydantic AI Gateway live mode, with the required OpenAI provider extra
  • use a standalone project and Python 3.10/3.14 CI jobs to accommodate the OpenAI SDK 3 dependency independently of the shared samples
  • register agents declaratively through PydanticAIWorkflow and PydanticAIPlugin
  • handle successive approval rounds with current message history and a fresh decision for each round
  • use released Pydantic AI >=2.46.0,<3 and Beartype >=0.23.0,<0.24, with Logfire >=4.39,<5
  • document agent isolation sandboxes as unsupported by this integration

Validation

All 15 tests pass on Python 3.10 (Pydantic AI 2.54.0) and Python 3.14 (Pydantic AI 2.55.0), including live model construction without network requests and second-round approval, rejection, and cancellation. The second-round approval regression failed before the workflow fix.

Run from pydantic_ai_plugin/:

  • uv sync --locked --all-groups
  • uv run poe lint
  • uv run poe test -q
  • uv lock --check

Root import ordering, formatting, and lockfile validation also pass.

@brianstrauch
brianstrauch requested review from a team as code owners September 2, 2026 23:52
@brianstrauch

Copy link
Copy Markdown
Member Author

We can optionally wait for beartype and pydantic releases before merging so we're not pinning commits

@brianstrauch
brianstrauch requested a review from a team as a code owner October 10, 2026 20:12
@brianstrauch
brianstrauch enabled auto-merge (squash) October 10, 2026 20:18

@DABH DABH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two issues reproduced locally: the documented live model is missing its provider dependency, and a second approval round leaves the workflow running after assertion failures. All 11 added tests pass.

Comment thread pyproject.toml Outdated
"beartype>=0.23.0,<0.24",
"logfire>=4.39,<5",
"mcp>=1.24,<2",
"pydantic-ai-slim[mcp,temporal]>=2.46.0,<3",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Include the OpenAI extra required by live mode

A clean uv sync --group pydantic-ai does not install openai, since neither the mcp nor temporal extra includes it. Consequently the documented model="gateway/openai:gpt-5.2" fails before making a request: infer_model("gateway/openai:gpt-5.2") raises an ImportError asking for the OpenAI provider dependency. This affects the live path in every sample even when PYDANTIC_AI_GATEWAY_API_KEY is set. Include the openai extra in this dependency group so the advertised live commands work.

deferred_tool_results=deferred_results,
model=input.model,
)
assert isinstance(resumed.output, str)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Handle additional approval rounds after resuming the agent

A resumed run can legitimately return another DeferredToolRequests, since delete_record remains available and still requires approval. For example, a model can request deletion of record 42, then request record 43 after receiving the first tool result. After the first approved tool runs, this assertion raises instead of exposing the next request. With the sample worker configuration, AssertionError repeatedly fails workflow tasks, leaving the execution running without a way to finish the next approval. Loop over deferred outputs until the agent returns a string, carrying forward the latest messages and clearing the decision for each new round.

@brianstrauch
brianstrauch requested a review from DABH October 12, 2026 16:54
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.

2 participants