← LEARN

AI agent observability patterns: failure modes, defenses, and what to monitor

·11 min read

A deep dive on AI agent observability patterns — the recurring failure modes of autonomous LLM agents, the telemetry that catches them early, and the enforcement layers that stop them from cratering your bill.

Why AI agent observability needs its own playbook

Generic LLM observability — logging prompts, completions, and token counts — covers the single-call case well. AI agent observability is a different problem. Autonomous agents loop, branch, call tools, spawn sub-agents, and make spending decisions on your behalf. The unit of analysis stops being a request and becomes a session, a budget, and a behaviour pattern over time.

The patterns below are the ones that recur across LangGraph, CrewAI, AutoGen, and hand-rolled agent stacks. If your monitoring does not surface them, your first warning that something went wrong will be a billing alert from your model provider.

Pattern 1 — Loop detection and the runaway tool call

The most expensive bug in autonomous agents is the silent loop: the planner keeps deciding the same next step, the same tool fires hundreds of times, and tokens drain at the model's max throughput. The classic LangGraph variant is a router node that never advances state; the CrewAI variant is two agents handing the same task back to each other.

Observability defense: track repeated (tool_name, arguments_hash) tuples per session. Anything that fires the same call more than N times inside a sliding window is a loop until proven otherwise. The enforcement layer should be able to hard-stop the session on the next ingest call, not write a ticket for a human to read on Monday.

Pattern 2 — Budget-aware spending caps

Per-agent dollar caps are the simplest correct primitive. Per-user, per-repo, and per-tenant caps layer on top. The pattern that scales is: every ingest call carries an identity, the observer accumulates spend against that identity in real time, and the response carries an authoritative stop=true when a hard cap is breached.

Soft warnings (warn at 70%, pause at 90%, hard stop at 100%) are the production-grade version. Single-threshold alarms get ignored; tiered ones cause humans to look before the cap is hit.

Pattern 3 — Cross-provider cost normalisation

An agent that switches between OpenAI, Anthropic, and a local model mid-session will defeat any per-provider dashboard. The observability layer has to normalise on dollars, not tokens, and it has to know the current pricing of every model it sees — including GitHub Copilot AI credits, which are priced differently from raw API tokens.

Without this, a model swap from gpt-4o-mini to claude-opus during a retry can quietly multiply session cost by 50× and never trip a token-count alarm.

Pattern 4 — Prompt-injection and tool-misuse detection

Once an agent can call tools, prompt injection becomes a security event, not a content-moderation curiosity. The observability layer should classify inbound content (retrieved documents, web pages, user messages) for known injection signatures and emit a warning span the moment a suspicious payload reaches a tool-calling agent.

The enforcement counterpart is a policy that blocks tool calls originating from a flagged turn until a human approves them. Detection without enforcement is theatre.

Pattern 5 — Session replay and post-incident diagnosis

When an agent goes wrong, you need to reconstruct what it saw and what it decided, step by step. Llm observability tools that store only individual completions cannot do this. Agent observability requires a session timeline: every event, every tool call, every inter-agent message, in order, with enough payload to replay the decision.

This is also what unblocks framework-specific debugging: a LangGraph state-machine bug looks very different from a CrewAI delegation bug, and both look different from an AutoGen group-chat deadlock.

How agentwach implements these patterns

agentwach is built around exactly these five patterns. The SDK ingest call returns guardrail decisions inline, so loops and budget breaches stop on the next iteration rather than after a human reads an alert. Cross-provider spend is normalised to USD across OpenAI, Anthropic, Google, and Copilot credits. Prompt-injection detection runs on every ingest payload, and the session replay tab lets you walk any agent through its decisions one event at a time.

If you are running LangGraph, CrewAI, or AutoGen and your only monitoring today is a token dashboard, picking up these patterns is the highest-leverage upgrade you can make this quarter.