Welcome to the production-grade template for building, testing, and deploying an autonomous Site Reliability Engineering (SRE) Agent in Google Cloud. This system integrates the Google Agent Development Kit (ADK) for multi-agent diagnostic graphs and the Google Antigravity SDK for the agent runtime, deny-by-default safety policies, and safe execution.
The agent monitors microservices, queries distributed traces, correlates logs, diagnoses cascade bottlenecks, auto-generates comprehensive incident post-mortems, and lets you download them straight from the chat UI. The whole stack runs locally with zero GCP credentials thanks to a mock-telemetry mode.
π¦ Source code:
github.com/xSAVIKx/sre-agent
Google Cloud credits are provided for this project.
#AgenticArchitect #GoogleAntigravity
When a request spikes in latency, the SRE Agent dissects the distributed trace. It calculates the inclusive vs. exclusive (self) execution time for every span, rendering a contribution table that pins down the exact bottleneck β e.g. a gateway request that looks 10 s slow, where 99.3% of the time is actually trapped in one database span three levels down.
Following a diagnosis, the agent compiles a complete Incident Post-Mortem (RCA) including:
- Incident Overview: Date/time, root service, Trace ID, impact duration, and status.
- Timeline: Trace timestamps for the gateway alert, cascading failure, and mitigation.
- Root Cause Analysis: Connection states, active chaos injections, or infrastructure timeouts.
- Prevention Plan: Immediate remediation, short-term workarounds, and long-term preventions.
The web chat parses diagnostic reports server-side; when it detects a post-mortem it renders a premium, styled Download Button that exports the report to markdown (post_mortem.md) entirely client-side via the Blob API.
Four FastAPI services collaborate over HTTP (Agent-to-Agent / A2A) with results streamed back as Server-Sent Events (SSE). The user-facing Orchestrator is locked to a deny-by-default policy β its only capability is to delegate to the read-only SRE diagnostics agent.
flowchart LR
User(["π€ On-call engineer"]) -->|"/chat (SSE)"| ORCH
subgraph Safe["π‘οΈ Orchestrator Β· service: sre-agent"]
ORCH["Antigravity runtime<br/>policy = deny('*'), allow('diagnose_sre')"]
end
ORCH -->|"diagnose_sre β A2A/SSE"| SRE["π¬ SRE diagnostics<br/>service: sre-sub-agent<br/>ADK: TraceAnalyzer β LogCorrelator"]
SRE -->|"topology"| INV["π Inventory agent<br/>service: inventory-agent"]
INV --> FS[("Firestore")]
SRE -->|"read-only Β· or MOCK_GCP"| OBS[("βοΈ Trace Β· Logging Β· Monitoring")]
APP["π Target app<br/>service: sre-chaos-monkey"] -->|"write-only telemetry"| OBS
SRE -->|"report + π₯ post-mortem"| ORCH --> User
| Service | Package | Role |
|---|---|---|
| Orchestrator | agent/ |
User-facing agent + web chat UI; delegates via the diagnose_sre tool. |
| SRE diagnostics | sre_agent/ |
The engine: observability tools + the ADK multi-agent workflow. |
| Inventory | inventory_agent/ |
Discovers & caches the project topology (Cloud Run services + databases). |
| Target app | app/ |
OpenTelemetry-instrumented "chaos monkey" that generates synthetic incidents. |
| Shared lib | sre_common/ |
otel_trace, retry_async, setup_logging, trace-context middleware. |
.
βββ README.md Β· AGENTS.md Β· BLOGPOST.md Β· CODELAB.md
βββ pyproject.toml # Root uv workspace (5 members)
βββ uv.lock
βββ docker-compose.yaml # Full local multi-service stack + Firestore emulator
βββ cloudbuild.yaml # Root Cloud Build config
βββ bootstrap.sh # Interactive GCP project setup (writes .env)
βββ deploy.sh # Least-privilege Cloud Run deploy
βββ cleanup.sh # GCP resource teardown
βββ simulate_incident.py # Local standalone simulation (no GCP needed)
β
βββ app/ # π Target FastAPI app (OpenTelemetry-instrumented)
β βββ main.py # Gateway β Backend β Database incident generator
β βββ Dockerfile Β· cloudbuild.yaml Β· pyproject.toml
β
βββ agent/ # π‘οΈ Orchestrator service (user-facing + web UI)
β βββ src/agent/
β β βββ config.py # Antigravity safety policies & runtime loader
β β βββ routes.py # FastAPI endpoints (/chat UI + SSE, /diagnose)
β β βββ main.py # FastAPI app wiring
β β βββ a2ui_translator.py # Markdown β rich A2UI schema (download button)
β β βββ firestore_strategy.py
β β βββ index.html # Premium web chat interface
β βββ test/
β βββ Dockerfile Β· cloudbuild.yaml Β· pyproject.toml
β
βββ sre_agent/ # π¬ SRE diagnostics engine
β βββ src/sre_agent/
β β βββ gcp_tools.py # Trace/log/metric tools + cascade & post-mortem
β β βββ sre_workflow.py # ADK multi-agent orchestration (two tiers)
β β βββ routes.py # A2A SSE endpoint /v1/agents/sre/messages
β β βββ registry.py # @register_tool decorator
β β βββ itinerary.py Β· config.py Β· firestore_strategy.py Β· main.py
β βββ test/
β βββ Dockerfile Β· cloudbuild.yaml Β· pyproject.toml
β
βββ inventory_agent/ # π Infrastructure topology discovery
β βββ src/inventory_agent/{main,routes,discovery,config,firestore_strategy}.py
β βββ Dockerfile Β· cloudbuild.yaml Β· pyproject.toml
β
βββ sre_common/ # π§° Shared library
β βββ src/sre_common/{otel,retry,logging,middleware}.py
β
βββ skills/ # π§© Portable Antigravity skill (mirror of the engine)
βββ sre_incident_solver/{SKILL.md, sre_workflow.py, gcp_tools.py, registry.py}
- Step-by-step Tutorial: Build the agent from scratch in
CODELAB.md. - Editorial Technical Post: The engineering architecture & design rationale in
BLOGPOST.md. - Contributor Guide: Conventions for AI and human collaborators in
AGENTS.md. - Follow-Up Exercises: Turn the codelab into your own project with hands-on extension challenges in
EXERCISES.md.
Run the entire diagnostic workflow locally in seconds with uv. No GCP account, project, or credentials required.
git clone https://github.com/xSAVIKx/sre-agent.git
cd sre-agentpip install uv
uv sync --all-packagesuv run simulate_incident.pyThis single command:
- Triggers the mock target app gateway to generate a synthetic database-timeout incident.
- Writes mock traces and logs to
mock_telemetry_data/(gitignored). - Boots the Orchestrator in mock mode, which calls
diagnose_sreand runs the workflow in-process. - Prints the structured telemetry plus the full diagnosis β the
/api/database99.3% bottleneck table and the complete# π¨ Incident Post-Mortemβ straight to your terminal.
Want the full multi-service experience (Orchestrator + SRE + Inventory + Firestore emulator + target app) with the web chat UI?
docker-compose up --build # then open the chat at /chatDeploy to Cloud Run following least-privilege best practices β each service gets its own minimally-scoped service account.
./bootstrap.sh # gcloud auth login, set project + region, write .env./deploy.shThis enables the required APIs (Run, Cloud Build, Trace, Logging, Monitoring, Artifact Registry, Firestore, Secret Manager), provisions the service accounts, grants least-privilege roles, then builds and deploys four Cloud Run services:
| Service account | Used by | Roles |
|---|---|---|
sre-chaos-monkey-sa |
target app (sre-chaos-monkey) |
cloudtrace.agent, logging.logWriter (write-only telemetry) |
sre-agent-sa |
SRE diagnostics (sre-sub-agent) |
cloudtrace.user, logging.viewer, monitoring.viewer, datastore.user (read-only) |
inventory-agent-sa |
inventory agent (inventory-agent) |
datastore.user, run.developer, logging.logWriter |
sre-build-sa |
Cloud Build | run.admin, storage.admin, artifactregistry.writer, logging.logWriter |
The split is the point: the app that generates chaos can only write telemetry; the agent that investigates it can only read.
This codebase shows three ways to work with the SRE agent:
Used programmatically in agent/src/agent/config.py to configure the Orchestrator: system instructions, registered tools, and a strict deny-by-default safety policy β [deny("*"), allow("diagnose_sre")]. The Orchestrator literally cannot read files, run commands, or hit arbitrary URLs; its only move is to delegate to the read-only SRE sub-agent.
Developers can drive and inspect the workspace from the terminal. The most direct way to exercise the full diagnostic loop is the local simulation above (uv run simulate_incident.py); the CLI also discovers the reusable skill under skills/sre_incident_solver/.
The desktop application auto-discovers skills placed in the skills/ directory. Opening this repository surfaces the sre_incident_solver skill via SKILL.md, letting you run and audit SRE tasks from a graphical canvas.
To prevent ongoing billing charges, remove all deployed Cloud Run services, IAM bindings, and service accounts:
./cleanup.sh