Spend & Loop Caps (Budget Safety)
Autonomous agents can occasionally get caught in recursive tool-calling loops (e.g. repeatedly searching a website with slightly different keywords or trying invalid SQL queries). Without strict guardrails, this can generate massive surprise cloud bills.
Circuit Breaker Configuration
Agent Substrate includes a hard budget circuit breaker evaluated before every turn and tool dispatch:
from substrate.agents import ReActAgent
agent = ReActAgent(
model="claude-3-7-sonnet",
max_steps=25, # Terminate if loop exceeds 25 steps
max_cost_usd=5.00, # Hard dollar ceiling per session
max_tokens_per_turn=4000 # Token rate limit
)What Happens When a Limit Is Reached?
If a run reaches its $5.00 ceiling:
- Execution Halts Instantly: The next model dispatch is blocked before tokens are billed.
- Partial Result Returned: The agent returns its latest valid state with a
BUDGET_CEILING_REACHEDstatus code. - Alert Emitted: An incident event is pushed to your OpenTelemetry / Slack webhook alerting your engineering team.
Was this page helpful?