Long-running AI agents without waiting Lambdas: a Bedrock preview
Picture this: your team wants an AI agent to write a weekly report. The agent needs a few minutes, calls a couple of tools, thinks, calls another tool. Your platform is Serverless, built on Lambda, and nobody wants a function sitting idle while a model ponders. Until recently that meant writing and operating the agent loop yourself. With Claude Managed Agents on Bedrock, now in preview, that loop becomes a managed service inside AWS.
I built a small example around exactly this situation: a fictional bookshop that gets an agent-written sales report every Monday, driven by EventBridge Scheduler and two TypeScript Lambda functions. The complete walkthrough lives in my full article on Claude Managed Agents with Lambda. Here I want to share the ideas that matter most.
What actually changes
Classic agent code is a loop: ask the model, check whether it wants a tool, run the tool, hand back the result, repeat. Frameworks help, but you still run that loop somewhere. With Claude Managed Agents, AWS hosts the loop and Anthropic tunes it to how Claude behaves. You bring the agent definition (model, system prompt, tools), the IAM permissions and an environment where tools such as bash execute. That environment is an AgentCore Runtime container in your own account.
A few things stood out to me while setting it up:
- No Anthropic API key. Requests go to a Bedrock endpoint and are signed with SigV4. Only role credentials are accepted, so an IAM user gets a 403. For Lambda that is a non-issue, since functions always run with a role.
- Agents are versioned. Every change to the definition creates a new version, and a session is one agent working in one environment with its own history.
- Frankfurt works.
eu-central-1is among the 14 preview Regions, as long as you use model IDs with theeu.prefix and keep everything in one Region. - The setup is the hurdle. Three roles, your own container image and Region-prefixed model IDs make the first test more work than simply calling an API.
Why the API fits Serverless so well
The part I like most is that the API is asynchronous by nature. You create a session, send a message and walk away. So I split the work into two functions, the same pattern I use for asynchronous APIs with a job table:
- A starter runs on Monday morning, records a job in DynamoDB, creates the session and sends the task. Then it returns immediately.
- A collector runs every five minutes, checks each open session and acts on its state.
The clever bit is custom tools. My get_weekly_sales tool does not run in the container at all but in my own code. When the agent wants it, the session goes idle with the stop reason requires_action and simply waits. Nothing has to stay alive in between. Here is the decision logic in simplified form:
const session = await getSession(job.sessionId); if (session.status === "running") { if (minutesSince(job.startedAt) > 30) await sendInterrupt(job.sessionId); return; } const pending = await findUnansweredToolCalls(job.sessionId); if (pending.length > 0) { await answerToolCalls(job.sessionId, pending); return; } await saveReport(job, await lastAgentMessage(job.sessionId)); Because the collector compares the tool requests with the results it already sent, it stays stateless. If it runs twice or crashes halfway, the next run only answers what is still missing. And since the preview has no session budget, the collector enforces its own time limit with an interrupt.
Costs, risks and my verdict
The service itself adds no charge during the preview. You pay Claude tokens at regular Bedrock prices, the runtime duration and storage for the image and logs. Lambda, Scheduler and DynamoDB barely register in this example.
Security deserves more attention. The tool runner executes bash without a sandbox, so anything the model generates can use the container's files, network and the runtime role's credentials. Keep that role minimal, and remember that tool results end up in the model's context and can carry injected instructions.
My take: handing the agent loop to the model's maker is a sensible move, because that loop is exactly what every team builds a little differently and a little buggy. It is still a preview with real gaps (no session budget, no webhooks, IAM actions that may change), so I would not put it into production today. For a contained internal use case like a weekly report, it is well worth trying.
What the full article covers
- Setting up the service in eu-central-1 with CloudFormation, including all three roles
- A first test with curl and an agent definition with a custom tool
- SigV4 signing from Lambda without extra dependencies, plus the complete starter and collector code
- Deployment with the Serverless Framework and a table of common errors with their causes
- An FAQ on pricing, MCP servers via AgentCore Gateway and the difference from Bedrock Agents
You can find all of it, including the architecture diagram and the animated event flow, in the complete guide on sascha-ms.de.
📖 This is the condensed version. The full article on sascha-ms.de goes deeper – with all code samples, diagrams and a short knowledge check.
👉 Next step: Curious what your own Lambda functions cost? Try my Lambda cost calculator – it runs right in your browser.
📬 Stay updated: New articles on serverless, AI and leading tech teams via RSS, browser push or the weekly newsletter (in German).
Originally published on sascha-ms.de. More articles on serverless, AI in everyday development and leading tech teams: sascha-ms.de/en