Agent Exceptions and Graceful Fallback Strategies in ADK
Where exceptions actually surface in an ADK run — tools, callbacks, model calls — and how to design fallbacks that degrade quality deliberately instead of crashing the conversation.
Published on • November 25, 2026
AI Assistant

An agent failure is qualitatively different from a web request failure. A 500 to a browser is invisible a moment later; an unhandled exception inside an agent run can strand a half-written session, leave the user staring at a spinner, or worse — leak a raw stack trace through the model’s next message. Reliability work in ADK is mostly about deciding, in advance, which layer catches which failure and what the user sees afterward.
Where exceptions actually surface
There are four distinct failure zones in a run, and each wants a different policy:
- Tool execution — your code, network calls, parsing. Most common.
- Model calls — provider errors, rate limits, safety blocks.
- Callbacks — before/after model, before/after agent. User code that must not take down the run.
- Framework/service layer — session store down, artifact write failed. Rare, but systemic.
ADK’s behavior differs per zone. A tool that raises doesn’t necessarily kill the run: the framework can convert the failure into a tool result the model sees, letting it react (“I couldn’t fetch that — let me try another approach”). That is the single most underused reliability feature in any agent framework: errors are content.
def lookup_inventory(sku: str, tool_context) -> dict:
"""Look up inventory levels for a SKU."""
try:
return {"sku": sku, "stock": inventory_client.get(sku)}
except InventoryUnavailable as exc:
# Return a structured, model-readable failure — do not raise.
return {
"sku": sku,
"stock": None,
"error": "inventory_backend_unavailable",
"message": str(exc),
"retryable": True,
}
The model receives inventory_backend_unavailable, can tell the user honestly, and can decide whether to retry. Compare that with raising: the model gets an opaque failure (or the whole run dies) and can’t reason about it at all.
The fallback ladder
Design fallbacks as an ordered ladder — you descend only as far as the failure forces you:
Rung 1 — retry with jitter. For transient errors (timeouts, 429s, connection resets). Bounded, exponential, jittered.
async def with_retries(fn, *, attempts=3, base=0.5):
for i in range(attempts):
try:
return await fn()
except (httpx.TimeoutException, httpx.TransportError):
if i == attempts - 1:
raise
await asyncio.sleep(base * (2 ** i) * random.uniform(0.8, 1.2))
Rung 2 — degraded tool result. Return cached, partial, or stale data with an explicit marker in the payload so the model knows its answer is less certain.
Rung 3 — alternate tool or sub-agent. The primary path is down; route to the backup. This is where structured error codes from Rung 1 pay off — the router can branch on error rather than parsing prose.
Rung 4 — smaller model. If the premium model is rate-limited, drop to a cheaper one for the remainder of the turn. The agent keeps working at reduced quality.
Rung 5 — honest surrender. “I can’t complete this right now; your session is saved — try again in a minute.” Persist state, end cleanly.
The discipline is deciding the ladder before shipping, not improvising inside an except: block at 2 a.m.
Fallback at the model layer
Provider failures — rate limits, quota, transient 5xx — are worth wrapping centrally:
from google.genai import errors as genai_errors
async def resilient_generate(model, contents, config):
try:
return await model.aio.generate_content(model=model, contents=contents, config=config)
except genai_errors.ServerError:
return await fallback_model.aio.generate_content(
model=FALLBACK_MODEL, contents=contents, config=config
)
Keep this in one place — a wrapper, a plugin, or a model-connector decorator — rather than sprinkling try/except through every agent. Rate-limit errors specifically deserve a different treatment from genuine errors: honor the retry-after, shed load, or route to the alternate tier.
Callbacks must be fail-safe
Callbacks run in the middle of someone’s conversation. A bug in your observability callback should not end the user’s turn:
def telemetry_callback(callback_context, llm_response=None, **kwargs):
try:
emit_metrics(callback_context.invocation_id, llm_response)
except Exception:
logger.exception("telemetry dropped a frame") # never re-raise
# return None → let ADK's default behavior proceed
Rule of thumb: callbacks observe, they don’t decide. If a callback genuinely must gate execution, catch everything and return an explicit, intentional value — never let an accidental exception act as policy.
Session consistency when things die
An aborted run can leave the session in a plausible-but-wrong state: a state delta applied without the event that explains it, a half-finished artifact, an output_key never written. Mitigations:
- Persist intent before side effects. Write a “pending” state marker before a tool mutates an external system; clear it on success.
- Make state deltas idempotent. ADK applies deltas per event; re-running a turn should converge, not double-increment.
- Record the failure as an event. A structured failure event in the session history is invaluable for debugging and for the next turn’s model to know what just happened.
- Test the crash. Inject a
KeyboardError-style failure mid-run in a test and assert the session is still readable and the user gets a sane response.
The user-facing contract
Never surface a raw exception message — it can contain internal URLs, IDs, or credentials, and it means nothing to the person reading it. Map failure classes to human sentences:
| Internal failure | User sees |
|---|---|
TimeoutError on tool | ”That’s taking longer than expected — try again?” |
| Rate limit exhausted | ”I’ve hit a brief limit; I’ll be back in a moment.” |
| Quota/billing | ”This feature is currently paused.” |
| Validation error | A rephrasing prompt, not a schema dump |
| Unknown bug | ”Something went wrong on my end.” + incident ID |
Log the full detail server-side keyed by that incident ID; give the user the incident ID, not the stack trace.
Where to go next
Graceful degradation is easier to design once runs are properly bounded — pair this with global timeouts and execution deadlines. The context objects described here are covered in the InvocationContext lifecycle, and the full production checklist lives in enterprise ADK assistants: reliability, latency, and cost.