python Pydantic AI Releases · · 2.22.0

Pydantic-AI v2.22.0: Gemini tool mode, Anthropic system prompts, Temporal fixes

sdkaigaengineerpython-agentic
feature patch

Pydantic-AI v2.22.0 introduces several new features, including default Gemini validated tool mode and the ability to send mid-conversation system prompts natively on Anthropic. It also addresses numerous bug fixes, particularly within Temporal workflow integrations and handling of tool usage. This release impacts developers using Pydantic-AI with LLM orchestration, especially those leveraging Temporal for durable execution, and requires updating the `genai-prices` dependency.

  • Allow MCPToolset clients to skip optional MCP tasks via prefer_tasks by @adtyavrdhn in https://github.com/pydantic/pydantic-ai/pull/6851
  • Default Gemini VALIDATED tool mode on supported models by @hramezani in https://github.com/pydantic/pydantic-ai/pull/6353
  • Send mid-conversation system prompts as native system messages on Anthropic by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6765
  • Add RunContext.is_tool_available by @DouweM in https://github.com/pydantic/pydantic-ai/pull/7011
  • Handle closed event loops in synchronous APIs by @adtyavrdhn in https://github.com/pydantic/pydantic-ai/pull/6850
Features (5)
  • Allow MCPToolset clients to skip optional MCP tasks via prefer_tasks by @adtyavrdhn in https://github.com/pydantic/pydantic-ai/pull/6851
  • Default Gemini VALIDATED tool mode on supported models by @hramezani in https://github.com/pydantic/pydantic-ai/pull/6353
  • Stop advertising tool search for capability-owned deferred tools on Anthropic by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6770

  • Send mid-conversation system prompts as native system messages on Anthropic by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6765
  • Add RunContext.is_tool_available by @DouweM in https://github.com/pydantic/pydantic-ai/pull/7011
Fixes (31)
  • Handle closed event loops in synchronous APIs by @adtyavrdhn in https://github.com/pydantic/pydantic-ai/pull/6850
  • Compare full origin, not just hostname, when dropping credentials on safe_download redirects by @pydanty[bot] in https://github.com/pydantic/pydantic-ai/pull/6811

  • Fix Temporal workflow livelock when anyio scope cancellation hits an in-flight activity await by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6892

  • Copy extra_headers before setdefault in OpenAI chat and Groq models by @pydanty[bot] in https://github.com/pydantic/pydantic-ai/pull/6868
  • Support requesting approval or deferring a call from a tool's args_validator by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6897
  • Use the workflow-prepared tool_def in Temporal function-tool activities instead of re-running prepare by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6890

  • Raise a UserError instead of hanging when run_sync() is called on an event loop it cannot drive by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6905

  • Fix Prefect tool-call cache keys: replay tool results on flow retry and stop colliding on RunContext fields a tool can read by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6944

  • Run after_tool_validate when an args_validator defers the call by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6961
  • Preserve the host's Logfire configuration in the Temporal LogfirePlugin by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6962
  • Fail the workflow instead of retrying forever when a Temporal activity argument can't be serialized by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6893

  • Install the EnqueueGuard on the DBOS/Prefect model-request and cancel_suspended_response units by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6943

  • Restore typed values in a dynamic tool's Temporal ActivityConfig after the activity round trip by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6947

  • Reject unregistered Model instances in durable runs instead of re-inferring them from model_id by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6898

  • Heartbeat in tool, MCP, dynamic-toolset, and event-stream Temporal activities by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6965

  • Rehydrate sets, carry conversation_id, and hard-error on omitted fields in TemporalRunContext by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6891

  • Allow ApprovalRequired/CallDeferred from post-validation tool hooks, UserError from pre-validation ones by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6951

  • Raise a UserError when a history processor or fallback_on handler has unresolvable type annotations by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6958

  • Raise ModelAPIError for OpenRouter responses with null choices and no error envelope by @ZacharyHampton in https://github.com/pydantic/pydantic-ai/pull/6901

  • Inline every $ref to a union $def, not just the first one by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6960
  • Reject unknown ActivityConfig keys in TemporalDurability by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6964
  • Honor per-tool TaskConfig on Prefect MCP tools and add PydanticUserError to its non-retryable set by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6952

  • Pass the unprepared request to the wrapped model in InstrumentedModel by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6982
  • fix(mcp): inherit agent retries in MCPToolset.tool_for_tool_def by @hramezani in https://github.com/pydantic/pydantic-ai/pull/6449
  • Fail the workflow on HookTimeoutError and FallbackExceptionGroup instead of retrying forever by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6978

  • Keep thinking alive by not forcing tool_choice on OpenRouter anthropic/ models by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6957

  • Add configurable max_retries to ToolSearchToolset by @pydanty[bot] in https://github.com/pydantic/pydantic-ai/pull/6740
  • Fix Temporal ActivityConfig validation on Python 3.10 and 3.11 by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6989
  • Pass pydantic_graph through Temporal workflow sandboxes by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6990
  • Memoize Temporal payload TypeAdapters by @DouweM in https://github.com/pydantic/pydantic-ai/pull/7001
  • Preserve SystemPromptPart semantics across caching and Temporal by @dsfaccini in https://github.com/pydantic/pydantic-ai/pull/6984
Read the original announcement →

https://github.com/pydantic/pydantic-ai/releases/tag/v2.22.0

Related releases