Design an Agent for Incident Root Cause Analysis
Understanding the Problem
🚨 What is an incident root cause analysis agent? When a production alert fires, an on-call engineer spends the first part of the incident gathering context: what changed, which service is actually broken, what the errors say, whether this happened before. An RCA agent does that gathering automatically. It queries logs, metrics, traces and change history, forms hypotheses about the cause, backs each one with evidence, and suggests remediations from the team's runbooks, which a human approves before anything runs.
You may get this as "logs to root cause to remediation suggestions," "design an AIOps agent," or, in fintech interviews, "design an agent that investigates payment reconciliation breaks." They share a shape: a lot of machine data, an LLM that's good at reading it and forming explanations, and actions where a mistake is expensive. The answer to all of them is the same split: the agent investigates and proposes; deterministic code and humans decide and act. We'll design the incident version and show how the same design covers reconciliation.
Functional Requirements
Core Requirements
- When a page fires, the system should automatically start an investigation, gathering logs, metrics, traces, recent deploys and config changes for the affected services.
- On-call engineers should get a summary with ranked root-cause hypotheses, each linked to the evidence behind it, within minutes, and be able to ask follow-up questions.
- The agent should propose remediations (roll back a deploy, turn off a feature flag, scale up, fail over) from a catalog of known actions; they run only after human approval and within deterministic limits.
- The system should learn from past incidents: retrieve similar incidents and their postmortems, and take feedback on its own accuracy.
Below the line (out of scope)
- Building the observability stack itself. We'll assume logs, metrics, traces and a deploy log already exist (see Metrics Monitoring and Distributed Logging).
- Alert design and paging policy.
- Fully autonomous remediation without humans.
Non-Functional Requirements
Ask about the size of the estate. We'll assume 800 services, 50 TB of logs a day, about 10 million active metric series, sampled distributed traces, and about 60 pages a day, plus a few hundred lower-severity alerts and ad-hoc "investigate this" requests, so about 500 investigations a day.
Core Requirements
- A first useful summary should be ready within 5 minutes of the page (about when the on-call engineer has acknowledged and opened a laptop), and keep updating as evidence arrives.
- Every claim must link to the evidence behind it: the exact query, time range and result. "I don't know" is an acceptable answer; a confident wrong one is not.
- The agent is read-only by default. Any change to production goes through an action catalog with limits, a human approval and an audit log.
- The system must keep working during big outages, when it's most needed and when the infrastructure around it is degraded, and must not overload the observability backends it queries.
- Logs contain customer data and secrets. Data sent to the model must be redacted, and users see only what their own access allows.
Below the line (out of scope)
- Multi-cloud and on-prem collectors.
- Root-causing incidents in third-party SaaS dependencies beyond reading their status pages.
The arithmetic says the agent can't simply read the data:
- 50 TB a day is about 580 MB per second of logs. A busy service might produce several TB a day, so hundreds of GB per hour. At roughly 4 bytes per token, one hour of one big service's logs is tens of billions of tokens. Even just its error lines can be hundreds of millions.
- An investigation is maybe 30 tool calls and a few hundred thousand tokens in total. At an assumed $3 per million input tokens, that's around $1 per investigation, or about $500 a day. Compared with the cost of an hour of outage or an hour of five engineers' time, token cost hardly matters.
- What does matter is query load. 30 queries per investigation is fine normally, but during a large outage 50 alerts can fire in a minute. Fifty independent investigations each running 30 heavy log scans would hit the log store at exactly the moment it's under the most stress.
The two conclusions shape everything: the agent must work from aggregates and targeted queries, never raw logs, and alerts must be grouped into incidents so one outage means one investigation, not fifty.