Skip to content
VDAI with VD

Phase 19 · Capstone Projects

Capstone 06 — DevOps Troubleshooting Agent for Kubernetes

AWS's DevOps Agent went GA, Resolve AI published its K8s playbooks, NeuBird demoed semantic monitoring, and Metoro tied AI SRE to per-service SLOs. The production shape is settled: an alert webhook fires, an agent reads telemetry, walks a graph of K8s objects, ranks root-cause hypotheses, and posts a Slack brief with approval buttons. Read-only by default. Every remediation gated by a human. This capstone is that agent, evaluated on 20 synthetic incidents and compared against AWS's Agent on three shared cases.

  • Capstone
  • Python (agent), TypeScript (Slack integration)
  • 30 hours
  • Before this: Phase 11 (LLM engineering), Phase 13 (tools and MCP), Phase 14 (agents), Phase 15 (autonomous), Phase 17 (infrastructure), Phase 18 (safety)

Problem

The 2025-2026 SRE narrative became: "AI agents triage incidents, humans approve remediations." AWS DevOps Agent, Resolve AI, NeuBird, Metoro, PagerDuty AIOps all ship this shape in production. The agent reads Prometheus metrics, Loki logs, Tempo traces, kube-state-metrics, and a knowledge graph of K8s objects. It produces a ranked root-cause hypothesis with telemetry citations in under five minutes. It never executes destructive commands without explicit human approval through Slack.

Most of the hard work is scoping and safety, not reasoning. The agent needs a read-only-by-default RBAC surface, a hardened MCP tool server, and audit logs of every command considered vs executed. It needs to know when it is outside its depth and escalate. And it has to run cheap enough that OOM-kill cascades do not generate a $5k agent bill.

Concept

The agent operates on a knowledge graph. Nodes are K8s objects (Pods, Deployments, Services, Nodes, HPAs, PVCs) plus telemetry sources (Prometheus series, Loki streams, Tempo traces). Edges encode ownership (Pod -> ReplicaSet -> Deployment), scheduling (Pod -> Node), and observation (Pod -> Prometheus series). The graph is kept fresh by a kube-state-metrics sync and re-sampled on every alert.

When an alert fires, the agent root-causes from the affected object. It walks edges, pulls the relevant telemetry slices (last 15 minutes), and drafts a hypothesis. The hypothesis is ranked by evidence: how many telemetry citations support it, how recent, how specific. The top-3 hypotheses go to Slack with graph-path visualizations and approval buttons for remediation actions.

Remediation is gated. Allowed default actions are read-only. Destructive actions (scaling down, rolling back, deleting Pods) require Slack approval; ArgoCD rollback hooks require an auth token the agent never holds. The audit log records every command the agent considered — not just executed — so the review process catches near-misses.

Architecture

PagerDuty / Alertmanager webhook
           |
           v
     FastAPI receiver
           |
           v
   LangGraph root-cause agent
           |
           +---- read-only MCP tools ----+
           |                             |
           v                             v
   K8s knowledge graph              telemetry slices
     (Neo4j / kuzu)              Prometheus, Loki, Tempo
   ownership + scheduling          last 15m, scoped
           |
           v
   hypothesis ranking (evidence weight)
           |
           v
   Slack brief + approval buttons
           |
           v (approved)
   ArgoCD rollback hook / PagerDuty escalate
           |
           v
   audit log: considered vs executed, every command

Stack

  • Observability sources: Prometheus, Loki, Tempo, kube-state-metrics
  • Knowledge graph: Neo4j (managed) or kuzu (embedded) of K8s objects + telemetry edges
  • Agent: LangGraph with per-tool allow-list, read-only by default
  • Tool transport: FastMCP over StreamableHTTP; separate server for destructive tools behind approval gate
  • Models: Claude Sonnet 4.7 for root-cause reasoning, Gemini 2.5 Flash for log summarization
  • Remediation: ArgoCD rollback webhook, PagerDuty escalate, Slack approval card
  • Audit: append-only structured log (considered, executed, approved, outcome)
  • Deployment: K8s deployment with its own narrow RBAC role; separate namespace

Interactive figure coming later.

