BuildMidData / MLAuto-graded
Cap an agent's steps and retry flaky tools
Put a step limit on an agent loop, retry tools that fail, and return a partial result when the budget runs out.run_agent(task, model, tools, max_steps, max_tool_retries) asks the model what to do, runs the tool it picks and feeds the result back until the model answers. As shipped, a model that never answers keeps it running forever, and a tool that raises once ends the run. Make it stop at max_steps with a partial result, retry a failing tool up to the limit, and hand a tool's final error back to the model so it can still finish.35 min
python
You're done when
- When the model never answers, the agent stops at exactly
max_stepsmodel steps. - When the budget runs out, it returns
budget_exhaustedwith apartialresult instead of raising or returning nothing. - A tool that fails a couple of times and then works is retried, and the run carries on.
- A failing tool is retried exactly as many times as
max_tool_retriesallows, with no extra attempts and none skipped. - A tool that keeps failing doesn't crash the agent, and the run still finishes.
- The tool's last error reaches the model as an observation instead of being swallowed.
What it measures
Agent engineeringKnowing which limits an unattended agent loop needs and where each one goes.
AI workflow designDeciding what a useful partial result looks like and when a retry is worth it.
Operational judgementPutting a ceiling on automation and saying plainly when it's been hit.
Your environment
Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish
Start this lab
35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo