Skip to content

Pydantic AI

Pydantic AI is a Python framework for building AI agents. An agent calls a language model in a loop, invokes tools, and produces a structured result. The pydantic-ai-harness package runs these agents on AWS Lambda durable functions. It checkpoints each model request and tool call as a durable step. An interrupted or retried run resumes from the last completed step instead of starting over.

For requirements, per-tool configuration, and the full API, see the Pydantic AI AWS Lambda documentation.

Installation

pip install "pydantic-ai-harness[aws-lambda]" "pydantic-ai-slim[bedrock]"

The Durable Execution SDK requires Python 3.11 or newer.

Quick start

Add the AWSLambdaDurability capability when you build the agent. Adapt an async handler with @durable_agent_handler. @durable_execution must be the outermost decorator, because it creates the handler that Lambda invokes. durable_agent_handler raises an error if you reverse the order.

from typing import Any

from aws_durable_execution_sdk_python import DurableContext, durable_execution
from pydantic_ai import Agent

from pydantic_ai_harness.aws_lambda import AWSLambdaDurability, durable_agent_handler

agent = Agent(
    "bedrock:us.amazon.nova-pro-v1:0",
    name="support",
    capabilities=[AWSLambdaDurability()],
)


@durable_execution
@durable_agent_handler
async def handler(event: dict[str, Any], context: DurableContext) -> str:
    result = await agent.run(str(event["prompt"]))
    return result.output

Warning

Attaching the capability alone does not make a run durable. A run started outside the durable agent handler checkpoints nothing and raises no warning.