Build It

  1. Graph ingestion. Sync kube-state-metrics into Neo4j/kuzu every 30s. Nodes: Pod, Deployment, Node, Service, PVC, HPA. Edges: OWNED_BY, SCHEDULED_ON, EXPOSES, MOUNTS, SCALES. Telemetry overlay edges: OBSERVED_BY (a Pod is observed by a Prometheus series).

  2. Alert receiver. FastAPI endpoint that accepts PagerDuty or Alertmanager webhooks. Extract the affected object(s) and SLO breach.

  3. Read-only tool surface. Wrap kubectl, Prometheus query, Loki logql, Tempo traceql through FastMCP. Every tool has a narrow RBAC verb ("get", "list", "describe"). No "delete", "exec", "scale" in the default server.

  4. Root-cause agent. LangGraph with three nodes: sample pulls the last-15-minutes telemetry slice, walk queries the graph for neighboring objects, hypothesize drafts ranked root-cause candidates with telemetry citations.

  5. Evidence scoring. Each hypothesis has a score = recency * specificity * graph-path length inverse * citation count. Return top-3.

  6. Slack brief. Post an attachment with the hypothesis, the graph-path visualization (a subgraph image rendered server-side), and approval buttons for at most one remediation action.

  7. Remediation gate. Destructive tools (scale down, roll back, delete) live on a second MCP server behind an approval token. The agent can call them only after the Slack card is approved by a human.

  8. Audit log. Append-only JSONL: for every candidate command, log whether it was considered, whether it was executed, who approved it. Ship to S3 daily.

  9. Synthetic incident suite. Build 20 scenarios: OOMKill cascade, DNS flap, HPA thrash, PVC fill, noisy neighbor, faulty sidecar, bad ConfigMap rollout, certificate rotation, image-pull backoff, etc. Score the agent on root-cause accuracy and time-to-hypothesis.

Use It

webhook: alert.pagerduty.com -> checkout-api SLO breach, error rate 14%
[graph]   affected: Deployment checkout-api (3 Pods, Node ip-10-2-3-4)
[walk]    neighbors: ReplicaSet checkout-api-abc, Service checkout-api,
           recent rollout 14m ago
[sample]  prometheus error_rate 14%, up-trend; loki 500s on /api/v2/pay
[hypo]    #1 bad rollout: latest image checkout-api:v2.41 fails /healthz
          citations: deploy.yaml (rev 42), prometheus errorRate, loki 500 stack
[slack]   [ROLL BACK to v2.40]  [ESCALATE]  [IGNORE]
          (approval required; agent does not roll back unilaterally)

Ship It

outputs/skill-devops-agent.md is the deliverable. Given a K8s cluster and alert source, the agent produces ranked root-cause hypotheses and a Slack-gated remediation flow.

WeightCriterionHow it is measured
25RCA accuracy on scenario suite≥80% correct root cause across 20 synthetic incidents
20SafetyDestructive-action guard never fires without Slack approval in the audit log
20Time-to-hypothesisp50 under 5 minutes from alert to Slack brief
20ExplainabilityEvery hypothesis has graph paths and telemetry citations
15Integration completenessPagerDuty, Slack, ArgoCD, Prometheus end-to-end working
100

Exercises

  1. Run your agent on the same three incidents AWS's DevOps Agent is demo'd on. Publish the side-by-side. Report where the agent diverges.

  2. Add a "near-miss" audit that flags any command the agent considered that would have been destructive without approval. Measure the near-miss rate over one week.

  3. Swap the hypothesis model from Claude Sonnet 4.7 to a self-hosted Llama 3.3 70B. Measure RCA accuracy delta and dollar per incident.

  4. Build a causal filter: distinguish correlated telemetry spikes from a true root cause. Train a small classifier on the 20-scenario labels.

  5. Add a rollback dry-run: ArgoCD rollback against a staging cluster with the same manifest. Verify the rollback plan in a live cluster before the Slack approval button.

Key Terms

TermWhat people sayWhat it actually means
K8s knowledge graph"Cluster graph"Nodes = K8s objects + telemetry series; edges = ownership, scheduling, observation
Read-only-by-default"Scoped RBAC"Agent's service account has only get/list/describe verbs; destructive verbs live in a separate server behind approval
Audit log"Considered vs executed"Append-only record of every candidate command, whether it ran, who approved
Hypothesis ranking"Evidence score"Recency × specificity × graph-path length inverse × citation count
Slack approval card"HITL gate"Interactive Slack message with remediation buttons; agent cannot proceed until a human clicks
Telemetry citation"Evidence pointer"A Prometheus query, Loki selector, or Tempo trace URL that supports a claim
MTTR"Time to resolution"Wall-clock from alert fire to SLO recovery

Further Reading

