CoolFace
Apppublic

DevilNReality/Incident-Triage-Reinforcement-Learning

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿšจ Incident Triage & Alert Routing โ€” OpenEnv

Meta ร— Hugging Face AI Hackathon | Round 1 An OpenEnv environment for training AI agents to triage production incidents like a senior SRE.

Environment Description

This environment simulates the real-world job of a Site Reliability Engineer (SRE) who receives a flood of production alerts and must:

  1. 1.Identify the root cause from a set of correlated alerts
  2. 2.Assign the correct severity level (P1โ€“P4)
  3. 3.Route the incident to the correct on-call team (SRE, Database, Network, or App)
  4. 4.(Hard task only) Suppress noise alerts โ€” flapping/self-resolving false positives

Every tech company faces alert fatigue. Reducing Mean Time To Detection (MTTD) by even 5 minutes has enormous operational value. This environment benchmarks how well an AI agent handles that pressure.


Observation Space

At each step the agent receives an AlertObservation:

python
class AlertObservation(BaseModel):
    alerts:       List[Alert]        # incoming monitoring alerts
    services_map: Dict[str, str]     # service โ†’ responsible team
    step:         int                # current step in the episode
    max_steps:    int                # maximum steps allowed
    task_id:      str                # "task_easy" | "task_medium" | "task_hard"

Each Alert contains:

python
class Alert(BaseModel):
    alert_id:   str    # e.g. "alert-001"
    service:    str    # e.g. "postgres-primary"
    metric:     str    # e.g. "db_query_time_ms"
    value:      float  # current metric value
    threshold:  float  # value that triggered the alert
    duration_s: int    # how long it has been firing (seconds)

Services Map

ServiceTeam
api-server-03, api-server-07, redis-cache-01sre
postgres-primary, postgres-replicadatabase
checkout-service, payment-service, auth-service, reporting-serviceapp
load-balancer-01, cdn-edge-02, dns-resolver-01network

Action Space

python
class TriageAction(BaseModel):
    severity:   Literal['P1', 'P2', 'P3', 'P4']
    team:       Literal['sre', 'database', 'network', 'app']
    root_cause: str        # one-sentence explanation, graded by keyword match
    suppressed: List[str]  # alert_ids believed to be noise (task_hard only)
FieldDescription
severityP1 = Critical (revenue impact), P2 = High (users affected), P3 = Medium, P4 = Low
teamOn-call team to page: sre, database, network, or app
root_causeFree-text root cause. Scored by keyword match against ground truth.
suppressedAlert IDs the agent believes are noise. Only scored in task_hard.

Reward Function

task_easy

ComponentWeight
Severity correct0.50
Team correct0.50

task_medium

ComponentWeight
Severity correct0.35
Team correct0.35
Root cause keywords0.30

task_hard

ComponentWeight
Noise suppression (F1)0.20
Severity correct0.25
Team correct0.25
Root cause keywords0.30
Over-suppression penaltyโˆ’0.20 per real alert wrongly suppressed

Task Descriptions

๐ŸŸข task_easy โ€” Single Alert, Obvious Root Cause

  • โ€”1 alert randomly chosen from 4 scenario variants
  • โ€”Variants: CPU spike โ†’ SRE ยท DB timeout โ†’ Database ยท Network latency โ†’ Network ยท 5xx errors โ†’ App
  • โ€”Max steps: 3
  • โ€”Expected score (frontier model): 0.9โ€“1.0

๐ŸŸ  task_medium โ€” 3 Correlated Alerts, Identify Root Cause

  • โ€”3 correlated alerts from 4 scenario sets (Database overload, Network partition, App memory leak, CPU saturation)
  • โ€”Agent must identify the single upstream root cause from downstream effects
  • โ€”Max steps: 3
  • โ€”Expected score (frontier model): 0.5โ€“0.75

๐Ÿ”ฅ task_hard โ€” 10โ€“15 Alerts, Suppress Noise & Escalate

  • โ€”6 real alerts (database outage root cause) + 5 noise alerts (short-duration, barely over threshold)
  • โ€”Noise rule: duration_s < 60 AND value < threshold ร— 1.10
  • โ€”Agent must suppress noise alerts and correctly identify the P1 database root cause
  • โ€”Max steps: 5
  • โ€”Expected score (frontier model): 0.2โ€“0.45

API Reference

All endpoints are available on port 7860 (via nginx reverse proxy).

MethodPathDescription
GET/healthHealth check โ€” returns {"status": "ok"}
GET/tasksList all tasks with metadata
POST/resetStart a new episode. Body: {"task_id": "task_easy", "seed": null}
POST/stepSubmit a TriageAction. Returns observation, reward, done, info.
GET/stateFull environment state including ground truth team/severity

Example: Full Episode

python
import requests

BASE = "https://<your-username>-incident-triage-env.hf.space"

# 1. Reset
obs = requests.post(f"{BASE}/reset", json={"task_id": "task_medium"}).json()

