Learning resourcesReviewed · Pydantic

Pydantic AI On-Demand Capabilities

Pydantic AI's On-Demand Capabilities is a documentation guide for Python developers building AI agents with several separate workflows, showing how to keep each workflow's instructions and tools hidden until the model or application code loads it. The tradeoff is an extra model exchange when the model has to discover and load a workflow itself. It explains how defer_loading=True keeps a workflow's instructions and tools hidden until needed, then activates its settings and hooks alongside them. Cache behavior depends on the provider and tool type; the page does not measure actual token or cost savings.

Researched 15 Nov 2026

In short.

Pydantic AI's On-Demand Capabilities is a guide for Python agent developers who want workflows loaded only when needed, with extra discovery calls and provider-dependent caching as the main tradeoffs. A capability groups instructions, tools and optional settings or hooks behind a short catalog entry. The page explains configuration, history replay, loading from code and integration restrictions. Its approval-hook examples require further implementation, and the evidence establishes no measured performance, cost savings or tested security enforcement.

Researched and written by an AI model and checked by a second AI model. How it works

The scope is the complete captured page at [https://pydantic.dev/docs/ai/capabilities/on-demand/index.md], including its examples, documentation-index and query-parameter notices, instruction-trust warnings, cache caveats, history behavior, realtime restrictions and durable-execution guidance. Linked pages, blog articles, repositories and package contents are excluded. No code or integration was executed. Installation compatibility, measured savings, live-model reliability, operating costs and reuse permissions remain unestablished where the page supplies no evidence.

The overview

Resource and scope

This Pydantic AI documentation page teaches on-demand capabilities: bundles of instructions and tools, optionally accompanied by model settings and lifecycle hooks. The source is [https://pydantic.dev/docs/ai/capabilities/on-demand/index.md].

The resource includes Python examples for customer support workflows, MCP servers, grouped capabilities, Markdown skills and database runbooks. Its focus is controlling when an agent receives workflow-specific behavior.

Practical fit

The approach fits an agent with several distinct workflows when most requests need only one. A refund workflow, for example, can keep its instructions and tool definitions out of unrelated requests while remaining discoverable through a short description.

The tradeoff becomes less attractive when the same capability is needed on most turns: the page explicitly says discovery can cost more than the tokens it saves. It provides detailed implementation guidance but no measured comparison establishing where that crossover occurs.

Who it helps

Python developers maintaining agents for support, research or other separate workflows are the clearest audience. Developers with existing Pydantic AI capabilities can apply the documented loading flag without redesigning every workflow.

Beginners can follow the small refund example, although familiarity with Python functions, decorators and model tool calls will help. Experienced developers get additional detail about hooks, provider request formats, persisted conversations and durable execution engines.

What the guide covers

A deferred capability can activate instructions, function tools, model settings, lifecycle hooks and native tools as a bundle. Built-in examples include MCP, WebSearch, WebFetch and Hooks. CombinedCapability groups several capabilities behind one catalog entry; members of that deferred group cannot also be independently deferred.

The page also explains wrapping Markdown files as capabilities, reading dynamic runbooks from a database and loading a capability through application code. Capability-owned tools are never discoverable through tool search; they become available by loading their capability.

Using it

Dependencies and prerequisites

The examples require Python and a Pydantic AI release supporting the documented capability APIs. External-model examples require access to the chosen provider. Minimum Python and package versions, installation commands, authentication setup and a complete dependency specification are not supplied. The Markdown examples additionally import yaml.

Deferred capabilities need stable identifiers. The load_capability tool name is reserved when this feature is present. Resuming a conversation requires retaining load and tool-availability records and constructing the agent with the corresponding capability definitions and matching IDs. An MCP identifier derived from its URL can change when the endpoint changes, so the page recommends an explicit ID for persisted conversations.

How loading works

Initially, the model receives a catalog containing each deferred capability's ID and optional description, plus the framework's load_capability tool. It does not receive that capability's instructions or usable tool definitions. When the model requests a load, the next model request receives the instructions and newly available tools. This sequence can happen inside one agent.run_sync call.

Loaded instructions enter conversation history in a system message where supported, or through the documented fallback representation. Instruction changes are appended rather than rewriting earlier messages. Loaded capabilities remain active for the rest of the run, so their hooks and settings can affect subsequent work beyond the triggering action.

Message history records which capabilities and tools became available. Model-requested loads use their tool exchange; loads from code use CapabilityLoadDeltaPart records, with tool availability recorded through ToolAvailabilityDeltaPart. History stores the loaded state, while capability definitions remain in application code.

Configuration approach

The minimal pattern creates a Capability with an explicit id, a description explaining when to use it, instructions and defer_loading=True. Functions are attached with capability.tool or capability.tool_plain, and the capability is passed in the Agent capabilities list. Existing functions and toolsets can also be supplied through tools and toolsets.

For custom model settings, hooks, native tools or per-run logic, the page directs developers to subclass AbstractCapability. Application code can call ctx.load_capability when it already knows which workflow applies. Loading in before_run makes the bundle available on the first request without model-led discovery; loading in before_model_request has different timing for tools and instructions versus settings, native tools and hooks.

Customer support example

The combined support example defines an orders capability and an account-security capability. The intended sequence loads orders for a delivery question and account-security for a suspicious-login question. The security bundle contains instructions, a session-revocation tool, increased reasoning effort and a tool hook.

These are illustrative implementations. In the page's separate refund examples, refund_status returns a fixed string; in the support example, order_status only reads an in-memory dictionary supplied as deps. The revoke_sessions function returns confirmation text without connecting to an identity service. The security hook contains comments describing approval checks and then returns the arguments; it does not implement approval or identity verification. The printed outputs in the page's FunctionModel examples do not establish real refunds, session revocations or successful policy enforcement.

Assessment & evidence

Important limitations

Loading a runbook does not prove that the model understood or followed it. The RunbookRequired example checks whether a capability ID is loaded and raises ModelRetry otherwise; it does not programmatically enforce the example's $500 manager-approval limit or the 30-day refund window. A rule that must apply before a deferred workflow loads needs an always-on enforcement hook.

Loaded instructions receive the operator's authority. The page warns against returning uncontrolled workspace content through instruction or description functions. Database runbook writers can consequently influence the agent with that authority. Dynamic instructions that change on every request also append an update on every request.

ctx.load_capability raises a UserError where no model request follows, for example from after_model_request on a response without tool calls, from after_run, or from an output tool; a load that was queued is discarded if the tool's step ends the run instead, such as when a tool call needs approval or is deferred, or the run produces its output. In before_model_request, tools and instructions reach the request being prepared, while settings, native tools and hooks apply from the following request. Realtime sessions do not support ctx.load_capability; the page documents model-led loading there for instructions-only capabilities.

Durable execution adds restrictions. Temporal and Prefect tool functions cannot load capabilities (a UserError is raised). On DBOS, plain function tools can load them, but tools from MCP servers and dynamic toolsets cannot, and a load made inside a function decorated with @DBOS.step succeeds but is lost when DBOS recovers the workflow, because Pydantic AI cannot detect that case. Hooks provide a documented alternative. Older versions cannot read CapabilityLoadDeltaPart, and compaction must preserve load records. The page also flags forced-tool-choice cache and request failures on OpenAI Responses models before GPT-5.6 under specified history settings.

Why the tradeoff can make sense

A short workflow catalog can replace a much larger set of unused instructions and schemas. Grouping a workflow's instructions with its tools also gives the model the relevant guidance when those tools become available. This explains the design's potential value, but does not establish improved accuracy or lower cost.

The likely benefit depends on workflow frequency, bundle size, provider caching and the model's ability to choose the right catalog entry. The page mentions tool-selection pressure around 30–50 visible tools without supplying an experiment establishing a universal threshold. Tool visibility, instruction delivery and authorization should be evaluated separately.

Other approaches described

Always-on capabilities suit behavior needed on most turns because they avoid discovery. Tool search suits a flat collection of independently discoverable tools without shared workflow instructions. On-demand capabilities instead reveal an entire related bundle.

The page compares the pattern with Anthropic Agent Skills and describes the Pydantic AI Harness Skills capability as delivering instructions only. Wrapping a Markdown skill in Capability adds associated tools and can extend to settings and hooks. Comparative performance and the contents of the linked resources are not established by this page.

Evidence and its limits

The evidence is the complete captured documentation page at [https://pydantic.dev/docs/ai/capabilities/on-demand/index.md]. It contains API examples, explanations of state transitions, provider-specific cache behavior and integration restrictions.

Several demonstrations use FunctionModel to script the expected responses instead of relying on a live language model. Those examples explain intended sequencing without establishing real-model discovery reliability. Nothing was executed; runtime correctness, external integrations, performance and security enforcement remain untested.

Access & freshness

Costs and efficiency

Software charges, provider prices and total operating costs are unknown from this page. The intended saving comes from omitting unused instructions and tool schemas, while model-led loading adds another model exchange. No token totals, latency measurements, billing examples or savings benchmarks are supplied.

Prompt caching, which lets a provider reuse an unchanged request prefix, depends on what loads. The page documents prefix preservation for instructions and for function tools using supported Anthropic or OpenAI Responses reveal mechanisms. Without native reveal support, adding function tools changes the prefix once per load. Loading native tools changes the prefix on every provider. Loaded bundles remain active, so their later request overhead also matters.

Reuse rights

The supplied page contains no explicit licence or redistribution terms for its documentation or code examples. Permissions for copying, modifying or redistributing those materials are therefore unknown from this evidence. The page's public availability alone does not establish those permissions.

Date and compatibility

The page was captured on 15 November 2026 at 08:08:43 UTC. Its publication date, last substantive update and minimum compatible Pydantic AI release are not established by the supplied text.

Named model identifiers are example configurations, not evidence of current account access or availability. Compatibility with a particular installed package version, provider configuration or older saved conversation remains unknown without further verification.

How to evaluate it for your work

Begin with a small read-only workflow that is rarely needed, give it a stable ID and a clear description, and compare it with the same workflow always loaded. Check when its tools become available, then measure request count, input tokens, latency and cache behavior on your chosen provider.

For persisted agents, verify resume and compaction behavior with matching capability definitions. For code-triggered loading, check the timing and recovery restrictions of the relevant hook or execution engine. Before connecting sensitive tools, implement actual authorization and approval checks, and keep instruction sources under trusted write control.

Evidence for this report

selected-page.txtselected · checked 2026-11-15