Skip to main content
Pydantic AI · Built for the long run

Build agents that go the distance.

Give agents a workspace, a plan, memory, and subagents. Pydantic AI Harness is built for work that runs for hours, with tool and output validation to catch invalid data and durable execution to recover from interruptions.

Build with Harness Explore durable execution

Open source. MIT licensed. Your models, your infrastructure. Enterprise support for when it really matters.

A long run, with checks along the way. Illustrated workflow
Task

Research the launch. Draft a brief.
Get approval before sending.

research_agentPydantic AI + Harness
01PlanContext + memory
02ResearchTools + subagents
03ApprovalHuman decision
Tool + output checksValidate retry
Durable runtimeSave resume
returnResearchBriefsummary · sources · next steps

Give it a job that takes time.

Harness keeps a plan, workspace, and working context as the agent breaks the research into smaller tasks.

Already doing real work

Pydantic AI Harness

Give your agent a whole working environment.

Build coding and research agents with a workspace, planning, subagents, and cross-session memory. Pydantic AI Harness gives you composable capabilities for hours of work, on the same Agent API. Start with a complete harness or control each capability yourself.

Companion open source packagepydantic-ai-harness
Compose a harness · excerpt
agent = Agent(
    'openai:gpt-5.6-sol',
    capabilities=[
        Coder(),
        Memory(FileStore('.memory')),
    ],
)

Coder() brings the workspace, planning, and subagents. Memory() adds knowledge across sessions.

Full runnable example

Run in a workspace the agent may edit. Install pydantic-ai-harness[cli], pydantic-ai-slim[openai], and logfire, and set OPENAI_API_KEY.

harness_agent.py
from pydantic_ai import Agent
from pydantic_ai_harness import (
    Coder, Memory,
)
from pydantic_ai_harness.memory import (
    FileStore,
)
import logfire

logfire.configure(
    send_to_logfire='if-token-present',
)
logfire.instrument_pydantic_ai()

agent = Agent(
    'openai:gpt-5.6-sol',
    capabilities=[
        Coder(),
        Memory(FileStore('.memory')),
    ],
)

# Chat with the agent in your terminal.
agent.to_cli_sync()
Start from a complete harness

Use Coder or Researcher, then add, replace, or remove capabilities.

Coder Researcher Build your own
Long-running agents

A restart shouldn’t restart the work.

A research job takes hours. An approval takes until tomorrow. A worker disappears halfway through. Run your Pydantic AI agent on a durable backend to preserve progress and continue the workflow.

Choose a durable runtime
One job, across interruptionsExample execution
  1. WorkResearch + tools

    Save progress in the durable backend.

  2. WaitRequest approval

    The workflow can wait for a human decision.

  3. RecoverRestore after restart

    The runtime recovers the persisted workflow.

  4. ContinueFinish the job

    Resume the agent with the approved result.

Persistence and recovery provided by your durable runtime

Also integrates with Kitaru and Apache Airflow through third-party backends.

Why Pydantic for the long run

Catch errors before the next step depends on them.

Long runs turn one result into the next step’s input. Pydantic AI validates tool arguments and structured outputs, then sends validation errors back to the model so it can retry. Define the checks your workflow has to pass before it continues.

  • Validate the handoff. Give tools and subagents explicit input and output contracts.
  • Correct while the run is in progress. Return useful validation feedback and retry within the limits you set.
  • Apply your own judgment. Use validators, tool guardrails, and human approval for application-specific decisions.
See validation and retries
Choose your model

OpenAI · Anthropic · Google · Bedrock · Mistral · Groq · Ollama

Explore providers and fallbacks
Request a correction · excerpt
@agent.output_validator
def require_sources(
    brief: ResearchBrief,
) -> ResearchBrief:
    if not brief.sources:
        raise ModelRetry(
            'Cite your sources.'
        )
    return brief
Missing sources?

The model gets Cite your sources. and another attempt within your retry budget.

Full example + offline test

