Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

Pydantic AI 2.0: How to Build a Typed Python Agent

Learn how Pydantic AI 2.0 agents combine instructions, tools, types, models, and run modes—and when capabilities, multiple agents, and observability make sense.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pydantic AI 2.0 lets Python developers define an LLM agent as a typed application component: choose a model, give it instructions and tools, optionally declare dependencies and a structured result, then select how the application runs it. Start with one agent and the simplest run mode that fits your app; add reusable capabilities or multiple agents only when the workflow calls for them.

Pydantic AI V2 became stable on June 23, 2026. The project’s releases page listed v2.54.0, dated October 2, 2026, as its latest stable release when checked on October 7, 2026. Because releases change frequently, verify the current version and pin the package version you use for an application.

As an Amazon Associate I earn from qualifying purchases.

What makes up a Pydantic AI agent?

Pydantic AI is a Python SDK, not a model or a hosted AI service. Its central Agent abstraction brings together the parts an application needs to run an LLM interaction: instructions, callable tools or toolsets, an optional output type, an optional dependency type, a model, and model settings. The official agent guide describes agents as reusable components that can be instantiated once for an application or created dynamically.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Instructions describe the agent’s role and constraints.
  • Tools let the model request application-defined actions or information.
  • Output typing is useful when downstream code needs a predictable structured result rather than free-form text.
  • Dependencies provide application context or services to the agent’s execution without baking that context into its instructions.
  • Model and settings determine which model is used and how the request is configured.

Type the inputs and outputs that matter to your application. This makes the intended contract clearer to readers, IDEs, and static type checkers. Keep the first version narrow: give the agent one job, only the tools it needs, and a structured output only if the next part of your program benefits from one.

Install Pydantic AI and choose a model provider

The official installation guide documents the standard pydantic-ai package as including core dependencies and libraries for OpenAI, Anthropic, and Google models, plus integrations such as the CLI, MCP, Evals, Web UI, and Logfire. Provider-specific setup still depends on the provider and model you select; there is no single API key or model name that applies to every configuration.

  1. Check the current installation instructions. Follow the command on the official installation page rather than assuming it has not changed.
  2. Install the package and any needed extras. For providers or integrations not included in the standard package, the guide documents extras and gives pydantic-ai[bedrock,temporal] as an example. It also describes pydantic-ai-slim for installations that select only the extras required.
  3. Configure your chosen provider. Follow that provider’s current documentation for credentials, model identifiers, and usage rules. Keep credentials in your application’s secret-management mechanism rather than embedding them in source code.
  4. Pin the version used by your project. Record the exact package version in your dependency configuration so the code you deploy does not silently track a later release.

Do not add optional integrations just because they are available. A basic agent needs a supported model connection; observability, gateway access, and other integrations depend on your operational needs.

Define the agent’s contract before adding complexity

Write down what the agent should receive, what it may do, and what your program expects back. Then encode those boundaries in the agent’s instructions, tools, dependency type, and output type as appropriate. For example, an agent that classifies an incoming request may need a constrained result type; an agent that only drafts text may not.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use dependencies for runtime context or application services that should be supplied by the calling program. Use tools for actions the model may choose to request. Neither makes an agent inherently reliable: validate consequential outputs and enforce permissions and business rules in application code, especially before a tool can change external state.

Choose how to run the agent

Pydantic AI documents several run interfaces in its agent guide. Choose based on the surrounding program and how much of the execution the caller needs to observe.

Interface Use it when What the caller gets
agent.run() Your application is asynchronous and can wait for completion. A completed result.
agent.run_sync() Your calling code needs synchronous execution. A completed result.
agent.run_stream() or agent.run_stream_sync() The interface should display generated text or structured output incrementally. Streamed output.
agent.run_stream_events() The application needs an event iterator rather than only a completed response. A stream of execution events.
agent.iter() The workflow needs stepwise access to the underlying graph. Access to execution steps.

For a basic asynchronous service, start with agent.run(). Choose streaming when a user interface benefits from showing progress as output arrives. Use iteration when step-level visibility or control is a real workflow requirement; it exposes more of the underlying execution than a typical request-response call needs.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you add capabilities or multiple agents?

Use a capability to reuse behavior

The official capabilities guide presents capabilities as composable units of behavior. A capability can provide tools, lifecycle hooks, instructions, model settings, or model selection. Simple instructions and settings can be supplied directly to an agent or agent spec; capabilities become useful when behavior goes beyond that configuration and needs to be reused or extended.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use multiple agents only when their boundaries help

The multi-agent guide describes a progression from a single-agent workflow to delegation through a sub-agent tool, programmatic hand-off in application code, and graph-based control flow for more complex coordination. Choose the least complicated pattern that gives each responsibility a clear boundary. A single agent is often easier to understand; separate agents add coordination and more paths to inspect, so use them when distinct responsibilities or explicit control flow justify that cost.

Observe execution and prepare for deployment

During development, inspect whether the agent is following the intended path, invoking the right tools, and returning the expected output. The installation guide points to Pydantic Logfire for observing agent behavior and describes a free tier; availability and terms can change. It also describes Pydantic AI Gateway as an optional way to access models from several providers with one API key. Neither service is required to build an agent.

Before deployment, check that your application handles provider errors and timeouts, validates outputs it relies on, and limits tools to actions the agent is authorized to request. Keep credentials and model configuration outside the agent’s user-facing instructions, and verify the package and provider setup against the current documentation. The official agent guide and examples are practical next steps for adapting the basic design to a specific application.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.