Skip to content

Latest commit

Β 

History

106 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›Έ Autonomous Cloud SRE Agent (ADK + Antigravity with uv)

Autonomous Cloud SRE Agent β€” scans traces, isolates the bottleneck, correlates logs, and auto-writes the post-mortem

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


⚑ Featured Capabilities

1. ⛓️ Multi-Service Cascade Latency & Bottleneck Analyzer

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.

2. πŸ“„ Automated Incident Post-Mortem Generator

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.

3. πŸ“₯ Interactive Chat Downloader

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.


πŸ—οΈ Architecture

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
Loading
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.

πŸ“‚ Repository Layout

.
β”œβ”€β”€ 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}

πŸ“– Key Deliverables

  • 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.

πŸš€ Quickstart: Local Standalone Simulation

Run the entire diagnostic workflow locally in seconds with uv. No GCP account, project, or credentials required.

1. Clone the Repository

git clone https://github.com/xSAVIKx/sre-agent.git
cd sre-agent

2. Synchronize Dependencies

pip install uv
uv sync --all-packages

3. Run the Incident Simulation

uv run simulate_incident.py

This single command:

  1. Triggers the mock target app gateway to generate a synthetic database-timeout incident.
  2. Writes mock traces and logs to mock_telemetry_data/ (gitignored).
  3. Boots the Orchestrator in mock mode, which calls diagnose_sre and runs the workflow in-process.
  4. Prints the structured telemetry plus the full diagnosis β€” the /api/database 99.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 /chat

☁️ Production Deployment: Google Cloud Run

Deploy to Cloud Run following least-privilege best practices β€” each service gets its own minimally-scoped service account.

1. Bootstrap GCP Settings

./bootstrap.sh   # gcloud auth login, set project + region, write .env

2. Deploy the Services

./deploy.sh

This 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.


βš™οΈ The Antigravity Ecosystem

This codebase shows three ways to work with the SRE agent:

1. The Antigravity SDK

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.

2. The Antigravity CLI (agy)

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/.

3. Antigravity 2.0 (Visual Workspace)

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.


🧹 Tearing Down the Stack

To prevent ongoing billing charges, remove all deployed Cloud Run services, IAM bindings, and service accounts:

./cleanup.sh

Contributors

Languages