Bounding Autonomous Agents with Stopping Conditions and Least Privilege
This lesson describes the controls that bound what an agent can do, how long it can run and how failures are contained, since agents can loop, run up costs, call tools wrongly or take unintended actions.
Learning outcomes
After completing this lesson, you will be able to:
- Define stopping conditions for agent loops.
- Apply timeouts and circuit breakers to tools.
- Restrict agents with IAM resource boundaries.
Stopping conditions
Every agent loop needs explicit stopping conditions: the goal is achieved, a maximum number of iterations or tool calls is reached, a token or cost budget is exhausted, the same tool is called repeatedly with the same arguments (a loop), or a wall-clock limit passes. In Step Functions, a counter and Choice state enforce limits, and the state machine's TimeoutSeconds caps total duration. Frameworks such as Strands Agents and Bedrock Agents also enforce limits on iterations. When a limit is hit, the agent returns a controlled response or escalates to a human.
The following diagram lists what went wrong with a runaway research agent and the safeguards that address it.

When should the loop stop?
Timeouts and circuit breakers
An autonomous agent can wait indefinitely for a tool that hangs, or retry a failing dependency again and again, consuming tokens and time without making progress. Timeouts prevent this and should apply at every level: SDK client read timeouts on model calls, Lambda function timeouts on tools, Task state timeouts and heartbeats in Step Functions, and an overall limit on the length of an agent session. When a timeout occurs, a Catch handler returns a structured error to the model, so it can choose another approach, or ends the workflow gracefully with a clear message.
Circuit breakers handle repeated failures. After a set number of failures within a time window, the circuit opens and further calls to that tool or model fail immediately for a cooling-off period, instead of waiting for another timeout. The agent stops burning tokens on a broken dependency, the dependency gets time to recover, and the application can fall back to an alternative or tell the user that the capability is temporarily unavailable.
IAM resource boundaries
An agent should be able to do only what its purpose requires. Its execution role and each tool's role grant least privilege: invoke only specific models, read only specific buckets or tables, write only through approved APIs. Permissions boundaries cap the maximum permissions any role created for agents can have. Resource-based policies and conditions (for example on tags or source VPC endpoints) add further limits. Read tools and write tools are separated so that write tools can require approval. Policy controls on tool calls, such as AgentCore Policy, can evaluate each call against rules before it runs.
The following table summarises the safeguards.
| Risk | Safeguard |
|---|---|
| Infinite loops | Maximum iterations; repeated-call detection |
| Runaway cost | Token and cost budgets per session; model choice |
| Slow tools or models | Lambda and SDK timeouts; Step Functions timeouts |
| Failing dependency | Circuit breaker and fallback |
| Excessive access | Least privilege roles; permissions boundaries; separate write tools |
| Harmful or irreversible actions | Human approval; guardrails; policy checks on tool calls |
Limiting what an agent can do
A runaway agent
A research agent ran for six hours overnight, made 3,000 search tool calls on the same query and consumed a month's token budget.
Several safeguards were missing. The fix adds a maximum of 25 tool calls per task, detection of repeated identical calls, a per-session token budget, a two-hour session timeout, a circuit breaker on the search tool (which was returning errors) and a CloudWatch alarm on token usage per session.
Which IAM feature caps what an agent's role can do, even if broader policies are attached later?
Show answer
A permissions boundary, which sets the maximum permissions the role can have.
Exam Tips
Remember for the exam
- Every agent loop needs iteration, token and time limits.
- Timeouts on SDK clients, Lambda tools and workflow states.
- Least privilege roles and permissions boundaries limit agent reach.
- Circuit breakers stop retrying broken tools.