Google ADK agent loop prevention: adding a circuit breaker before your Gemini bill arrives

Google’s Agent Development Kit (ADK), released in 2025, is a Python framework for building multi-agent systems on top of Gemini. It handles agent orchestration, tool registration, and multi-agent routing with a clean declarative API. What it does not include is a runtime circuit breaker: if an ADK agent enters a tool-call loop, a handoff cycle between sub-agents, or accumulates tokens past Gemini’s context limit, ADK will keep calling the model until the task succeeds, the process crashes, or your billing quota runs out. This page shows how to intercept ADK’s Gemini calls, detect repeating patterns, enforce per-run dollar caps, and recover cleanly when the guard trips.

How ADK agents loop: the three failure modes

Adding a circuit breaker to ADK: the interception point

ADK multi-agent routing: detecting handoff cycles

ADK built-in limits vs. RunGuard

ControlADK built-inRunGuard
Max agent turnsmax_iterations parameterLoop detector fires before turn limit on repeating patterns
Per-run cost capNot supportedbudget: max_usd — fires before each Gemini call
Tool-call loop detectionNot supportedloop: repeats=3 fires on 3rd repeat of same tool call
Sub-agent routing cycle detectionNot supportedloop: max_cycle_len=4 catches A↔B routing cycles
Context-window guardException on overflow onlyPre-call ContextOverflowError before request is sent
Slack/PagerDuty alert on tripNot supportedalerts: slack_webhook or pagerduty_key

Gemini token pricing and budget calibration