Code

  • main.py

    python phases/19-capstone-projects/06-devops-troubleshooting-agent/code/main.pyOpen on GitHub ↗
  • ts/package.json

    Open on GitHub ↗
  • ts/README.md

    Open on GitHub ↗
  • ts/src/agent.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/agent.tsOpen on GitHub ↗
  • ts/src/blocks.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/blocks.tsOpen on GitHub ↗
  • ts/src/index.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/index.tsOpen on GitHub ↗
  • ts/src/server.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/server.tsOpen on GitHub ↗
  • ts/src/slack_verify.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/slack_verify.tsOpen on GitHub ↗
  • ts/src/types.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/src/types.tsOpen on GitHub ↗
  • ts/tests/agent.test.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/tests/agent.test.tsOpen on GitHub ↗
  • ts/tests/server.test.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/tests/server.test.tsOpen on GitHub ↗
  • ts/tests/slack_verify.test.ts

    npx tsx phases/19-capstone-projects/06-devops-troubleshooting-agent/code/ts/tests/slack_verify.test.tsOpen on GitHub ↗
  • ts/tsconfig.json

    Open on GitHub ↗

Take-away files

skill-devops-agent.md

---
name: devops-agent
description: Build a Kubernetes troubleshooting agent that walks a cluster knowledge graph, ranks root causes, and gates every remediation through Slack.
version: 1.0.0
phase: 19
lesson: 06
tags: [capstone, devops, sre, kubernetes, langgraph, fastmcp, aiops]
---

Given a K8s cluster and an alert source (PagerDuty or Alertmanager), build an agent that produces ranked root-cause hypotheses in under five minutes and gates every remediation through a Slack approval card.

Build plan:

1. Ingest kube-state-metrics into Neo4j or kuzu every 30s. Build a graph of Pods, Deployments, Services, Nodes, PVCs, HPAs plus telemetry-overlay edges to Prometheus, Loki, and Tempo sources.
2. Stand up a FastAPI webhook receiver for PagerDuty and Alertmanager.
3. Expose read-only tools through FastMCP with StreamableHTTP transport: kubectl get/describe, promql, logql, traceql.
4. Build a LangGraph root-cause agent with three nodes: `sample` (pull 15m telemetry), `walk` (traverse graph neighbors), `hypothesize` (rank candidates by recency × specificity × citation count).
5. Post the top-3 ranked hypotheses with graph-path visualization to Slack with approval buttons.
6. Put destructive tools (scale, rollback, delete) on a separate FastMCP server behind an approval token the agent obtains only after Slack signoff.
7. Maintain an append-only audit log: every *considered* command, whether approved, whether executed, who approved.
8. Build 20 synthetic incident scenarios (OOMKill, DNS flap, HPA thrash, PVC fill, noisy neighbor, faulty sidecar, ConfigMap bad rollout, cert rotation, image-pull backoff, probe failure, and 10 more). Score agent on RCA accuracy and time-to-hypothesis.

Assessment rubric:

| Weight | Criterion | Measurement |
|:-:|---|---|
| 25 | RCA accuracy on scenario suite | At least 80% correct root cause across 20 synthetic incidents |
| 20 | Safety | Destructive-action guard never fires without Slack approval in the audit log |
| 20 | Time-to-hypothesis | p50 under 5 minutes from alert to Slack brief |
| 20 | Explainability | Every hypothesis has graph paths and telemetry citations |
| 15 | Integration completeness | PagerDuty, Slack, ArgoCD, Prometheus end-to-end working |

Hard rejects:

- Agents with a single MCP server that mixes read-only and destructive tools.
- Any RCA produced without telemetry citations. Uncited hypotheses must be rejected.
- Audit logs that only record executions. They must record every command considered.
- Claims of accuracy without running the agent against the 20-scenario suite with seeds.

Refusal rules:

- Refuse to remediate without Slack approval from a human on-caller. Even if the hypothesis is obvious.
- Refuse to expose `kubectl exec`, `kubectl port-forward`, or any interactive tool via the read-only MCP. These are destructive in effect.
- Refuse to batch-apply remediations across multiple deployments without per-deployment approval cards.

Output: a repo containing the FastAPI receiver, the LangGraph agent, the read-only and destructive MCP servers, the Slack integration, the 20-scenario test suite, a side-by-side comparison against AWS DevOps Agent on three shared incidents, and a write-up on near-miss commands (what the agent *considered* but did not execute) over a one-week observation window.