New Upgrade to Multi-Agent Incident Command Center
Browse files- .gitignore +5 -0
- README.md +80 -40
- __init__.py +6 -6
- client.py +24 -13
- inference.py +202 -50
- models.py +58 -18
- openenv.yaml +6 -6
- pre_validate.sh +2 -0
- pyproject.toml +15 -18
- requirements.txt +10 -4
- server/Dockerfile +3 -3
- server/__init__.py +1 -0
- server/app.py +18 -11
- server/environment.py +501 -46
- server/requirements.txt +1 -1
- server/support_env_environment.py +5 -0
- train_trl.py +194 -0
- validate-submission.sh +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.venv/
|
| 4 |
+
artifacts/
|
| 5 |
+
outputs/
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
|
@@ -11,65 +11,105 @@ tags:
|
|
| 11 |
- openenv
|
| 12 |
- reinforcement-learning
|
| 13 |
- llm-agents
|
|
|
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
-
#
|
| 17 |
|
| 18 |
-
##
|
| 19 |
-
This environment simulates
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
##
|
| 24 |
|
| 25 |
### Action Space
|
| 26 |
-
- `
|
| 27 |
-
- `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
### Observation Space
|
| 30 |
-
- `
|
| 31 |
-
- `
|
| 32 |
-
- `
|
| 33 |
-
- `
|
|
|
|
| 34 |
|
| 35 |
### Reward Function
|
| 36 |
-
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
##
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
| `medium` | 2 | Standard conversational support language. |
|
| 46 |
-
| `hard` | 3 | Complex queries involving API logs and technical stack traces. |
|
| 47 |
|
| 48 |
-
##
|
| 49 |
|
| 50 |
-
### 1. Installation
|
| 51 |
```bash
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
```
|
| 54 |
|
| 55 |
-
###
|
| 56 |
-
Ensure your local setup matches the competition requirements:
|
| 57 |
```bash
|
| 58 |
-
|
| 59 |
```
|
| 60 |
|
| 61 |
-
###
|
| 62 |
-
Execute the provided baseline using the Hugging Face Router and the Qwen2.5-72B model:
|
| 63 |
```bash
|
| 64 |
-
export HF_TOKEN="your_huggingface_token"
|
| 65 |
python inference.py
|
| 66 |
```
|
| 67 |
|
| 68 |
-
##
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
---
|
| 74 |
-
*
|
| 75 |
-
*Environment ID: `support_env` | Powered by OpenEnv SDK.*
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Multi-Agent Incident Command Center
|
| 3 |
+
emoji: 🚨
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
|
|
|
| 11 |
- openenv
|
| 12 |
- reinforcement-learning
|
| 13 |
- llm-agents
|
| 14 |
+
- multi-agent
|
| 15 |
+
- long-horizon
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# 🚨 Multi-Agent Incident Command Center (OpenEnv Round 2)
|
| 19 |
|
| 20 |
+
## Problem and Motivation
|
| 21 |
+
This environment simulates incident management for a modern software platform under real operational constraints.
|
| 22 |
|
| 23 |
+
The agent must coordinate multiple specialist roles and resolve incidents over long trajectories with partial observability, action costs, and SLA pressure. This targets Round-2 themes:
|
| 24 |
+
- **Theme #1 Multi-Agent Interactions**: triage, investigator, and ops-manager role coordination
|
| 25 |
+
- **Theme #3.1 World Modeling (Professional Tasks)**: realistic logs/metrics/KB workflows
|
| 26 |
+
- **Theme #2 Long-Horizon Planning**: delayed rewards, carry-over constraints, budget-limited sessions
|
| 27 |
|
| 28 |
+
## Environment Design
|
| 29 |
|
| 30 |
### Action Space
|
| 31 |
+
- `inspect_logs(target)`
|
| 32 |
+
- `inspect_metrics(target)`
|
| 33 |
+
- `consult_kb(target)`
|
| 34 |
+
- `negotiate_handoff(target)` where target is one of:
|
| 35 |
+
- `triage_agent`
|
| 36 |
+
- `investigator_agent`
|
| 37 |
+
- `ops_manager_agent`
|
| 38 |
+
- `apply_fix(resolution_summary)`
|
| 39 |
+
- `close_incident(root_cause, resolution_summary)`
|
| 40 |
|
| 41 |
### Observation Space
|
| 42 |
+
- `incident_id`, `incident_title`, `incident_description`
|
| 43 |
+
- `visible_signals` (partial clues)
|
| 44 |
+
- `available_actions`, `available_teams`
|
| 45 |
+
- `budget_remaining`, `sla_minutes_remaining`, `incidents_remaining`
|
| 46 |
+
- `terminal_output` (response from world/tool execution)
|
| 47 |
|
| 48 |
### Reward Function
|
| 49 |
+
- Dense shaping with delayed completion rewards:
|
| 50 |
+
- Small penalty for investigation actions to discourage brute-force scanning
|
| 51 |
+
- Positive reward for discovering new root-cause evidence
|
| 52 |
+
- Bonus for correct specialist handoff
|
| 53 |
+
- Positive reward for effective mitigation
|
| 54 |
+
- Large terminal reward for correct closure (with additional speed bonus)
|
| 55 |
+
- Strong negative reward for wrong closure, SLA exhaustion, or budget exhaustion
|
| 56 |
|
| 57 |
+
## Task Levels
|
| 58 |
+
- `easy`: 2 incidents
|
| 59 |
+
- `medium`: 3 incidents
|
| 60 |
+
- `hard`: 4 incidents with stricter planning requirements
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
## Local Setup
|
| 63 |
|
|
|
|
| 64 |
```bash
|
| 65 |
+
python -m venv .venv
|
| 66 |
+
# Windows PowerShell:
|
| 67 |
+
.venv\Scripts\Activate.ps1
|
| 68 |
+
pip install -r requirements.txt
|
| 69 |
```
|
| 70 |
|
| 71 |
+
### Run environment
|
|
|
|
| 72 |
```bash
|
| 73 |
+
python -m server.app
|
| 74 |
```
|
| 75 |
|
| 76 |
+
### Run baseline inference
|
|
|
|
| 77 |
```bash
|
|
|
|
| 78 |
python inference.py
|
| 79 |
```
|
| 80 |
|
| 81 |
+
### OpenEnv validation
|
| 82 |
+
```bash
|
| 83 |
+
openenv validate
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Training Script (TRL)
|
| 87 |
+
This repo includes `train_trl.py` for minimum Round-2 training evidence using Hugging Face TRL.
|
| 88 |
+
|
| 89 |
+
It does:
|
| 90 |
+
1. Roll out trajectories from a baseline coordinator
|
| 91 |
+
2. Convert trajectories into SFT-style chat examples
|
| 92 |
+
3. Train a compact model with `SFTTrainer`
|
| 93 |
+
4. Evaluate random vs heuristic policy and save plots
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
python train_trl.py
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Artifacts are written to `artifacts/`:
|
| 100 |
+
- `reward_curve.png`
|
| 101 |
+
- `summary_metrics.json`
|
| 102 |
+
|
| 103 |
+
## Hugging Face Space
|
| 104 |
+
After testing locally, deploy this repo as a Docker Space and set `app_port=8000`.
|
| 105 |
+
|
| 106 |
+
## Submission Checklist
|
| 107 |
+
- [ ] OpenEnv latest runtime and `openenv validate` passing
|
| 108 |
+
- [ ] HF Space URL live and reachable
|
| 109 |
+
- [ ] `train_trl.py` (or Colab equivalent) run with real outputs
|
| 110 |
+
- [ ] Reward/loss plot images committed and linked
|
| 111 |
+
- [ ] 2-minute demo video/blog link added
|
| 112 |
+
- [ ] README links all artifacts and references
|
| 113 |
|
| 114 |
---
|
| 115 |
+
*Environment ID: `incident_command_center_env`*
|
|
|
__init__.py
CHANGED
|
@@ -4,13 +4,13 @@
|
|
| 4 |
# This source code is licensed under the BSD-style license found in the
|
| 5 |
# LICENSE file in the root directory of this source tree.
|
| 6 |
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
-
from .client import
|
| 10 |
-
from .models import
|
| 11 |
|
| 12 |
__all__ = [
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
]
|
|
|
|
| 4 |
# This source code is licensed under the BSD-style license found in the
|
| 5 |
# LICENSE file in the root directory of this source tree.
|
| 6 |
|
| 7 |
+
"""Incident Command Center environment."""
|
| 8 |
|
| 9 |
+
from .client import IncidentCommandEnvClient
|
| 10 |
+
from .models import IncidentAction, IncidentObservation
|
| 11 |
|
| 12 |
__all__ = [
|
| 13 |
+
"IncidentAction",
|
| 14 |
+
"IncidentObservation",
|
| 15 |
+
"IncidentCommandEnvClient",
|
| 16 |
]
|
client.py
CHANGED
|
@@ -1,26 +1,37 @@
|
|
| 1 |
from openenv.core.env_client import EnvClient
|
| 2 |
from openenv.core.client_types import StepResult
|
| 3 |
-
from models import
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
return action.model_dump(exclude_none=True)
|
| 8 |
|
| 9 |
def _parse_result(self, payload: dict) -> StepResult:
|
| 10 |
obs_data = payload.get("observation", {})
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
-
|
| 19 |
return StepResult(
|
| 20 |
observation=observation,
|
| 21 |
reward=payload.get("reward", 0.0),
|
| 22 |
-
done=payload.get("done", False)
|
| 23 |
)
|
| 24 |
|
| 25 |
-
def _parse_state(self, payload: dict) ->
|
| 26 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from openenv.core.env_client import EnvClient
|
| 2 |
from openenv.core.client_types import StepResult
|
| 3 |
+
from models import IncidentAction, IncidentObservation, IncidentState
|
| 4 |
|
| 5 |
+
|
| 6 |
+
class IncidentCommandEnvClient(EnvClient[IncidentAction, IncidentObservation, IncidentState]):
|
| 7 |
+
def _step_payload(self, action: IncidentAction) -> dict:
|
| 8 |
return action.model_dump(exclude_none=True)
|
| 9 |
|
| 10 |
def _parse_result(self, payload: dict) -> StepResult:
|
| 11 |
obs_data = payload.get("observation", {})
|
| 12 |
+
|
| 13 |
+
observation = IncidentObservation(
|
| 14 |
+
incident_id=obs_data.get("incident_id", ""),
|
| 15 |
+
incident_title=obs_data.get("incident_title", ""),
|
| 16 |
+
incident_description=obs_data.get("incident_description", ""),
|
| 17 |
+
available_actions=obs_data.get("available_actions", []),
|
| 18 |
+
available_teams=obs_data.get("available_teams", []),
|
| 19 |
+
visible_signals=obs_data.get("visible_signals", []),
|
| 20 |
+
terminal_output=obs_data.get("terminal_output", ""),
|
| 21 |
+
budget_remaining=obs_data.get("budget_remaining", 0),
|
| 22 |
+
sla_minutes_remaining=obs_data.get("sla_minutes_remaining", 0),
|
| 23 |
+
incidents_remaining=obs_data.get("incidents_remaining", 0),
|
| 24 |
)
|
| 25 |
+
|
| 26 |
return StepResult(
|
| 27 |
observation=observation,
|
| 28 |
reward=payload.get("reward", 0.0),
|
| 29 |
+
done=payload.get("done", False),
|
| 30 |
)
|
| 31 |
|
| 32 |
+
def _parse_state(self, payload: dict) -> IncidentState:
|
| 33 |
+
return IncidentState(**payload)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Backward-compatible alias for older imports.
|
| 37 |
+
SREEnvClient = IncidentCommandEnvClient
|
inference.py
CHANGED
|
@@ -1,83 +1,235 @@
|
|
| 1 |
-
import os
|
| 2 |
import asyncio
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# 1. Mandatory Environment Variables
|
| 8 |
-
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("API_KEY")
|
| 9 |
-
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
| 10 |
-
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
| 11 |
-
ENV_URL = os.getenv("ENV_URL", "https://swapnilpatil28-support-env.hf.space")
|
| 12 |
-
BENCHMARK = "support_env"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
def log_step(step: int, action: str, reward: float, done: bool, error: Optional[str]) -> None:
|
| 19 |
error_val = error if error else "null"
|
| 20 |
done_val = str(done).lower()
|
| 21 |
-
print(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 24 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 25 |
-
print(
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
async def run_task(task_name: str):
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
steps_taken = 0
|
| 49 |
-
score = 0.0
|
| 50 |
success = False
|
| 51 |
|
| 52 |
try:
|
| 53 |
-
# Initial Reset
|
| 54 |
res = env.reset(task_name=task_name)
|
| 55 |
-
|
| 56 |
while not res.done:
|
| 57 |
steps_taken += 1
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
res = env.step(
|
| 62 |
-
|
| 63 |
reward = float(res.reward or 0.0)
|
| 64 |
rewards.append(reward)
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
# Scoring Logic (Normalized [0,1])
|
| 69 |
score = sum(rewards) / len(rewards) if rewards else 0.0
|
| 70 |
-
|
| 71 |
-
success = score > 0.5
|
| 72 |
-
|
| 73 |
finally:
|
| 74 |
try:
|
| 75 |
env.close()
|
| 76 |
-
except:
|
| 77 |
pass
|
| 78 |
log_end(success=success, steps=steps_taken, score=score, rewards=rewards)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
for task in ["easy", "medium", "hard"]:
|
| 83 |
asyncio.run(run_task(task))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from typing import Dict, List, Optional
|
| 5 |
+
|
| 6 |
+
from client import IncidentCommandEnvClient
|
| 7 |
+
from models import IncidentAction
|
| 8 |
+
|
| 9 |
+
ENV_URL = os.getenv("ENV_URL", "http://127.0.0.1:8000")
|
| 10 |
+
BENCHMARK = "incident_command_center_env"
|
| 11 |
+
RANDOM_BASELINE = os.getenv("RANDOM_BASELINE", "false").lower() == "true"
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def log_start(task: str, env: str, policy: str) -> None:
|
| 15 |
+
print(f"[START] task={task} env={env} policy={policy}", flush=True)
|
| 16 |
+
|
| 17 |
|
| 18 |
def log_step(step: int, action: str, reward: float, done: bool, error: Optional[str]) -> None:
|
| 19 |
error_val = error if error else "null"
|
| 20 |
done_val = str(done).lower()
|
| 21 |
+
print(
|
| 22 |
+
f"[STEP] step={step} action={action} reward={reward:.2f} done={done_val} error={error_val}",
|
| 23 |
+
flush=True,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
|
| 27 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 28 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 29 |
+
print(
|
| 30 |
+
f"[END] success={str(success).lower()} steps={steps} score={score:.3f} rewards={rewards_str}",
|
| 31 |
+
flush=True,
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
|
| 35 |
+
class HeuristicCoordinator:
|
| 36 |
+
"""Simple policy for baseline demonstrations and offline data generation."""
|
| 37 |
+
|
| 38 |
+
def __init__(self) -> None:
|
| 39 |
+
self._phase_by_incident: Dict[str, int] = {}
|
| 40 |
+
self._suspects_by_incident: Dict[str, str] = {}
|
| 41 |
+
|
| 42 |
+
def select_action(self, observation) -> IncidentAction:
|
| 43 |
+
incident_id = observation.incident_id
|
| 44 |
+
text = (
|
| 45 |
+
f"{observation.incident_title} {observation.incident_description} "
|
| 46 |
+
f"{' '.join(observation.visible_signals)} {observation.terminal_output}"
|
| 47 |
+
).lower()
|
| 48 |
+
phase = self._phase_by_incident.get(incident_id, 0)
|
| 49 |
+
|
| 50 |
+
if phase == 0:
|
| 51 |
+
self._phase_by_incident[incident_id] = 1
|
| 52 |
+
return IncidentAction(
|
| 53 |
+
actor="triage_agent",
|
| 54 |
+
action_type="inspect_logs",
|
| 55 |
+
target=self._pick_log_target(text),
|
| 56 |
+
)
|
| 57 |
+
if phase == 1:
|
| 58 |
+
self._phase_by_incident[incident_id] = 2
|
| 59 |
+
return IncidentAction(
|
| 60 |
+
actor="investigator_agent",
|
| 61 |
+
action_type="inspect_metrics",
|
| 62 |
+
target=self._pick_metric_target(text),
|
| 63 |
+
)
|
| 64 |
+
if phase == 2:
|
| 65 |
+
self._phase_by_incident[incident_id] = 3
|
| 66 |
+
owner = self._pick_owner(text)
|
| 67 |
+
return IncidentAction(
|
| 68 |
+
actor="ops_manager_agent",
|
| 69 |
+
action_type="negotiate_handoff",
|
| 70 |
+
target=owner,
|
| 71 |
+
)
|
| 72 |
+
if phase == 3:
|
| 73 |
+
self._phase_by_incident[incident_id] = 4
|
| 74 |
+
guess = self._infer_root_cause(text)
|
| 75 |
+
self._suspects_by_incident[incident_id] = guess
|
| 76 |
+
return IncidentAction(
|
| 77 |
+
actor="investigator_agent",
|
| 78 |
+
action_type="apply_fix",
|
| 79 |
+
resolution_summary=self._generate_fix_plan(guess),
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
guess = self._suspects_by_incident.get(incident_id, self._infer_root_cause(text))
|
| 83 |
+
return IncidentAction(
|
| 84 |
+
actor="ops_manager_agent",
|
| 85 |
+
action_type="close_incident",
|
| 86 |
+
root_cause=guess,
|
| 87 |
+
resolution_summary=f"Closed with hypothesis {guess}.",
|
| 88 |
)
|
| 89 |
+
|
| 90 |
+
def _pick_log_target(self, text: str) -> str:
|
| 91 |
+
mapping = {
|
| 92 |
+
"checkout": "payments-api",
|
| 93 |
+
"login": "auth-service",
|
| 94 |
+
"catalog": "catalog-api",
|
| 95 |
+
"shipment": "route-planner",
|
| 96 |
+
"invoice": "billing-worker",
|
| 97 |
+
"cascade": "notification-gateway",
|
| 98 |
+
"export": "export-worker",
|
| 99 |
+
"alert": "alert-router",
|
| 100 |
+
"inventory": "inventory-ledger",
|
| 101 |
+
}
|
| 102 |
+
return self._pick_from_mapping(text, mapping, "auth-service")
|
| 103 |
+
|
| 104 |
+
def _pick_metric_target(self, text: str) -> str:
|
| 105 |
+
mapping = {
|
| 106 |
+
"checkout": "dash-redis",
|
| 107 |
+
"login": "dash-auth",
|
| 108 |
+
"catalog": "dash-kafka",
|
| 109 |
+
"shipment": "dash-eta",
|
| 110 |
+
"invoice": "dash-billing",
|
| 111 |
+
"cascade": "dash-notify",
|
| 112 |
+
"export": "dash-export",
|
| 113 |
+
"alert": "dash-alerts",
|
| 114 |
+
"inventory": "dash-inventory",
|
| 115 |
+
}
|
| 116 |
+
return self._pick_from_mapping(text, mapping, "dash-global")
|
| 117 |
+
|
| 118 |
+
def _pick_owner(self, text: str) -> str:
|
| 119 |
+
if any(token in text for token in ["deploy", "rate", "sla", "rotation"]):
|
| 120 |
+
return "ops_manager_agent"
|
| 121 |
+
if any(token in text for token in ["schema", "export", "cache", "inventory"]):
|
| 122 |
+
return "investigator_agent"
|
| 123 |
+
return "triage_agent"
|
| 124 |
+
|
| 125 |
+
def _infer_root_cause(self, text: str) -> str:
|
| 126 |
+
if "redis" in text and "pool" in text:
|
| 127 |
+
return "redis_connection_pool_exhausted"
|
| 128 |
+
if "jwt" in text or "token" in text:
|
| 129 |
+
return "jwt_clock_skew_mismatch"
|
| 130 |
+
if "cache" in text and "invalidation" in text:
|
| 131 |
+
return "cache_invalidation_topic_lag"
|
| 132 |
+
if "timezone" in text or "offset" in text:
|
| 133 |
+
return "timezone_normalization_bug"
|
| 134 |
+
if "idempotency" in text or "duplicate invoice" in text:
|
| 135 |
+
return "idempotency_key_regression"
|
| 136 |
+
if "429" in text or "promo" in text:
|
| 137 |
+
return "rate_limit_misconfigured_for_promo_segment"
|
| 138 |
+
if "schema" in text and "drift" in text:
|
| 139 |
+
return "schema_version_drift"
|
| 140 |
+
if "dedupe" in text or "alert storm" in text:
|
| 141 |
+
return "dedupe_rule_disabled"
|
| 142 |
+
if "out-of-order" in text or "oversell" in text:
|
| 143 |
+
return "event_ordering_race_condition"
|
| 144 |
+
return "unknown"
|
| 145 |
+
|
| 146 |
+
def _generate_fix_plan(self, root_cause: str) -> str:
|
| 147 |
+
fixes = {
|
| 148 |
+
"redis_connection_pool_exhausted": "increase redis pool and recycle stale connections",
|
| 149 |
+
"jwt_clock_skew_mismatch": "sync clock tolerance and increase jwt leeway",
|
| 150 |
+
"cache_invalidation_topic_lag": "scale invalidation consumer and replay partition 3",
|
| 151 |
+
"timezone_normalization_bug": "patch timezone parser and use iana timezone map",
|
| 152 |
+
"idempotency_key_regression": "restore idempotency guard and persist retry token first",
|
| 153 |
+
"rate_limit_misconfigured_for_promo_segment": "hotfix promo segment rate limits and enable exponential backoff",
|
| 154 |
+
"schema_version_drift": "enforce schema negotiation and pin serializer to v11",
|
| 155 |
+
"dedupe_rule_disabled": "restore dedupe rule and replay critical fingerprints",
|
| 156 |
+
"event_ordering_race_condition": "enable sequence guards and quarantine out-of-order events",
|
| 157 |
+
}
|
| 158 |
+
return fixes.get(root_cause, "collect additional diagnostics and rollback last change")
|
| 159 |
+
|
| 160 |
+
def _pick_from_mapping(self, text: str, mapping: Dict[str, str], default: str) -> str:
|
| 161 |
+
for token, value in mapping.items():
|
| 162 |
+
if token in text:
|
| 163 |
+
return value
|
| 164 |
+
return default
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def random_action(observation) -> IncidentAction:
|
| 168 |
+
action_type = random.choice(observation.available_actions or ["inspect_logs"])
|
| 169 |
+
teams = observation.available_teams or ["triage_agent", "investigator_agent", "ops_manager_agent"]
|
| 170 |
+
actor = random.choice(teams)
|
| 171 |
+
random_target = random.choice(
|
| 172 |
+
[
|
| 173 |
+
"payments-api",
|
| 174 |
+
"auth-service",
|
| 175 |
+
"dash-auth",
|
| 176 |
+
"dash-redis",
|
| 177 |
+
"kb-rate-limits",
|
| 178 |
+
"investigator_agent",
|
| 179 |
+
]
|
| 180 |
+
)
|
| 181 |
+
return IncidentAction(
|
| 182 |
+
actor=actor,
|
| 183 |
+
action_type=action_type,
|
| 184 |
+
target=random_target,
|
| 185 |
+
root_cause="unknown",
|
| 186 |
+
resolution_summary="random baseline action",
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
|
| 190 |
async def run_task(task_name: str):
|
| 191 |
+
env = IncidentCommandEnvClient(base_url=ENV_URL).sync()
|
| 192 |
+
policy_name = "random_baseline" if RANDOM_BASELINE else "heuristic_coordinator"
|
| 193 |
+
coordinator = HeuristicCoordinator()
|
| 194 |
+
|
| 195 |
+
log_start(task=task_name, env=BENCHMARK, policy=policy_name)
|
| 196 |
+
|
| 197 |
+
rewards: List[float] = []
|
| 198 |
steps_taken = 0
|
|
|
|
| 199 |
success = False
|
| 200 |
|
| 201 |
try:
|
|
|
|
| 202 |
res = env.reset(task_name=task_name)
|
|
|
|
| 203 |
while not res.done:
|
| 204 |
steps_taken += 1
|
| 205 |
+
action = random_action(res.observation) if RANDOM_BASELINE else coordinator.select_action(
|
| 206 |
+
res.observation
|
| 207 |
+
)
|
| 208 |
+
res = env.step(action)
|
|
|
|
| 209 |
reward = float(res.reward or 0.0)
|
| 210 |
rewards.append(reward)
|
| 211 |
+
log_step(
|
| 212 |
+
step=steps_taken,
|
| 213 |
+
action=f"{action.actor}:{action.action_type}:{action.target or '-'}",
|
| 214 |
+
reward=reward,
|
| 215 |
+
done=res.done,
|
| 216 |
+
error=None,
|
| 217 |
+
)
|
| 218 |
|
|
|
|
| 219 |
score = sum(rewards) / len(rewards) if rewards else 0.0
|
| 220 |
+
success = score > 0.2
|
|
|
|
|
|
|
| 221 |
finally:
|
| 222 |
try:
|
| 223 |
env.close()
|
| 224 |
+
except Exception:
|
| 225 |
pass
|
| 226 |
log_end(success=success, steps=steps_taken, score=score, rewards=rewards)
|
| 227 |
|
| 228 |
+
|
| 229 |
+
def main() -> None:
|
| 230 |
for task in ["easy", "medium", "hard"]:
|
| 231 |
asyncio.run(run_task(task))
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
if __name__ == "__main__":
|
| 235 |
+
main()
|
models.py
CHANGED
|
@@ -1,18 +1,58 @@
|
|
| 1 |
-
from typing import
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, List, Literal, Optional
|
| 2 |
+
|
| 3 |
+
from openenv.core.env_server import Action, Observation, State
|
| 4 |
+
from pydantic import Field
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class IncidentAction(Action):
|
| 8 |
+
action_type: Literal[
|
| 9 |
+
"inspect_logs",
|
| 10 |
+
"inspect_metrics",
|
| 11 |
+
"consult_kb",
|
| 12 |
+
"negotiate_handoff",
|
| 13 |
+
"apply_fix",
|
| 14 |
+
"close_incident",
|
| 15 |
+
] = Field(..., description="The action selected by the acting agent.")
|
| 16 |
+
target: Optional[str] = Field(
|
| 17 |
+
None,
|
| 18 |
+
description="Service/dashboard/knowledge id depending on action_type.",
|
| 19 |
+
)
|
| 20 |
+
root_cause: Optional[str] = Field(
|
| 21 |
+
None,
|
| 22 |
+
description="Predicted root cause when action_type=close_incident.",
|
| 23 |
+
)
|
| 24 |
+
resolution_summary: Optional[str] = Field(
|
| 25 |
+
None,
|
| 26 |
+
description="Human-readable fix summary for apply_fix/close_incident.",
|
| 27 |
+
)
|
| 28 |
+
actor: Literal["triage_agent", "investigator_agent", "ops_manager_agent"] = Field(
|
| 29 |
+
"triage_agent",
|
| 30 |
+
description="Which specialist is currently acting in the environment.",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class IncidentObservation(Observation):
|
| 35 |
+
incident_id: str
|
| 36 |
+
incident_title: str
|
| 37 |
+
incident_description: str
|
| 38 |
+
available_actions: List[str] = Field(default_factory=list)
|
| 39 |
+
available_teams: List[str] = Field(default_factory=list)
|
| 40 |
+
visible_signals: List[str] = Field(default_factory=list)
|
| 41 |
+
terminal_output: str = ""
|
| 42 |
+
budget_remaining: int = 0
|
| 43 |
+
sla_minutes_remaining: int = 0
|
| 44 |
+
incidents_remaining: int = 0
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class IncidentState(State):
|
| 48 |
+
task_id: str = "easy"
|
| 49 |
+
current_incident_index: int = 0
|
| 50 |
+
incidents_resolved: int = 0
|
| 51 |
+
incidents_failed: int = 0
|
| 52 |
+
budget_remaining: int = 0
|
| 53 |
+
sla_minutes_remaining: int = 0
|
| 54 |
+
mitigation_applied: bool = False
|
| 55 |
+
clues_found: List[str] = Field(default_factory=list)
|
| 56 |
+
handoff_history: List[str] = Field(default_factory=list)
|
| 57 |
+
action_trace: List[str] = Field(default_factory=list)
|
| 58 |
+
per_incident_steps: Dict[str, int] = Field(default_factory=dict)
|
openenv.yaml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
name: "
|
| 2 |
-
version: "
|
| 3 |
-
description: "A
|
| 4 |
tasks:
|
| 5 |
- id: "easy"
|
| 6 |
-
description: "
|
| 7 |
- id: "medium"
|
| 8 |
-
description: "
|
| 9 |
- id: "hard"
|
| 10 |
-
description: "
|
|
|
|
| 1 |
+
name: "incident_command_center_env"
|
| 2 |
+
version: "2.0"
|
| 3 |
+
description: "A multi-agent long-horizon environment for incident triage, investigation, and coordinated remediation."
|
| 4 |
tasks:
|
| 5 |
- id: "easy"
|
| 6 |
+
description: "Resolve 2 incidents with clear but noisy signals."
|
| 7 |
- id: "medium"
|
| 8 |
+
description: "Resolve 3 incidents with partial observability and trade-offs."
|
| 9 |
- id: "hard"
|
| 10 |
+
description: "Resolve 4 incidents under strict budget + SLA constraints."
|
pre_validate.sh
CHANGED
|
@@ -10,6 +10,8 @@ openenv validate
|
|
| 10 |
echo "[3/3] Checking Inference Script format..."
|
| 11 |
if [ -f "inference.py" ]; then echo " ✓ inference.py found"; else echo " ✗ inference.py missing"; exit 1; fi
|
| 12 |
|
|
|
|
|
|
|
| 13 |
echo "========================================"
|
| 14 |
echo " Ready for Submission!"
|
| 15 |
echo "========================================"
|
|
|
|
| 10 |
echo "[3/3] Checking Inference Script format..."
|
| 11 |
if [ -f "inference.py" ]; then echo " ✓ inference.py found"; else echo " ✗ inference.py missing"; exit 1; fi
|
| 12 |
|
| 13 |
+
if [ -f "train_trl.py" ]; then echo " ✓ train_trl.py found"; else echo " ✗ train_trl.py missing"; exit 1; fi
|
| 14 |
+
|
| 15 |
echo "========================================"
|
| 16 |
echo " Ready for Submission!"
|
| 17 |
echo "========================================"
|
pyproject.toml
CHANGED
|
@@ -9,23 +9,21 @@ requires = ["setuptools>=45", "wheel"]
|
|
| 9 |
build-backend = "setuptools.build_meta"
|
| 10 |
|
| 11 |
[project]
|
| 12 |
-
name = "openenv-
|
| 13 |
version = "0.1.0"
|
| 14 |
-
description = "
|
| 15 |
requires-python = ">=3.10"
|
| 16 |
dependencies = [
|
| 17 |
-
# Core OpenEnv runtime (provides FastAPI server + HTTP client types)
|
| 18 |
-
# install from github
|
| 19 |
-
# "openenv-core[core] @ git+https://github.com/meta-pytorch/OpenEnv.git",
|
| 20 |
"openenv-core[core]>=0.2.2",
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
]
|
| 30 |
|
| 31 |
[project.optional-dependencies]
|
|
@@ -35,11 +33,10 @@ dev = [
|
|
| 35 |
]
|
| 36 |
|
| 37 |
[project.scripts]
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
[tool.setuptools]
|
| 43 |
include-package-data = true
|
| 44 |
-
|
| 45 |
-
package-dir = { "support_env" = ".", "support_env.server" = "server" }
|
|
|
|
| 9 |
build-backend = "setuptools.build_meta"
|
| 10 |
|
| 11 |
[project]
|
| 12 |
+
name = "openenv-incident-command-center"
|
| 13 |
version = "0.1.0"
|
| 14 |
+
description = "Multi-agent Incident Command Center environment for OpenEnv"
|
| 15 |
requires-python = ">=3.10"
|
| 16 |
dependencies = [
|
|
|
|
|
|
|
|
|
|
| 17 |
"openenv-core[core]>=0.2.2",
|
| 18 |
+
"fastapi>=0.115.0",
|
| 19 |
+
"uvicorn>=0.30.0",
|
| 20 |
+
"pydantic>=2.7.0",
|
| 21 |
+
"transformers>=4.44.0",
|
| 22 |
+
"trl>=0.10.1",
|
| 23 |
+
"datasets>=2.20.0",
|
| 24 |
+
"accelerate>=0.33.0",
|
| 25 |
+
"peft>=0.12.0",
|
| 26 |
+
"matplotlib>=3.8.0",
|
| 27 |
]
|
| 28 |
|
| 29 |
[project.optional-dependencies]
|
|
|
|
| 33 |
]
|
| 34 |
|
| 35 |
[project.scripts]
|
| 36 |
+
server = "server.app:main"
|
| 37 |
+
run-baseline = "inference:main"
|
| 38 |
+
run-training = "train_trl:main"
|
| 39 |
|
| 40 |
[tool.setuptools]
|
| 41 |
include-package-data = true
|
| 42 |
+
py-modules = ["client", "models", "inference", "train_trl"]
|
|
|
requirements.txt
CHANGED
|
@@ -1,4 +1,10 @@
|
|
| 1 |
-
openenv-core
|
| 2 |
-
fastapi
|
| 3 |
-
uvicorn
|
| 4 |
-
pydantic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openenv-core[core]>=0.2.2
|
| 2 |
+
fastapi>=0.115.0
|
| 3 |
+
uvicorn>=0.30.0
|
| 4 |
+
pydantic>=2.7.0
|
| 5 |
+
transformers>=4.44.0
|
| 6 |
+
trl>=0.10.1
|
| 7 |
+
datasets>=2.20.0
|
| 8 |
+
accelerate>=0.33.0
|
| 9 |
+
peft>=0.12.0
|
| 10 |
+
matplotlib>=3.8.0
|
server/Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
WORKDIR /app
|
| 3 |
-
COPY requirements.txt .
|
| 4 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
-
COPY .
|
| 6 |
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
WORKDIR /app
|
| 3 |
+
COPY server/requirements.txt /app/requirements.txt
|
| 4 |
+
RUN pip install --no-cache-dir -r /app/requirements.txt
|
| 5 |
+
COPY . /app
|
| 6 |
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
server/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Server package for Incident Command Center environment."""
|
server/app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from openenv.core.env_server import create_fastapi_app
|
| 2 |
-
from models import
|
| 3 |
-
from server.environment import
|
| 4 |
from fastapi.responses import HTMLResponse
|
| 5 |
import uvicorn
|
| 6 |
|
|
@@ -10,7 +10,7 @@ dashboard_content = r"""
|
|
| 10 |
<head>
|
| 11 |
<meta charset='UTF-8'>
|
| 12 |
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
| 13 |
-
<title>
|
| 14 |
<style>
|
| 15 |
:root { --primary: #3b82f6; --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; }
|
| 16 |
body { font-family: -apple-system, sans-serif; background-color: var(--bg); color: var(--text); padding: 2rem; }
|
|
@@ -20,24 +20,31 @@ dashboard_content = r"""
|
|
| 20 |
</head>
|
| 21 |
<body>
|
| 22 |
<div class='container'>
|
| 23 |
-
<h1>
|
| 24 |
-
<p>
|
| 25 |
|
| 26 |
<h2>Action Space</h2>
|
| 27 |
<ul>
|
| 28 |
-
<li><code>
|
| 29 |
-
<li><code>
|
| 30 |
-
<li><code>
|
|
|
|
|
|
|
|
|
|
| 31 |
</ul>
|
| 32 |
|
| 33 |
<h2>Reward Logic</h2>
|
| 34 |
-
<p>
|
| 35 |
</div>
|
| 36 |
</body>
|
| 37 |
</html>
|
| 38 |
"""
|
| 39 |
|
| 40 |
-
app = create_fastapi_app(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
@app.get('/', response_class=HTMLResponse)
|
| 43 |
@app.get('/web', response_class=HTMLResponse)
|
|
@@ -48,4 +55,4 @@ def main():
|
|
| 48 |
uvicorn.run(app, host='0.0.0.0', port=8000)
|
| 49 |
|
| 50 |
if __name__ == '__main__':
|
| 51 |
-
main()
|
|
|
|
| 1 |
from openenv.core.env_server import create_fastapi_app
|
| 2 |
+
from models import IncidentAction, IncidentObservation
|
| 3 |
+
from server.environment import IncidentCommandCenterEnvironment
|
| 4 |
from fastapi.responses import HTMLResponse
|
| 5 |
import uvicorn
|
| 6 |
|
|
|
|
| 10 |
<head>
|
| 11 |
<meta charset='UTF-8'>
|
| 12 |
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
| 13 |
+
<title>Incident Command Center | OpenEnv Dashboard</title>
|
| 14 |
<style>
|
| 15 |
:root { --primary: #3b82f6; --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; }
|
| 16 |
body { font-family: -apple-system, sans-serif; background-color: var(--bg); color: var(--text); padding: 2rem; }
|
|
|
|
| 20 |
</head>
|
| 21 |
<body>
|
| 22 |
<div class='container'>
|
| 23 |
+
<h1>Multi-Agent Incident Command Center</h1>
|
| 24 |
+
<p>Round-2 themes: Multi-Agent Interactions + World Modeling (Professional Tasks).</p>
|
| 25 |
|
| 26 |
<h2>Action Space</h2>
|
| 27 |
<ul>
|
| 28 |
+
<li><code>inspect_logs(target)</code></li>
|
| 29 |
+
<li><code>inspect_metrics(target)</code></li>
|
| 30 |
+
<li><code>consult_kb(target)</code></li>
|
| 31 |
+
<li><code>negotiate_handoff(target)</code></li>
|
| 32 |
+
<li><code>apply_fix(resolution_summary)</code></li>
|
| 33 |
+
<li><code>close_incident(root_cause)</code></li>
|
| 34 |
</ul>
|
| 35 |
|
| 36 |
<h2>Reward Logic</h2>
|
| 37 |
+
<p>Dense reward shaping for clue discovery, team coordination, and efficient resolution under budget + SLA constraints. Correct closure with mitigation gets the highest reward.</p>
|
| 38 |
</div>
|
| 39 |
</body>
|
| 40 |
</html>
|
| 41 |
"""
|
| 42 |
|
| 43 |
+
app = create_fastapi_app(
|
| 44 |
+
IncidentCommandCenterEnvironment,
|
| 45 |
+
IncidentAction,
|
| 46 |
+
IncidentObservation,
|
| 47 |
+
)
|
| 48 |
|
| 49 |
@app.get('/', response_class=HTMLResponse)
|
| 50 |
@app.get('/web', response_class=HTMLResponse)
|
|
|
|
| 55 |
uvicorn.run(app, host='0.0.0.0', port=8000)
|
| 56 |
|
| 57 |
if __name__ == '__main__':
|
| 58 |
+
main()
|
server/environment.py
CHANGED
|
@@ -1,61 +1,516 @@
|
|
| 1 |
import uuid
|
| 2 |
-
from typing import
|
|
|
|
| 3 |
from openenv.core.env_server import Environment
|
| 4 |
-
from models import SREAction, SREObservation, SREState
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def __init__(self):
|
| 8 |
super().__init__()
|
| 9 |
-
self.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
-
def reset(self, task_name: str = "easy") ->
|
| 28 |
-
|
| 29 |
-
self.
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
def step(self, action:
|
| 34 |
self._state.step_count += 1
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
reward = 0.0
|
| 38 |
terminal_output = ""
|
| 39 |
|
| 40 |
-
if action.action_type == "
|
| 41 |
-
reward =
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
reward =
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
@property
|
| 60 |
-
def state(self) ->
|
| 61 |
-
return self._state
|
|
|
|
| 1 |
import uuid
|
| 2 |
+
from typing import Dict, List
|
| 3 |
+
|
| 4 |
from openenv.core.env_server import Environment
|
|
|
|
| 5 |
|
| 6 |
+
from models import IncidentAction, IncidentObservation, IncidentState
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class IncidentCommandCenterEnvironment(Environment):
|
| 10 |
+
"""Multi-agent, long-horizon SRE incident simulation for OpenEnv."""
|
| 11 |
+
|
| 12 |
def __init__(self):
|
| 13 |
super().__init__()
|
| 14 |
+
self.tasks = self._build_tasks()
|
| 15 |
+
self._task_budgets = {"easy": 24, "medium": 48, "hard": 72}
|
| 16 |
+
self._task_sla = {"easy": 90, "medium": 180, "hard": 300}
|
| 17 |
+
self.current_task: List[Dict[str, object]] = []
|
| 18 |
+
|
| 19 |
+
def _build_tasks(self) -> Dict[str, List[Dict[str, object]]]:
|
| 20 |
+
return {
|
| 21 |
+
"easy": [
|
| 22 |
+
{
|
| 23 |
+
"id": "INC-E1",
|
| 24 |
+
"title": "Checkout timeouts",
|
| 25 |
+
"description": "Payment checkout is failing intermittently for premium users.",
|
| 26 |
+
"root_cause": "redis_connection_pool_exhausted",
|
| 27 |
+
"signals": [
|
| 28 |
+
"Spike in checkout latency for premium cohort",
|
| 29 |
+
"Error budget dropped from 99.9% to 99.2%",
|
| 30 |
+
],
|
| 31 |
+
"logs": {
|
| 32 |
+
"payments-api": "Timeout waiting for redis write lock",
|
| 33 |
+
"checkout-worker": "Queue delay exceeds 12s under load",
|
| 34 |
+
"redis-cluster": "Connection pool exhausted at 512/512",
|
| 35 |
+
},
|
| 36 |
+
"metrics": {
|
| 37 |
+
"dash-checkout": "p99 latency 4.1s, error-rate 6.2%",
|
| 38 |
+
"dash-redis": "connections 512/512, eviction 0, cpu 74%",
|
| 39 |
+
"dash-worker": "queue_depth 440, consumer_lag 380",
|
| 40 |
+
},
|
| 41 |
+
"kb": {
|
| 42 |
+
"kb-redis-pool": "Raise redis pool and recycle stale handles in checkout-worker.",
|
| 43 |
+
"kb-checkout-fallback": "Degrade recommendation calls when payment queue > 300.",
|
| 44 |
+
},
|
| 45 |
+
"good_handoff": "investigator_agent",
|
| 46 |
+
"accepted_fixes": [
|
| 47 |
+
"increase redis pool",
|
| 48 |
+
"recycle stale connections",
|
| 49 |
+
"enable checkout fallback",
|
| 50 |
+
],
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": "INC-E2",
|
| 54 |
+
"title": "Login failures after deploy",
|
| 55 |
+
"description": "Users report frequent login retries after auth rollout.",
|
| 56 |
+
"root_cause": "jwt_clock_skew_mismatch",
|
| 57 |
+
"signals": [
|
| 58 |
+
"Auth errors spike immediately after deployment",
|
| 59 |
+
"Regional variance appears in mobile clients",
|
| 60 |
+
],
|
| 61 |
+
"logs": {
|
| 62 |
+
"auth-service": "Token issued-at in future; rejected by validator",
|
| 63 |
+
"gateway": "401 bursts from auth-service route",
|
| 64 |
+
"mobile-api": "Retrying auth flow due to invalid token state",
|
| 65 |
+
},
|
| 66 |
+
"metrics": {
|
| 67 |
+
"dash-auth": "401_rate 14%, token_validation_failures high",
|
| 68 |
+
"dash-gateway": "auth_route_retries 3.2x baseline",
|
| 69 |
+
},
|
| 70 |
+
"kb": {
|
| 71 |
+
"kb-jwt-time": "Synchronize clock skew tolerance for issuer and verifier.",
|
| 72 |
+
"kb-mobile-auth": "Fallback to server timestamp for token freshness checks.",
|
| 73 |
+
},
|
| 74 |
+
"good_handoff": "ops_manager_agent",
|
| 75 |
+
"accepted_fixes": [
|
| 76 |
+
"increase jwt leeway",
|
| 77 |
+
"sync clock tolerance",
|
| 78 |
+
"roll back token validator",
|
| 79 |
+
],
|
| 80 |
+
},
|
| 81 |
+
],
|
| 82 |
+
"medium": [
|
| 83 |
+
{
|
| 84 |
+
"id": "INC-M1",
|
| 85 |
+
"title": "Catalog stale prices",
|
| 86 |
+
"description": "Users see old prices during flash sale windows.",
|
| 87 |
+
"root_cause": "cache_invalidation_topic_lag",
|
| 88 |
+
"signals": [
|
| 89 |
+
"Mismatch between checkout and catalog prices",
|
| 90 |
+
"Issue concentrated in high-traffic products",
|
| 91 |
+
],
|
| 92 |
+
"logs": {
|
| 93 |
+
"catalog-api": "Read from cache generation=188, expected=193",
|
| 94 |
+
"kafka-consumer": "Lag increased on invalidation-topic partition 3",
|
| 95 |
+
"pricing-service": "Published invalidation events at 2.1k/s",
|
| 96 |
+
},
|
| 97 |
+
"metrics": {
|
| 98 |
+
"dash-catalog": "cache_hit 98%, stale_reads elevated",
|
| 99 |
+
"dash-kafka": "consumer_lag 5400 on partition 3",
|
| 100 |
+
},
|
| 101 |
+
"kb": {
|
| 102 |
+
"kb-cache-invalidation": "Scale invalidation consumers and replay stalled partition.",
|
| 103 |
+
},
|
| 104 |
+
"good_handoff": "investigator_agent",
|
| 105 |
+
"accepted_fixes": [
|
| 106 |
+
"scale invalidation consumer",
|
| 107 |
+
"replay partition 3",
|
| 108 |
+
"flush impacted cache keys",
|
| 109 |
+
],
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"id": "INC-M2",
|
| 113 |
+
"title": "Shipment ETA corruption",
|
| 114 |
+
"description": "Shipping ETAs jump unpredictably after route service update.",
|
| 115 |
+
"root_cause": "timezone_normalization_bug",
|
| 116 |
+
"signals": [
|
| 117 |
+
"ETA jumps by +24h in APAC region",
|
| 118 |
+
"Warehouse scans are on-time, only UI estimate is wrong",
|
| 119 |
+
],
|
| 120 |
+
"logs": {
|
| 121 |
+
"route-planner": "Parsed timezone fallback=UTC for locale en-IN",
|
| 122 |
+
"eta-service": "Normalization mismatch for offset +05:30",
|
| 123 |
+
},
|
| 124 |
+
"metrics": {
|
| 125 |
+
"dash-eta": "eta_anomaly_rate 9.4%",
|
| 126 |
+
"dash-route": "parser_warnings spike post deploy",
|
| 127 |
+
},
|
| 128 |
+
"kb": {
|
| 129 |
+
"kb-timezone": "Use IANA timezone mapping and validate locale fallback path.",
|
| 130 |
+
},
|
| 131 |
+
"good_handoff": "triage_agent",
|
| 132 |
+
"accepted_fixes": [
|
| 133 |
+
"patch timezone parser",
|
| 134 |
+
"use iana timezone map",
|
| 135 |
+
"rollback route update",
|
| 136 |
+
],
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"id": "INC-M3",
|
| 140 |
+
"title": "Invoice duplicates",
|
| 141 |
+
"description": "A subset of merchants received duplicate invoices.",
|
| 142 |
+
"root_cause": "idempotency_key_regression",
|
| 143 |
+
"signals": [
|
| 144 |
+
"Duplicate invoices share same order id",
|
| 145 |
+
"Triggered after billing retry logic change",
|
| 146 |
+
],
|
| 147 |
+
"logs": {
|
| 148 |
+
"billing-worker": "Retry path ignored idempotency token for v2 flow",
|
| 149 |
+
"billing-api": "POST /invoice executed twice for order O-92A",
|
| 150 |
+
},
|
| 151 |
+
"metrics": {
|
| 152 |
+
"dash-billing": "duplicate_invoice_rate 3.7%",
|
| 153 |
+
"dash-worker": "retry_attempts 2.4x",
|
| 154 |
+
},
|
| 155 |
+
"kb": {
|
| 156 |
+
"kb-idempotency": "Persist retry token before dispatch and enforce dedupe check.",
|
| 157 |
+
},
|
| 158 |
+
"good_handoff": "ops_manager_agent",
|
| 159 |
+
"accepted_fixes": [
|
| 160 |
+
"restore idempotency guard",
|
| 161 |
+
"persist retry token first",
|
| 162 |
+
"dedupe duplicate invoice jobs",
|
| 163 |
+
],
|
| 164 |
+
},
|
| 165 |
+
],
|
| 166 |
+
"hard": [
|
| 167 |
+
{
|
| 168 |
+
"id": "INC-H1",
|
| 169 |
+
"title": "Cross-service saturation cascade",
|
| 170 |
+
"description": "A sudden promo launch causes cascading failures across checkout, auth, and notification services.",
|
| 171 |
+
"root_cause": "rate_limit_misconfigured_for_promo_segment",
|
| 172 |
+
"signals": [
|
| 173 |
+
"Failure spreads from notifications to checkout within minutes",
|
| 174 |
+
"Customer segment 'promo_mega' has concentrated failures",
|
| 175 |
+
],
|
| 176 |
+
"logs": {
|
| 177 |
+
"notification-gateway": "429 flood for promo_mega segment",
|
| 178 |
+
"checkout-api": "Retries amplified upstream failures from notification sidecar",
|
| 179 |
+
"auth-service": "Session refresh queue saturation due to retry storm",
|
| 180 |
+
},
|
| 181 |
+
"metrics": {
|
| 182 |
+
"dash-global": "error budget burn 3.7x",
|
| 183 |
+
"dash-notify": "429_rate 38%",
|
| 184 |
+
"dash-auth": "session_queue_depth 940",
|
| 185 |
+
},
|
| 186 |
+
"kb": {
|
| 187 |
+
"kb-rate-limits": "Segment-specific limits must be applied with gradual rollout and backoff.",
|
| 188 |
+
},
|
| 189 |
+
"good_handoff": "ops_manager_agent",
|
| 190 |
+
"accepted_fixes": [
|
| 191 |
+
"hotfix promo segment rate limits",
|
| 192 |
+
"enable exponential backoff",
|
| 193 |
+
"throttle notification fanout",
|
| 194 |
+
],
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"id": "INC-H2",
|
| 198 |
+
"title": "Data export corruption",
|
| 199 |
+
"description": "Enterprise customers report corrupted CSV exports from analytics dashboard.",
|
| 200 |
+
"root_cause": "schema_version_drift",
|
| 201 |
+
"signals": [
|
| 202 |
+
"Corruption only in accounts migrated last week",
|
| 203 |
+
"Export job success is high but data quality is low",
|
| 204 |
+
],
|
| 205 |
+
"logs": {
|
| 206 |
+
"export-worker": "Schema mismatch: expected v11 got v10 on tenant shard",
|
| 207 |
+
"analytics-api": "Fallback serializer dropped nullable columns",
|
| 208 |
+
},
|
| 209 |
+
"metrics": {
|
| 210 |
+
"dash-export": "job_success 97%, data_quality_score 61%",
|
| 211 |
+
"dash-analytics": "schema_mismatch counter rising",
|
| 212 |
+
},
|
| 213 |
+
"kb": {
|
| 214 |
+
"kb-schema-drift": "Force schema negotiation at read time and backfill migrated shards.",
|
| 215 |
+
},
|
| 216 |
+
"good_handoff": "investigator_agent",
|
| 217 |
+
"accepted_fixes": [
|
| 218 |
+
"enforce schema negotiation",
|
| 219 |
+
"backfill migrated shards",
|
| 220 |
+
"pin serializer to v11",
|
| 221 |
+
],
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"id": "INC-H3",
|
| 225 |
+
"title": "On-call alert storm",
|
| 226 |
+
"description": "On-call rotations are overwhelmed by noisy duplicate alerts, masking a real outage.",
|
| 227 |
+
"root_cause": "dedupe_rule_disabled",
|
| 228 |
+
"signals": [
|
| 229 |
+
"Alert volume 10x baseline with low incident diversity",
|
| 230 |
+
"Primary outage not visible in first-page alerts",
|
| 231 |
+
],
|
| 232 |
+
"logs": {
|
| 233 |
+
"alert-router": "Deduplication pipeline bypassed after config reload",
|
| 234 |
+
"pager-service": "Repeated notifications for identical fingerprint",
|
| 235 |
+
},
|
| 236 |
+
"metrics": {
|
| 237 |
+
"dash-alerts": "alerts_per_minute 1200",
|
| 238 |
+
"dash-pager": "notification_duplicates 87%",
|
| 239 |
+
},
|
| 240 |
+
"kb": {
|
| 241 |
+
"kb-alert-dedupe": "Restore dedupe stage and replay suppressed critical fingerprint set.",
|
| 242 |
+
},
|
| 243 |
+
"good_handoff": "triage_agent",
|
| 244 |
+
"accepted_fixes": [
|
| 245 |
+
"restore dedupe rule",
|
| 246 |
+
"replay critical fingerprints",
|
| 247 |
+
"mute duplicate alert channels",
|
| 248 |
+
],
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"id": "INC-H4",
|
| 252 |
+
"title": "Inventory phantom stock",
|
| 253 |
+
"description": "Inventory service reports available stock that does not exist in warehouse.",
|
| 254 |
+
"root_cause": "event_ordering_race_condition",
|
| 255 |
+
"signals": [
|
| 256 |
+
"Negative physical stock but positive ledger entries",
|
| 257 |
+
"Warehouse reconciliation jobs are delayed",
|
| 258 |
+
],
|
| 259 |
+
"logs": {
|
| 260 |
+
"inventory-ledger": "Out-of-order reserve/release events for same SKU",
|
| 261 |
+
"warehouse-sync": "Late event merge exceeded ordering window",
|
| 262 |
+
},
|
| 263 |
+
"metrics": {
|
| 264 |
+
"dash-inventory": "oversell_incidents 4.2%",
|
| 265 |
+
"dash-sync": "late_event_ratio 17%",
|
| 266 |
+
},
|
| 267 |
+
"kb": {
|
| 268 |
+
"kb-event-ordering": "Use monotonic sequence guards and quarantine out-of-order events.",
|
| 269 |
+
},
|
| 270 |
+
"good_handoff": "investigator_agent",
|
| 271 |
+
"accepted_fixes": [
|
| 272 |
+
"enable sequence guards",
|
| 273 |
+
"quarantine out-of-order events",
|
| 274 |
+
"reconcile affected skus",
|
| 275 |
+
],
|
| 276 |
+
},
|
| 277 |
+
],
|
| 278 |
}
|
| 279 |
|
| 280 |
+
def reset(self, task_name: str = "easy") -> IncidentObservation:
|
| 281 |
+
selected_task = task_name if task_name in self.tasks else "easy"
|
| 282 |
+
self.current_task = self.tasks[selected_task]
|
| 283 |
+
self._state = IncidentState(
|
| 284 |
+
episode_id=str(uuid.uuid4()),
|
| 285 |
+
task_id=selected_task,
|
| 286 |
+
current_incident_index=0,
|
| 287 |
+
budget_remaining=self._task_budgets[selected_task],
|
| 288 |
+
sla_minutes_remaining=self._task_sla[selected_task],
|
| 289 |
+
)
|
| 290 |
+
return self._observation_for_current_incident(
|
| 291 |
+
terminal_output=(
|
| 292 |
+
"Incident Command Center initialized. "
|
| 293 |
+
"Coordinate triage_agent, investigator_agent, and ops_manager_agent."
|
| 294 |
+
),
|
| 295 |
+
reward=0.0,
|
| 296 |
+
done=False,
|
| 297 |
+
)
|
| 298 |
|
| 299 |
+
def step(self, action: IncidentAction) -> IncidentObservation:
|
| 300 |
self._state.step_count += 1
|
| 301 |
+
self._state.sla_minutes_remaining = max(0, self._state.sla_minutes_remaining - 5)
|
| 302 |
+
self._state.budget_remaining -= 1
|
| 303 |
+
|
| 304 |
+
if self._state.current_incident_index >= len(self.current_task):
|
| 305 |
+
return IncidentObservation(
|
| 306 |
+
done=True,
|
| 307 |
+
reward=0.0,
|
| 308 |
+
incident_id="EOF",
|
| 309 |
+
incident_title="All incidents completed",
|
| 310 |
+
incident_description="Episode ended.",
|
| 311 |
+
terminal_output="No remaining incidents.",
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
if self._state.budget_remaining < 0:
|
| 315 |
+
self._state.incidents_failed += 1
|
| 316 |
+
return IncidentObservation(
|
| 317 |
+
done=True,
|
| 318 |
+
reward=-1.5,
|
| 319 |
+
incident_id="BUDGET_EXHAUSTED",
|
| 320 |
+
incident_title="Resource budget exhausted",
|
| 321 |
+
incident_description="Agent used too many actions before finishing the task.",
|
| 322 |
+
terminal_output="Episode terminated: investigation budget exhausted.",
|
| 323 |
+
budget_remaining=0,
|
| 324 |
+
sla_minutes_remaining=self._state.sla_minutes_remaining,
|
| 325 |
+
incidents_remaining=len(self.current_task) - self._state.current_incident_index,
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
incident = self.current_task[self._state.current_incident_index]
|
| 329 |
+
incident_id = str(incident["id"])
|
| 330 |
+
self._state.per_incident_steps[incident_id] = (
|
| 331 |
+
self._state.per_incident_steps.get(incident_id, 0) + 1
|
| 332 |
+
)
|
| 333 |
+
self._state.action_trace.append(f"{action.actor}:{action.action_type}:{action.target or '-'}")
|
| 334 |
+
|
| 335 |
+
if self._state.sla_minutes_remaining <= 0:
|
| 336 |
+
self._state.incidents_failed += 1
|
| 337 |
+
return IncidentObservation(
|
| 338 |
+
done=True,
|
| 339 |
+
reward=-1.2,
|
| 340 |
+
incident_id=incident_id,
|
| 341 |
+
incident_title=str(incident["title"]),
|
| 342 |
+
incident_description=str(incident["description"]),
|
| 343 |
+
terminal_output="Episode terminated: global SLA budget reached zero.",
|
| 344 |
+
budget_remaining=max(self._state.budget_remaining, 0),
|
| 345 |
+
sla_minutes_remaining=0,
|
| 346 |
+
incidents_remaining=len(self.current_task) - self._state.current_incident_index,
|
| 347 |
+
)
|
| 348 |
|
| 349 |
reward = 0.0
|
| 350 |
terminal_output = ""
|
| 351 |
|
| 352 |
+
if action.action_type == "inspect_logs":
|
| 353 |
+
reward -= 0.04
|
| 354 |
+
lookup = (action.target or "").strip()
|
| 355 |
+
logs = incident["logs"]
|
| 356 |
+
terminal_output = logs.get(lookup, f"No logs found for target '{lookup}'.")
|
| 357 |
+
reward += self._grant_clue_reward(incident, terminal_output)
|
| 358 |
+
|
| 359 |
+
elif action.action_type == "inspect_metrics":
|
| 360 |
+
reward -= 0.04
|
| 361 |
+
lookup = (action.target or "").strip()
|
| 362 |
+
metrics = incident["metrics"]
|
| 363 |
+
terminal_output = metrics.get(lookup, f"No metrics found for target '{lookup}'.")
|
| 364 |
+
reward += self._grant_clue_reward(incident, terminal_output)
|
| 365 |
+
|
| 366 |
+
elif action.action_type == "consult_kb":
|
| 367 |
+
reward -= 0.03
|
| 368 |
+
lookup = (action.target or "").strip()
|
| 369 |
+
kb = incident["kb"]
|
| 370 |
+
terminal_output = kb.get(lookup, f"No KB article found for key '{lookup}'.")
|
| 371 |
+
reward += self._grant_clue_reward(incident, terminal_output)
|
| 372 |
+
|
| 373 |
+
elif action.action_type == "negotiate_handoff":
|
| 374 |
+
reward -= 0.02
|
| 375 |
+
team = (action.target or "").strip()
|
| 376 |
+
self._state.handoff_history.append(team)
|
| 377 |
+
if team == incident["good_handoff"]:
|
| 378 |
+
reward += 0.12
|
| 379 |
+
terminal_output = (
|
| 380 |
+
f"Handoff accepted by {team}. "
|
| 381 |
+
"New hypothesis confidence increased."
|
| 382 |
+
)
|
| 383 |
+
else:
|
| 384 |
+
reward -= 0.10
|
| 385 |
+
terminal_output = (
|
| 386 |
+
f"Handoff to {team} introduced delay. "
|
| 387 |
+
"This incident likely needs a different owner."
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
elif action.action_type == "apply_fix":
|
| 391 |
+
reward -= 0.02
|
| 392 |
+
fix_text = (action.resolution_summary or "").lower()
|
| 393 |
+
accepted_fixes = incident["accepted_fixes"]
|
| 394 |
+
is_good_fix = any(token in fix_text for token in accepted_fixes)
|
| 395 |
+
if is_good_fix:
|
| 396 |
+
self._state.mitigation_applied = True
|
| 397 |
+
reward += 0.35
|
| 398 |
+
terminal_output = "Mitigation accepted. Error rate is stabilizing."
|
| 399 |
+
else:
|
| 400 |
+
reward -= 0.30
|
| 401 |
+
terminal_output = "Applied mitigation appears ineffective."
|
| 402 |
+
|
| 403 |
+
elif action.action_type == "close_incident":
|
| 404 |
+
guess = (action.root_cause or "").strip().lower()
|
| 405 |
+
expected = str(incident["root_cause"]).lower()
|
| 406 |
+
correct = guess == expected
|
| 407 |
+
episode_done = False
|
| 408 |
+
if correct:
|
| 409 |
+
completion_reward = 0.80
|
| 410 |
+
if self._state.mitigation_applied:
|
| 411 |
+
completion_reward += 0.30
|
| 412 |
+
completion_reward += self._speed_bonus(incident_id)
|
| 413 |
+
reward += completion_reward
|
| 414 |
+
self._state.incidents_resolved += 1
|
| 415 |
+
terminal_output = (
|
| 416 |
+
"Incident resolved successfully. "
|
| 417 |
+
f"Root cause confirmed: {incident['root_cause']}."
|
| 418 |
+
)
|
| 419 |
+
else:
|
| 420 |
+
reward -= 1.10
|
| 421 |
+
self._state.incidents_failed += 1
|
| 422 |
+
terminal_output = (
|
| 423 |
+
"Incident closure rejected by postmortem checker. "
|
| 424 |
+
f"Expected root cause differs from '{guess or 'unknown'}'."
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
self._advance_incident()
|
| 428 |
+
if self._state.current_incident_index >= len(self.current_task):
|
| 429 |
+
episode_done = True
|
| 430 |
+
terminal_output += " All assigned incidents processed."
|
| 431 |
+
else:
|
| 432 |
+
next_incident = self.current_task[self._state.current_incident_index]
|
| 433 |
+
terminal_output += f" Next incident: {next_incident['id']}."
|
| 434 |
+
|
| 435 |
+
return self._observation_for_current_incident(
|
| 436 |
+
terminal_output=terminal_output,
|
| 437 |
+
reward=reward,
|
| 438 |
+
done=episode_done,
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
else:
|
| 442 |
+
reward -= 0.25
|
| 443 |
+
terminal_output = f"Unsupported action_type: {action.action_type}"
|
| 444 |
+
|
| 445 |
+
return self._observation_for_current_incident(
|
| 446 |
+
terminal_output=terminal_output,
|
| 447 |
+
reward=reward,
|
| 448 |
+
done=False,
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
def _grant_clue_reward(self, incident: Dict[str, object], signal_text: str) -> float:
|
| 452 |
+
root = str(incident["root_cause"]).lower()
|
| 453 |
+
signal_key = signal_text.strip().lower()
|
| 454 |
+
if root in signal_key and signal_key not in self._state.clues_found:
|
| 455 |
+
self._state.clues_found.append(signal_key)
|
| 456 |
+
return 0.12
|
| 457 |
+
return 0.0
|
| 458 |
+
|
| 459 |
+
def _speed_bonus(self, incident_id: str) -> float:
|
| 460 |
+
steps_used = self._state.per_incident_steps.get(incident_id, 1)
|
| 461 |
+
if steps_used <= 4:
|
| 462 |
+
return 0.20
|
| 463 |
+
if steps_used <= 7:
|
| 464 |
+
return 0.10
|
| 465 |
+
return 0.0
|
| 466 |
+
|
| 467 |
+
def _advance_incident(self) -> None:
|
| 468 |
+
self._state.current_incident_index += 1
|
| 469 |
+
self._state.mitigation_applied = False
|
| 470 |
+
self._state.clues_found = []
|
| 471 |
+
|
| 472 |
+
def _observation_for_current_incident(
|
| 473 |
+
self, terminal_output: str, reward: float, done: bool
|
| 474 |
+
) -> IncidentObservation:
|
| 475 |
+
if done:
|
| 476 |
+
return IncidentObservation(
|
| 477 |
+
done=True,
|
| 478 |
+
reward=reward,
|
| 479 |
+
incident_id="EOF",
|
| 480 |
+
incident_title="All incidents completed",
|
| 481 |
+
incident_description="Episode ended.",
|
| 482 |
+
available_actions=[],
|
| 483 |
+
available_teams=[],
|
| 484 |
+
visible_signals=[],
|
| 485 |
+
terminal_output=terminal_output,
|
| 486 |
+
budget_remaining=max(self._state.budget_remaining, 0),
|
| 487 |
+
sla_minutes_remaining=self._state.sla_minutes_remaining,
|
| 488 |
+
incidents_remaining=0,
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
incident = self.current_task[self._state.current_incident_index]
|
| 492 |
+
return IncidentObservation(
|
| 493 |
+
done=False,
|
| 494 |
+
reward=reward,
|
| 495 |
+
incident_id=str(incident["id"]),
|
| 496 |
+
incident_title=str(incident["title"]),
|
| 497 |
+
incident_description=str(incident["description"]),
|
| 498 |
+
available_actions=[
|
| 499 |
+
"inspect_logs",
|
| 500 |
+
"inspect_metrics",
|
| 501 |
+
"consult_kb",
|
| 502 |
+
"negotiate_handoff",
|
| 503 |
+
"apply_fix",
|
| 504 |
+
"close_incident",
|
| 505 |
+
],
|
| 506 |
+
available_teams=["triage_agent", "investigator_agent", "ops_manager_agent"],
|
| 507 |
+
visible_signals=list(incident["signals"]),
|
| 508 |
+
terminal_output=terminal_output,
|
| 509 |
+
budget_remaining=max(self._state.budget_remaining, 0),
|
| 510 |
+
sla_minutes_remaining=self._state.sla_minutes_remaining,
|
| 511 |
+
incidents_remaining=len(self.current_task) - self._state.current_incident_index,
|
| 512 |
+
)
|
| 513 |
|
| 514 |
@property
|
| 515 |
+
def state(self) -> IncidentState:
|
| 516 |
+
return self._state
|
server/requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
openenv[core]>=0.2.
|
| 2 |
fastapi>=0.115.0
|
| 3 |
uvicorn>=0.24.0
|
| 4 |
|
|
|
|
| 1 |
+
openenv-core[core]>=0.2.2
|
| 2 |
fastapi>=0.115.0
|
| 3 |
uvicorn>=0.24.0
|
| 4 |
|
server/support_env_environment.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Backward-compatible alias for older imports."""
|
| 2 |
+
|
| 3 |
+
from server.environment import IncidentCommandCenterEnvironment
|
| 4 |
+
|
| 5 |
+
SupportEnvEnvironment = IncidentCommandCenterEnvironment
|
train_trl.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Dict, List
|
| 7 |
+
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
from datasets import Dataset
|
| 10 |
+
|
| 11 |
+
from client import IncidentCommandEnvClient
|
| 12 |
+
from inference import HeuristicCoordinator, random_action
|
| 13 |
+
from models import IncidentAction
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
ARTIFACT_DIR = Path("artifacts")
|
| 17 |
+
ARTIFACT_DIR.mkdir(parents=True, exist_ok=True)
|
| 18 |
+
|
| 19 |
+
ENV_URL = os.getenv("ENV_URL", "http://127.0.0.1:8000")
|
| 20 |
+
BASE_MODEL = os.getenv("BASE_MODEL", "Qwen/Qwen2.5-1.5B-Instruct")
|
| 21 |
+
MAX_ROLLOUT_STEPS = int(os.getenv("MAX_ROLLOUT_STEPS", "120"))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@dataclass
|
| 25 |
+
class EpisodeStats:
|
| 26 |
+
policy_name: str
|
| 27 |
+
task_name: str
|
| 28 |
+
total_reward: float
|
| 29 |
+
steps: int
|
| 30 |
+
success: bool
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def obs_to_prompt(obs) -> str:
|
| 34 |
+
return (
|
| 35 |
+
"You are controlling a multi-agent incident command center.\n"
|
| 36 |
+
f"Incident ID: {obs.incident_id}\n"
|
| 37 |
+
f"Title: {obs.incident_title}\n"
|
| 38 |
+
f"Description: {obs.incident_description}\n"
|
| 39 |
+
f"Visible signals: {', '.join(obs.visible_signals)}\n"
|
| 40 |
+
f"Budget remaining: {obs.budget_remaining}\n"
|
| 41 |
+
f"SLA minutes remaining: {obs.sla_minutes_remaining}\n"
|
| 42 |
+
f"Terminal output: {obs.terminal_output}\n"
|
| 43 |
+
"Return a JSON object with keys: actor, action_type, target, root_cause, resolution_summary."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def action_to_json(action: IncidentAction) -> str:
|
| 48 |
+
return json.dumps(action.model_dump(exclude_none=True), ensure_ascii=True)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def rollout(policy_name: str, task_name: str, collect_dataset: bool = False):
|
| 52 |
+
env = IncidentCommandEnvClient(base_url=ENV_URL).sync()
|
| 53 |
+
coordinator = HeuristicCoordinator()
|
| 54 |
+
records: List[Dict[str, str]] = []
|
| 55 |
+
rewards: List[float] = []
|
| 56 |
+
steps = 0
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
result = env.reset(task_name=task_name)
|
| 60 |
+
while not result.done and steps < MAX_ROLLOUT_STEPS:
|
| 61 |
+
steps += 1
|
| 62 |
+
if policy_name == "heuristic":
|
| 63 |
+
action = coordinator.select_action(result.observation)
|
| 64 |
+
else:
|
| 65 |
+
action = random_action(result.observation)
|
| 66 |
+
|
| 67 |
+
if collect_dataset:
|
| 68 |
+
records.append(
|
| 69 |
+
{
|
| 70 |
+
"prompt": obs_to_prompt(result.observation),
|
| 71 |
+
"response": action_to_json(action),
|
| 72 |
+
}
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
result = env.step(action)
|
| 76 |
+
rewards.append(float(result.reward or 0.0))
|
| 77 |
+
finally:
|
| 78 |
+
try:
|
| 79 |
+
env.close()
|
| 80 |
+
except Exception:
|
| 81 |
+
pass
|
| 82 |
+
|
| 83 |
+
total_reward = sum(rewards)
|
| 84 |
+
success = total_reward > 0.0
|
| 85 |
+
return EpisodeStats(policy_name, task_name, total_reward, steps, success), records, rewards
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def build_training_dataset(episodes_per_task: int = 4) -> Dataset:
|
| 89 |
+
all_rows: List[Dict[str, str]] = []
|
| 90 |
+
for task in ["easy", "medium", "hard"]:
|
| 91 |
+
for _ in range(episodes_per_task):
|
| 92 |
+
_, rows, _ = rollout(policy_name="heuristic", task_name=task, collect_dataset=True)
|
| 93 |
+
all_rows.extend(rows)
|
| 94 |
+
return Dataset.from_list(all_rows)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def run_trl_sft(dataset: Dataset) -> None:
|
| 98 |
+
"""
|
| 99 |
+
Minimal TRL script.
|
| 100 |
+
This intentionally stays lightweight for CPU-friendly reproducibility.
|
| 101 |
+
For actual hackathon runs, execute in Colab with a GPU and adjust params.
|
| 102 |
+
"""
|
| 103 |
+
try:
|
| 104 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 105 |
+
from trl import SFTConfig, SFTTrainer
|
| 106 |
+
except ImportError as exc:
|
| 107 |
+
raise RuntimeError(
|
| 108 |
+
"Missing training dependencies. Install with: pip install -r requirements.txt"
|
| 109 |
+
) from exc
|
| 110 |
+
|
| 111 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 112 |
+
if tokenizer.pad_token is None:
|
| 113 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 114 |
+
|
| 115 |
+
model = AutoModelForCausalLM.from_pretrained(BASE_MODEL)
|
| 116 |
+
|
| 117 |
+
def formatting_func(example):
|
| 118 |
+
return f"<|user|>\n{example['prompt']}\n<|assistant|>\n{example['response']}"
|
| 119 |
+
|
| 120 |
+
config = SFTConfig(
|
| 121 |
+
output_dir="outputs/sft_run",
|
| 122 |
+
per_device_train_batch_size=1,
|
| 123 |
+
gradient_accumulation_steps=2,
|
| 124 |
+
learning_rate=2e-5,
|
| 125 |
+
num_train_epochs=1,
|
| 126 |
+
max_seq_length=768,
|
| 127 |
+
logging_steps=5,
|
| 128 |
+
save_strategy="no",
|
| 129 |
+
report_to=[],
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
trainer = SFTTrainer(
|
| 133 |
+
model=model,
|
| 134 |
+
args=config,
|
| 135 |
+
train_dataset=dataset,
|
| 136 |
+
formatting_func=formatting_func,
|
| 137 |
+
)
|
| 138 |
+
trainer.train()
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def evaluate_policies() -> Dict[str, List[float]]:
|
| 142 |
+
random_scores: List[float] = []
|
| 143 |
+
heuristic_scores: List[float] = []
|
| 144 |
+
|
| 145 |
+
for task in ["easy", "medium", "hard"]:
|
| 146 |
+
random.seed(7)
|
| 147 |
+
random_stats, _, _ = rollout("random", task)
|
| 148 |
+
heuristic_stats, _, _ = rollout("heuristic", task)
|
| 149 |
+
random_scores.append(random_stats.total_reward)
|
| 150 |
+
heuristic_scores.append(heuristic_stats.total_reward)
|
| 151 |
+
|
| 152 |
+
return {"random": random_scores, "heuristic": heuristic_scores}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def plot_rewards(score_map: Dict[str, List[float]]) -> None:
|
| 156 |
+
labels = ["easy", "medium", "hard"]
|
| 157 |
+
x = list(range(len(labels)))
|
| 158 |
+
plt.figure(figsize=(8, 4.5))
|
| 159 |
+
plt.plot(x, score_map["random"], marker="o", label="Random baseline")
|
| 160 |
+
plt.plot(x, score_map["heuristic"], marker="o", label="Heuristic coordinator")
|
| 161 |
+
plt.xticks(x, labels)
|
| 162 |
+
plt.xlabel("Task difficulty")
|
| 163 |
+
plt.ylabel("Episode total reward")
|
| 164 |
+
plt.title("Incident Command Center: baseline comparison")
|
| 165 |
+
plt.grid(alpha=0.3)
|
| 166 |
+
plt.legend()
|
| 167 |
+
plt.tight_layout()
|
| 168 |
+
plt.savefig(ARTIFACT_DIR / "reward_curve.png", dpi=160)
|
| 169 |
+
plt.close()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def main() -> None:
|
| 173 |
+
dataset = build_training_dataset(episodes_per_task=3)
|
| 174 |
+
dataset.save_to_disk("artifacts/trl_dataset")
|
| 175 |
+
|
| 176 |
+
run_trl_sft(dataset)
|
| 177 |
+
scores = evaluate_policies()
|
| 178 |
+
plot_rewards(scores)
|
| 179 |
+
|
| 180 |
+
summary = {
|
| 181 |
+
"base_model": BASE_MODEL,
|
| 182 |
+
"dataset_rows": len(dataset),
|
| 183 |
+
"random_rewards": scores["random"],
|
| 184 |
+
"heuristic_rewards": scores["heuristic"],
|
| 185 |
+
}
|
| 186 |
+
with open(ARTIFACT_DIR / "summary_metrics.json", "w", encoding="utf-8") as f:
|
| 187 |
+
json.dump(summary, f, indent=2)
|
| 188 |
+
|
| 189 |
+
print("Training and evaluation complete.")
|
| 190 |
+
print(f"Saved artifacts in: {ARTIFACT_DIR.resolve()}")
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
if __name__ == "__main__":
|
| 194 |
+
main()
|
validate-submission.sh
CHANGED
|
@@ -20,6 +20,11 @@ portable_mktemp() {
|
|
| 20 |
PING_URL="${1:-}"
|
| 21 |
REPO_DIR="${2:-.}"
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
log() { printf "[%s] %b\n" "$(date -u +%H:%M:%S)" "$*"; }
|
| 24 |
pass() { log "${GREEN}PASSED${NC} -- $1"; }
|
| 25 |
fail() { log "${RED}FAILED${NC} -- $1"; }
|
|
|
|
| 20 |
PING_URL="${1:-}"
|
| 21 |
REPO_DIR="${2:-.}"
|
| 22 |
|
| 23 |
+
if [ -z "$PING_URL" ]; then
|
| 24 |
+
printf "Usage: ./validate-submission.sh <hf_space_url> [repo_dir]\n"
|
| 25 |
+
exit 1
|
| 26 |
+
fi
|
| 27 |
+
|
| 28 |
log() { printf "[%s] %b\n" "$(date -u +%H:%M:%S)" "$*"; }
|
| 29 |
pass() { log "${GREEN}PASSED${NC} -- $1"; }
|
| 30 |
fail() { log "${RED}FAILED${NC} -- $1"; }
|