# 2. Step
action = {
    "severity": "P1",
    "team": "database",
    "root_cause": "Database overload causing query timeouts and downstream 5xx errors",
    "suppressed": []
}
result = requests.post(f"{BASE}/step", json=action).json()
print(result["reward"], result["done"], result["info"])

๐Ÿš€ Setup & Deployment

Option A โ€” Hugging Face Spaces (recommended)

Prerequisites
  • โ€”Git installed
  • โ€”A Hugging Face account with a token from https://huggingface.co/settings/tokens
Step 1 โ€” Install the HF CLI & login
bash
pip install huggingface_hub
huggingface-cli login
Step 2 โ€” Create a new Space

Go to https://huggingface.co/new-space and set:

  • โ€”Space name: incident-triage-env
  • โ€”SDK: Docker
  • โ€”Visibility: Public
Step 3 โ€” Clone and push
bash
git clone https://huggingface.co/spaces/<your-username>/incident-triage-env
cd incident-triage-env

# Copy all project files here, then:
git add .
git commit -m "deploy: Incident Triage OpenEnv"
git push

HF Spaces detects the Dockerfile and builds automatically (~3โ€“5 min). Monitor progress in the Logs tab.

Step 4 โ€” Add secrets (for LLM agent mode)

In your Space โ†’ Settings โ†’ Repository secrets:

SecretValue
HF_TOKENYour HF token (hf_...)
API_BASE_URLhttps://router.huggingface.co/v1
MODEL_NAMEmeta-llama/Llama-3.3-70B-Instruct
The Streamlit UI and rule-based agent work without secrets. Secrets are only needed for LLM Agent mode.

Option B โ€” Local Development

bash
# 1. Install dependencies
pip install -r requirements.txt

# 2. Start FastAPI backend (terminal 1)
cd backend
uvicorn server:app --reload --port 8000

# 3. Start Streamlit UI (terminal 2, from project root)
BACKEND_URL=http://localhost:8000 streamlit run frontend/app.py
# Opens at http://localhost:8501

# 4. (Optional) Run the LLM baseline agent
cp .env.example .env   # fill in your API keys
source .env
python inference.py

Option C โ€” Docker locally

bash
docker build -t incident-triage-env .
docker run -p 7860:7860 \
  -e HF_TOKEN=hf_... \
  -e API_BASE_URL=https://router.huggingface.co/v1 \
  -e MODEL_NAME=meta-llama/Llama-3.3-70B-Instruct \
  incident-triage-env

# UI + API both at http://localhost:7860

Architecture

Browser / OpenEnv Checker
         โ”‚
         โ–ผ port 7860 (public)
       nginx
      โ•ฑ     โ•ฒ
     โ–ผ         โ–ผ
FastAPI       Streamlit
 :8000         :8501
(API calls)   (Web UI)

nginx routes:

  • โ€”POST /reset, GET /health, /tasks, /step, /state โ†’ FastAPI (OpenEnv checker)
  • โ€”/ and all other traffic โ†’ Streamlit UI (browser)

Project Structure

incident-triage-env/
โ”œโ”€โ”€ Dockerfile           โ† Builds & runs nginx + FastAPI + Streamlit
โ”œโ”€โ”€ nginx.conf           โ† Reverse proxy: port 7860 โ†’ FastAPI:8000 / Streamlit:8501
โ”œโ”€โ”€ start.sh             โ† Startup script launching all three processes
โ”œโ”€โ”€ requirements.txt     โ† Python dependencies (latest versions)
โ”œโ”€โ”€ openenv.yaml         โ† OpenEnv spec: tasks, action/observation spaces, reward
โ”œโ”€โ”€ pyproject.toml       โ† Package config; server entry point: server.app:main
โ”œโ”€โ”€ .env.example         โ† Template for local env vars
โ”œโ”€โ”€ .dockerignore        โ† Excludes __pycache__, *.pyc, .git, uv.lock etc.
โ”œโ”€โ”€ inference.py         โ† LLM baseline agent (uses OpenAI client + HF router)
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ models.py        โ† Pydantic v2: Alert, AlertObservation, TriageAction, TriageReward
โ”‚   โ”œโ”€โ”€ tasks.py         โ† All task definitions + graders (easy / medium / hard)
โ”‚   โ”œโ”€โ”€ environment.py   โ† OpenEnv contract: reset() step() state()
โ”‚   โ””โ”€โ”€ server.py        โ† FastAPI app with /reset /step /state /health /tasks
โ”œโ”€โ”€ server/
โ”‚   โ””โ”€โ”€ app.py           โ† Entry point wrapper for multi-mode deployment (server.app:main)
โ””โ”€โ”€ frontend/
    โ””โ”€โ”€ app.py           โ† Streamlit UI: alert cards, routing table, score chart

Baseline Scores

TaskScoreNotes
task_easy~0.95Near-perfect on single alert
task_medium~0.63Good severity+team, partial root cause keyword match
task_hard~0.31Noise suppression is the primary challenge

Scores from meta-llama/Llama-3.3-70B-Instruct via HF inference router.


Built for the Meta ร— Hugging Face AI Hackathon, Round 1.