Spaces:
Runtime error
Runtime error
File size: 2,010 Bytes
205f6c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """
Dynamics - state transition logic for the DebugOps environment.
The agent must perform the correct multi-step fix sequence to resolve
an incident. Wrong actions degrade system metrics.
"""
from __future__ import annotations
from typing import Dict, Any
def apply_action(state: Dict[str, Any], action: str) -> Dict[str, Any]:
"""
Mutate-and-return state after the agent takes `action`.
Resolution logic
----------------
Each root cause has a `fix_sequence` list stored inside state.
The agent must perform each action in order:
- Correct step → fix_progress += 1; metrics partially improve
- Wrong step → metrics degrade further
- All steps done → resolved = True, metrics recover
"""
seq = state["fix_sequence"]
prog = state["fix_progress"]
if prog < len(seq) and action == seq[prog]:
# Correct action
state["fix_progress"] += 1
prog += 1
state["metrics"]["latency"] *= 0.85
state["metrics"]["error_rate"] *= 0.80
state["metrics"]["cpu"] *= 0.90
if prog == len(seq):
state["resolved"] = True
state["metrics"]["latency"] = max(state["metrics"]["latency"] * 0.5, 30)
state["metrics"]["error_rate"] = max(state["metrics"]["error_rate"] * 0.1, 0.01)
state["metrics"]["cpu"] = max(state["metrics"]["cpu"] * 0.6, 20)
for svc in state["services"]:
state["services"][svc] = "healthy"
else:
state["metrics"]["latency"] = min(state["metrics"]["latency"] * 1.12, 2000)
state["metrics"]["error_rate"] = min(state["metrics"]["error_rate"] * 1.10, 1.0)
state["metrics"]["cpu"] = min(state["metrics"]["cpu"] * 1.05, 100)
if not state["resolved"]:
state["metrics"]["latency"] = min(state["metrics"]["latency"] * 1.03, 2000)
state["metrics"]["cpu"] = min(state["metrics"]["cpu"] * 1.01, 100)
return state |