Add Pydantic AI Durable Capability Example#552
Conversation
| # is not recorded as failed. | ||
| async def call_tool(): | ||
| try: | ||
| return {"retry": False, "value": await handler(args)} |
There was a problem hiding this comment.
Return value from handler may not be serializable.
There was a problem hiding this comment.
To keep this demo simple, tool results are just assumed to be JSON serializable.
In the future we'll add a per-tool config to allow users to specify custom SerDes for each tool.
3c5d118 to
e8d8d74
Compare
There was a problem hiding this comment.
what is this zip for?
rather than check in a zip to github, where it will increase the size of a git clone forever more, can we make this a script instead? A script to make the zip?
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio |
There was a problem hiding this comment.
ruff F401 — unused import asyncio at test/pydantic_ai_agent/test_pydantic_ai_agent.py:5. Auto-fixable.
| ) | ||
| def test_pydantic_ai_agent_runs_in_cloud(durable_runner): | ||
| if durable_runner.mode != "cloud": | ||
| pytest.skip("Pydantic AI Bedrock example only runs in cloud mode") |
There was a problem hiding this comment.
the durable_runner fixture calls pytest.fail("handler is required for local mode tests"), so strictly speaking this is dead code, I think?
| assert deserialize_operation_payload(result.result) | ||
| operation_names = {operation.name for operation in result.operations} | ||
| assert any(name and name.startswith("model.request") for name in operation_names) | ||
| assert any(name and name.startswith("tool.") for name in operation_names) |
There was a problem hiding this comment.
might be handy to have a test where the agent actually suspends mid-run and then succeeds on a later invocation by replaying its checkpointed model and tool steps.
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— theLambdaDurabilitycapability.pydantic_ai_agent.py— the durable handler and agent.pydantic-ai-agent.zip— prebuilt deployment package (built for the Lambdapython3.13/x86_64runtime).Requires an execution role with durable execution and
bedrock:InvokeModelpermissions, and Bedrock access for
PYDANTIC_AI_MODEL(default
us.amazon.nova-micro-v1:0).Deploy
Invoke
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.