Skip to content

Add Pydantic AI Durable Capability Example#552

Draft
nvasiu wants to merge 1 commit into
mainfrom
pydantic-ai-durable-capability
Draft

Add Pydantic AI Durable Capability Example#552
nvasiu wants to merge 1 commit into
mainfrom
pydantic-ai-durable-capability

Conversation

@nvasiu

@nvasiu nvasiu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Pydantic AI Durable Agent

A Pydantic AI agent as a Lambda durable function. Each model request and tool
call is checkpointed as a durable step.

  • lambda_durability.py — the LambdaDurability capability.
  • pydantic_ai_agent.py — the durable handler and agent.
  • pydantic-ai-agent.zip — prebuilt deployment package (built for the Lambda
    python3.13 / x86_64 runtime).

Requires an execution role with durable execution and bedrock:InvokeModel
permissions, and Bedrock access for PYDANTIC_AI_MODEL
(default us.amazon.nova-micro-v1:0).

Deploy

aws lambda create-function \
  --function-name pydantic-ai-agent \
  --runtime python3.13 \
  --handler pydantic_ai_agent.handler \
  --role <ROLE_ARN> \
  --zip-file fileb://pydantic-ai-agent.zip \
  --timeout 300 --memory-size 1024 \
  --environment '{"Variables":{"PYDANTIC_AI_MODEL":"us.amazon.nova-micro-v1:0"}}' \
  --durable-config '{"ExecutionTimeout":3600,"RetentionPeriodInDays":7}' \
  --region us-east-1

aws lambda wait function-active --function-name pydantic-ai-agent --region us-east-1
aws lambda publish-version --function-name pydantic-ai-agent --region us-east-1

Invoke

aws lambda invoke \
  --function-name pydantic-ai-agent:1 \
  --invocation-type Event \
  --payload '{"prompt":"What is the weather in Vancouver?"}' \
  --region us-east-1 /dev/stdout

aws lambda get-durable-execution \
  --durable-execution-arn "<DurableExecutionArn>" --region us-east-1

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

# is not recorded as failed.
async def call_tool():
try:
return {"retry": False, "value": await handler(args)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value from handler may not be serializable.

step_ctx = contextvars.copy_context()

def on_done(task):
if task.exception():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future will not be resolved if this call raises an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants