Research date · May 6, 2026
Generated with AI

Error Handling in AI Agent Frameworks

A multipart guide. Production agent runs fail in many more ways than the four buckets the frameworks themselves design around. This index orients you across five chapters that, between them, cover what actually breaks in production — and what each framework does (or doesn't do) about it.

The five chapters

Pick a chapter by where the failure originates. Frameworks have native machinery for some; others are mostly an operational concern.

CHAPTER 1 · IN-LOOP

Inside the agent loop

The four failure modes the frameworks themselves are built around — what happens during a single agent run.

  • Tool calls fail (exceptions, 5xx, schema mismatch)
  • LLM sends incorrect / malformed response
  • Hallucination (made-up tools, args, facts)
  • Context overflow (input too large)
Read Chapter 1 →
CHAPTER 2 · PROVIDER-SIDE

When the model provider misbehaves

Failures upstream of your code — the LLM API rate-limits, refuses, disconnects, or expires your auth.

  • Rate limits (HTTP 429) and burst spikes
  • Provider outages / 5xx
  • API-key expiration & auth rotation
  • Content-moderation refusals
  • Streaming disconnects mid-response
  • Output truncation (max-tokens hit)
Read Chapter 2 →
CHAPTER 3 · MULTI-AGENT

Multi-agent specific failures

Cycles, deadlocks, and state inconsistency that only show up when agents call agents.

  • Cyclic handoffs (A → B → A → …)
  • Deadlocks & spinning supervisors
  • State inconsistency across branches
  • Recursion / iteration limits as the last guard
Read Chapter 3 →
CHAPTER 4 · OPERATIONAL

Operational failures

Failures in the boring layer beneath the agent — budgets, infra, and cancellation.

  • Cost / token-budget exhaustion
  • Infrastructure (DB, cache, OOM, network)
  • User cancellation & caller timeouts
  • Throughput throttling (RPM)
Read Chapter 4 →
CHAPTER 5 · DATA & COMPLIANCE

Data & compliance failures

Bad inputs from upstream and outputs that violate policy. Mostly an ingress / egress concern.

  • Bad upstream input (malformed, encoded badly)
  • PII leaking into prompts or outputs
  • Output policy violations
  • Where each framework's hooks help — and where they don't
Read Chapter 5 →

At-a-glance — what's framework-handled vs. operational

Every chapter dives deeper, but here's the shorthand. ● = native machinery, ◐ = partial / opt-in, ○ = defer to your operational tooling.

Failure LangChain LangGraph CrewAI Google ADK Semantic Kernel Best handled at
Tool call fails ● handle_tool_error · v1 ToolRetryMiddleware ● ToolNode.handle_tool_errors ● max_retry_limit ● on_tool_error_callback ◐ filter try/except Framework
LLM bad output ● OutputFixingParser / RetryOutputParser ● ValidationNode ● parse() + corrective re-prompt ● on_model_error_callback ◐ auto-function-invocation filter Framework
Hallucination ○ ○ ◐ Task.guardrail(s) ○ ○ Your validators / RAG
Context overflow ● trim_messages · SummarizationMiddleware ◐ pre_model_hook + trim_messages ● respect_context_window auto-summarize ● CompactionRequestProcessor ● ChatHistoryReducer Framework
Provider 429 / outage ◐ v1 ModelRetryMiddleware / Fallback ◐ RetryPolicy on agent node ◐ RPMController only ◐ on_model_error_callback ○ default no retry Gateway / LLM router
Auth expiration ○ ○ ○ ○ ○ Secret manager
Streaming disconnect ○ ○ ○ ● live-API session resumption ○ Framework / gateway
Cyclic handoffs ◐ max_iterations=15 ● recursion_limit ● max_iter=25 ◐ per-agent iteration caps ● TerminationStrategy.maximum_iterations Framework
Cost / token budget ● v1 ModelCallLimitMiddleware ○ ◐ max_iter as a proxy ○ ○ Cost gateway / budget guard
Infra failures ○ ○ ○ ○ ○ Platform / k8s
User cancellation ◐ async cancellation ◐ task cancel via Pregel ○ ◐ CancellationToken-style ● CancellationToken Framework
PII / compliance ● v1 PIIMiddleware ○ ○ ○ ○ Pre-processor / Presidio