Separating an AI agent from a Lambda tool handler

For an application where an AI agent can call backend tools, I would keep each Lambda handler limited to one operation with explicit input validation. The model can propose an action, but the handler should still check authorization for the current user. I would require a separate approval step for destructive operations.

Evgenii Arsentev writes about the distinction between agents and chatbots here: What Is an AI Agent? Agents vs Chatbots, Explained. This is background reading, rather than a Serverless Framework deployment tutorial.

For longer tasks, would you put the orchestration in Step Functions and use Lambda only for individual tool calls? I would be interested in how others separate retries from actions that must not run twice.

Step Functions for orchestration with Lambda only for individual tool calls is a good split. For retries, make each tool handler idempotent by taking an idempotency key from the caller and storing it in DynamoDB with a conditional write, so a retried call returns the saved result instead of running again. Let Step Functions own the retry policy (Retry with backoff and MaxAttempts) and only retry on errors you know are transient, like throttling. For destructive actions, put a manual approval step in front using a task token (waitForTaskToken), and send failures to an SQS dead-letter queue so nothing is silently replayed.

One caveat on the DynamoDB idempotency pattern: storing the saved result after the side effect still leaves a window where Lambda performs the action and then dies before writing the key, so a retry repeats it. Use the downstream service’s own idempotency key if it has one, or record an in-progress claim with a conditional write before acting and reconcile stuck claims later. Also make sure Step Functions only retries Lambda timeout or transient errors, not validation or authorization failures, and give waitForTaskToken approvals a timeout/heartbeat so tasks don’t hang indefinitely.