docs/capabilities/overview.md
A capability is a reusable, composable unit of agent behavior. Instead of threading multiple arguments through your Agent constructor — instructions here, model settings there, a toolset somewhere else, a history processor on yet another parameter — you can bundle related behavior into a single capability and pass it via the [capabilities][pydantic_ai.agent.Agent.init] parameter.
Capabilities can provide any combination of:
This makes them the primary extension point for Pydantic AI. Whether you're building a memory system, a guardrail, a cost tracker, or an approval workflow, a capability is the right abstraction.
Capabilities can be always-on or loaded by the model on demand. The capability index below spans Pydantic AI itself and Pydantic AI Harness, third-party packages provide many more, and you can define your own, declaratively or by subclassing. To run agents durably across failures, restarts, and long waits, see Durable Execution.
Capabilities come from two packages, and they all compose, with each other and with your own. Core (pydantic-ai) ships the capabilities that require model or framework support: provider-native tools, provider APIs, and deep loop integration. Pydantic AI Harness, the official capability library and harness for Pydantic AI, ships everything else, from single capabilities to complete agents. The Package column says which; every entry links to its documentation.
Complete agent stacks as regular combined capabilities: one import gives you a working agent, and you can take either apart into the blocks below.
| Harness | Package | What it provides |
|---|---|---|
| Coder | Harness | A complete coding-agent stack: files, shell, repo context, planning, a read-only explorer sub-agent, and context controls |
| Researcher | Harness | A complete web-research stack: search, page fetching, a delegated sub-researcher, and bounded tool output |
The workspace the agent acts in: the files it edits and the commands it runs, local or isolated.
| Capability | Package | What it does |
|---|---|---|
| FileSystem | Harness | Read, write, edit, search files under a root; path-traversal and symlink safe, secrets read-only |
| Shell | Harness | Command execution with allowlists, denylists, timeouts, and credential-stripping |
| Modal Sandbox | Harness | Commands and files in an isolated Modal cloud sandbox |
Connections to systems outside the agent's workspace, and abilities the provider executes natively.
| Capability | Package | What it does |
|---|---|---|
| MCP | Core | Connect any MCP server's tools; local by default, provider-native connectors opt-in |
| Image Generation | Core | Generate and edit images; provider-native where supported, sub-agent fallback elsewhere |
| Native Tool | Core | Register any provider-native tool with the agent |
| StackOne | Harness | Act on linked SaaS accounts (HRIS, ATS, CRM, …) via StackOne |
| LocalStack | Harness | An emulated AWS environment with AWS CLI tools |
| Macroscope | Harness | Run a local Macroscope code review and hand the findings to the agent |
Finding and reading things on the open web.
| Capability | Package | What it does |
|---|---|---|
| Web Search | Core | Provider-native search where available, local DuckDuckGo fallback everywhere |
| Web Fetch | Core | Fetch and read URLs, native or local |
| X Search | Core | Search X; native on xAI, subagent fallback elsewhere |
| Exa Search | Harness | Web research via Exa: excerpted search, full-page reads, opt-in cited deep search |
| Exa Agent | Harness | Delegate open-ended research to the Exa Agent API |
| Browser Use | Harness | Hand web tasks to an autonomous browser-use agent driving a real browser |
How the agent thinks and divides the work.
| Capability | Package | What it does |
|---|---|---|
| Thinking | Core | Provider-adaptive extended thinking at configurable effort |
| Planning | Harness | Model-owned task plans with a cache-safe live reminder |
| Subagents | Harness | Delegate self-contained tasks to named child agents |
| Dynamic Workflow | Harness | The model orchestrates sub-agents from one Python script: fan-out, chain, vote in a single tool call, with hard max_agent_calls budgets |
| Advisor | Harness | Let an executor consult a stronger model mid-run |
How the agent spends its context window: the difference between an agent that degrades over a long run and one that doesn't, and between paying for tokens N times or once.
| Capability | Package | What it does |
|---|---|---|
| Code Mode | Harness | The model writes one Python script that calls many tools inside a Monty sandbox: one round-trip instead of N, and intermediate results never enter the context window |
| Tool Search | Core | Load tool definitions on demand instead of carrying hundreds in every prompt |
| Compaction | Core | Provider-native compaction on OpenAI and Anthropic; the provider summarizes history server-side |
| Compaction | Harness | Model-agnostic strategies: tool-result clearing, sliding-window trimming, LLM summarization, tiered; all window-relative, with live usage reporting |
| Tool Output Limits | Harness | Truncate, spill to a queryable file, or summarize oversized tool returns at the source |
| Warn On Cache Busts | Harness | Detect prompt-cache prefix collapses between requests, from the provider's own numbers |
What the agent knows and remembers, loaded when relevant instead of carried in every prompt.
| Capability | Package | What it does |
|---|---|---|
| Memory | Harness | A persistent, namespaced notebook: bounded prompt injection, on-demand search; in-memory/file/Postgres stores |
| Conversation Search | Harness | BM25 search over stored history, including turns compaction dropped |
| Skills | Harness | Load Agent Skill (SKILL.md) instructions on demand |
| Repo Context | Harness | Start runs oriented: AGENTS.md/CLAUDE.md + repository structure |
| Pydantic AI Docs | Harness | On-demand Pydantic AI documentation lookup |
Bounding what the agent may do, and keeping it on-instructions.
| Capability | Package | What it does |
|---|---|---|
| Guardrails | Harness | Validate/block/redact user input, tool calls, tool results, and output, including secret masking and parallel async guards |
| Spend Limits | Harness | Cross-window USD/token budgets and per-response cost tracking, per model and per tenant |
| Tool approval | Core | Flag tool calls that need human approval before they run |
| Handle Deferred Tool Calls | Core | Resolve approval-deferred tool calls programmatically |
| System Reminders | Harness | Cache-safe re-injection of guidance mid-run to counter instruction fade |
| Capability | Package | What it does |
|---|---|---|
| Capability Creation | Harness | The agent writes, validates, and persists new capabilities during a run, loaded on the next run: self-extension with typed, inspectable units instead of arbitrary code |
Outside the loop: how runs persist, survive failures, and get observed and configured in production.
| Capability | Package | What it does |
|---|---|---|
| Durable execution | Core | Runs that survive restarts and failures on Temporal, DBOS, or Prefect, with Restate, Kitaru, and Airflow integrations |
| Step Persistence | Harness | Save, restore, resume (continue_run), and fork (fork_run) runs; file/SQLite/Mongo backends |
| Instrumentation | Core | OpenTelemetry GenAI spans for every model and tool call; the raw material for Logfire traces |
| Managed Prompt | Harness | Back instructions with a Logfire-managed prompt; version and roll out without redeploying |
| Thread Executor | Core | Run sync tools on a shared thread pool |
Core also ships capabilities for customizing the agent loop itself, mostly for production servers:
| Capability | Package | What it does |
|---|---|---|
| Hooks | Core | Decorator-based lifecycle hook registration |
| Select Model | Core | Select a static or per-step model with a callable |
| Resolve Model ID | Core | Resolve custom, application-specific model IDs with a callable |
| Prepare Tools / Prepare Output Tools | Core | Filter or modify function and [output tool][pydantic_ai.output.ToolOutput] definitions per step |
| Prefix Tools | Core | Wrap a capability and prefix its tool names |
| Include Tool Return Schemas | Core | Include return type schemas in tool definitions sent to the model |
| Set Tool Metadata | Core | Merge metadata key-value pairs onto selected tools |
| Raise Content Filter Error | Core | Raise [ContentFilterError][pydantic_ai.exceptions.ContentFilterError] whenever a model response has finish_reason='content_filter' |
| Reinject System Prompt | Core | Reinject the configured system prompt when the incoming message history is missing one |
| Process History | Core | Wrap a history processor |
| Process Event Stream | Core | Forward agent stream events to a handler function |
The authoring primitives, [Capability][pydantic_ai.capabilities.Capability] for bundling behavior without subclassing and [Toolset][pydantic_ai.capabilities.Toolset] for wrapping an [AbstractToolset][pydantic_ai.toolsets.AbstractToolset], are covered below. ACP (experimental, Harness) serves any agent to editors like Zed over the Agent Client Protocol. Capabilities that can be declared in YAML/JSON agent specs are listed there.
from pydantic_ai import Agent
from pydantic_ai.capabilities import Thinking, WebSearch
agent = Agent(
'anthropic:claude-fable-5',
instructions='You are a research assistant. Be thorough and cite sources.',
capabilities=[
Thinking(effort='high'),
WebSearch(local='duckduckgo'),
],
)
Instructions and model settings are configured directly via the instructions and model_settings parameters on Agent (or [AgentSpec][pydantic_ai.agent.AgentSpec]). Capabilities are for behavior that goes beyond simple configuration — tools, lifecycle hooks, and custom extensions. They compose well, especially when you want to reuse the same configuration across multiple agents or load it from a spec file.
CapabilityYou don't need a subclass to define a capability of your own: [Capability][pydantic_ai.capabilities.Capability] bundles instructions, function tools, and toolsets declaratively — think of it as defining a skill:
from pydantic_ai import Agent
from pydantic_ai.capabilities import Capability
refunds = Capability(
id='refunds',
description='Use for refund eligibility and refund status.',
instructions='Always confirm the order ID before issuing a refund.',
)
@refunds.tool_plain
def refund_status(order_id: str) -> str:
"""Look up the refund status for an order."""
return f'Order {order_id}: refund issued on 2026-05-01.'
agent = Agent('openai:gpt-5.6-sol', capabilities=[refunds])
Add defer_loading=True and the bundle becomes an on-demand capability that stays collapsed to a one-line catalog entry until the model loads it — the same shape as Agent Skills, which you can wrap in a Capability directly. See The Capability convenience class for the full API. For behavior beyond instructions, tools, and toolsets — lifecycle hooks, model settings, native tools — subclass [AbstractCapability][pydantic_ai.capabilities.AbstractCapability] as covered in Building Custom Capabilities.
[WebSearch][pydantic_ai.capabilities.WebSearch], [WebFetch][pydantic_ai.capabilities.WebFetch], [ImageGeneration][pydantic_ai.capabilities.ImageGeneration], [XSearch][pydantic_ai.capabilities.XSearch], and [MCP][pydantic_ai.capabilities.MCP] each cover a single capability (web search, URL fetch, image generation, X search, MCP) across two implementations:
| Capability | Local fallback | Notes |
|---|---|---|
[WebSearch][pydantic_ai.capabilities.WebSearch] | local='duckduckgo' or local=True (DuckDuckGo) | Requires the duckduckgo optional group |
[WebFetch][pydantic_ai.capabilities.WebFetch] | local=True (markdownify-based fetch) | Requires the web-fetch optional group |
[ImageGeneration][pydantic_ai.capabilities.ImageGeneration] | Subagent via fallback_model= | Delegates to a model that supports native image generation |
[XSearch][pydantic_ai.capabilities.XSearch] | Subagent via fallback_model= | No default non-xAI fallback; set fallback_model to an xAI model that supports [XSearchTool][pydantic_ai.native_tools.XSearchTool] |
[MCP][pydantic_ai.capabilities.MCP] | Direct connection to the MCP server (the default) | Accepts any [MCPToolset][pydantic_ai.mcp.MCPToolset] input; transport is auto-detected from a URL |
Because these capabilities contribute model-facing tools, their id, description, and defer_loading fields are meaningful: set them when that tool should stay hidden until the model loads the matching workflow with the load_capability tool. This includes [ImageGeneration][pydantic_ai.capabilities.ImageGeneration] when image generation should only be available for an image-specific workflow, whether it resolves to a native image tool or a fallback subagent tool.
Configure each side via the native= and local= kwargs. native= accepts True (use the capability's default native tool instance), False (disable native), or an explicit instance like WebSearchTool(...) for fine-grained config. local= accepts True (the bundled local fallback, on capabilities that have one — WebSearch and WebFetch), False (disable local), a named strategy string where supported, or any callable, [Tool][pydantic_ai.tools.Tool], or [AbstractToolset][pydantic_ai.toolsets.AbstractToolset]. Optional installs needed for the local fallback are opt-in — the capability raises a [UserError][pydantic_ai.exceptions.UserError] at construction (with an install hint) when you ask for a local strategy whose extra isn't installed.
from pydantic_ai import Agent
from pydantic_ai.capabilities import MCP, ImageGeneration, WebFetch, WebSearch, XSearch
agent = Agent(
'anthropic:claude-fable-5',
capabilities=[
# Native when supported; DuckDuckGo fallback on unsupported models
WebSearch(local='duckduckgo'),
# Native when supported; markdownify-based fallback on unsupported models
WebFetch(local=True),
# Native when supported; subagent fallback via `fallback_model`
ImageGeneration(fallback_model='openai:gpt-5.6-sol'),
# Native on xAI; on other models, explicitly delegate to an xAI model
XSearch(fallback_model='xai:grok-4.3'),
# Runs the MCP server locally by default; pass `native=True` to also advertise native MCP
MCP('https://mcp.example.com/api'),
],
)
MCP defaults the other way from the others: because MCP carries credentials, it runs locally by default and you opt into native MCP with native=True. The others default to native and you opt into local with local=.
[XSearch][pydantic_ai.capabilities.XSearch] is slightly different from [WebSearch][pydantic_ai.capabilities.WebSearch] and [WebFetch][pydantic_ai.capabilities.WebFetch]: there is no default non-xAI fallback. If your agent is not running on an xAI model, set fallback_model explicitly to an xAI model that supports [XSearchTool][pydantic_ai.native_tools.XSearchTool].
Some constraint fields require the native tool (the bundled local fallback can't enforce them) — passing them locks the capability to the native path. If the model doesn't support the native tool, the capability raises a [UserError][pydantic_ai.exceptions.UserError].
# Limit to 5 searches per run — requires native (the local fallback can't track call count)
WebSearch(max_uses=5)
# Only fetch example.com — enforced locally when native is unavailable
WebFetch(allowed_domains=['example.com'], local=True)
All five capabilities are subclasses of [NativeOrLocalTool][pydantic_ai.capabilities.NativeOrLocalTool], which you can use directly or subclass to build your own provider-adaptive tools. For example, to pair [CodeExecutionTool][pydantic_ai.native_tools.CodeExecutionTool] with a local fallback:
from pydantic_ai.native_tools import CodeExecutionTool
from pydantic_ai.capabilities import NativeOrLocalTool
cap = NativeOrLocalTool(native=CodeExecutionTool(), local=my_local_executor)
Third-party packages publish capabilities of their own — see Third-Party Capabilities for the ecosystem, and Publishing capabilities for making your own capability available to others.