API316: Coding an AI agent from scratch with AWS Lambda durable functions

Resources for API316: Coding an AI agent from scratch with AWS Lambda durable functions

AI agents need multi-step reasoning, tool execution, human approvals and long-running waits, and they have to keep their state when something fails. In this code talk we built an AI agent, the Expo Booth Scout, as one AWS Lambda durable function: a tool-use loop with Amazon Bedrock, retries with exponential backoff, a human approval gate that costs nothing while it waits, and polling of an external system.

This page has the slides, the demo code, and documentation for each part of the talk.

AWS Lambda durable functions

The mental model

Durable functions checkpoint each operation and replay your code after an interruption, so completed work is not run again and waits cost no compute.

The tool-use loop

Checkpointed model turns and tool calls

Each model turn and each tool call runs in context.step(), so after an interruption the agent resumes at the first unfinished step without calling the model again.

Retries with exponential backoff

Recovering from transient failures

A retry strategy on StepConfig retries a failed tool step with backoff, instead of failing the whole agent.

Serverlesspresso

Workshop

Serverlesspresso is an event-driven coffee-ordering application. The workshop builds it with AWS Lambda durable functions.

Human approval

Suspend until the attendee decides

The request_approval tool uses context.wait_for_callback(). The agent suspends with no Lambda running until the approve or reject decision arrives.

Polling an external system

Reserve the swag

The reserve_swags tool submits reservations to an asynchronous service, then uses context.wait_for_condition() to poll until every reservation is confirmed. The function suspends between polls.

Demo code repository

GitHub repo

The Expo Booth Scout agent, its web UI and the AWS SAM template, ready to deploy in your own account.

Keep learning

Workshops and more serverless

Hands-on workshops, the new Lambda form factors, and more serverless content.

Presented by:

Rana Kiziltoprak German

Rana Kiziltoprak German

Rana is a Senior Technical Account Manager at Amazon Web Services, where she helps Enterprise Support customers build scalable, cost-optimized, resilient, and secure architectures and prepare their workloads for production scale. She specializes in AWS serverless services and event-driven architectures.

Serda Kasaci Yildirim

Serda Kasaci Yildirim

Serda is a Solutions Architect at Amazon Web Services (AWS) based in Vienna, Austria.