Install pydantic-ai and logfire, plus pytest for the tests. Set OPENAI_API_KEY to run the agent. The tests use a local model double; Logfire export is optional.

from pydantic import BaseModel
from pydantic_ai import (
    Agent, ModelRetry, RunContext,
)
import logfire

logfire.configure(
    send_to_logfire='if-token-present',
)
logfire.instrument_pydantic_ai()

class ResearchBrief(BaseModel):
    summary: str
    sources: list[str]
    follow_up: list[str]

agent = Agent(
    'openai:gpt-5.6-sol',
    deps_type=list[str],
    output_type=ResearchBrief,
    defer_model_check=True,
)

@agent.tool
def read_notes(
    ctx: RunContext[list[str]],
) -> list[str]:
    """Read this customer's notes."""
    return ctx.deps

@agent.output_validator
def require_sources(
    brief: ResearchBrief,
) -> ResearchBrief:
    if not brief.sources:
        raise ModelRetry(
            'Cite your sources.'
        )
    return brief

if __name__ == '__main__':
    result = agent.run_sync(
        'Read notes. Write a brief.',
        deps=['We need a Python SDK.'],
    )
    print(result.output.summary)
Realtime audio

Same tools. Now you can talk to them.

Build a conversation that can do something. Stream speech in and out, handle interruptions, and call your backend tools during the conversation.

The session shares your agent’s dependencies, instructions, and message history. Hand the conversation to a text agent afterward to produce a structured follow-up.

Build a voice agent

OpenAI · Azure · Google Gemini · xAI

Connect your frontend or audio transport
Speech → tools → actionIllustrated conversation
You

“Can you move my booking to Friday?”

Tool callcheck_availability(day="Friday") 7 pm available
Agent

“There’s a table at seven. Shall I move it?”

After the callConversation history typed follow-up
The rest of the engineering

Ship it. Test it. See what happens.

Open source · Pydantic Evals

Make quality a release check.

Build datasets, score the behavior that matters, and compare runs when prompts, models, or tools change.

Evaluate your agents
Optional platform · Logfire

Understand the whole run.

Follow model calls, tool calls, and application work in one trace. Investigate latency, costs, and failures with the context around them.

See agent observability
Optional service · AI Gateway

Control provider access and spend.

Route model requests through a shared gateway with spend controls. Keep the agent code and the operational policy separate.

Explore AI Gateway
OpenTelemetry throughout

Use Logfire for the closest integration, or send traces to your existing OpenTelemetry backend.

Instrumentation docs
From teams building with it

Readable enough to make it your own.

With Pydantic AI you have everything there readable. You have Python, it runs on Pydantic Graph. So this is also something I like. The graph is open and understandable.
Eric Charles, Founder & CEO, Datalayer Read the case study
A few practical questions

Choose the pieces your application needs.

Is Pydantic AI free to use?

Pydantic AI and Pydantic AI Harness are open source under the MIT license. You pay your model providers and hosting services. Logfire and AI Gateway are optional Pydantic products with their own pricing.

When should I add Pydantic AI Harness?

Use Harness for coding, research, and other multi-step jobs that need a workspace, planning, delegation, memory, and context management. Start with Coder or Researcher, or compose individual capabilities on any Pydantic AI agent.

Can an agent survive a process restart?

Yes, when you run it with a durable execution backend. Pydantic AI integrates with Temporal, DBOS, Prefect, Restate, and AWS Lambda durable functions, with additional third-party integrations. The backend owns persistence and recovery; a standard in-memory Agent run does not persist itself.

Can the same tools work in a voice agent?

Realtime sessions use Pydantic AI tools, dependencies, instructions, and message history. Your application connects the microphone, speaker, or browser transport. The conversation can then continue as a text-agent run for a structured follow-up.

Do I need Logfire or AI Gateway?

You can call model providers directly and export OpenTelemetry traces to a compatible backend. Logfire adds agent views, traces, evals, and production diagnostics. AI Gateway adds shared provider access and operational controls.

Give it the whole job.

Build your next agent with Harness.

Your workspace. Your model. Your rules.