Spaces:
Runtime error
Runtime error
| """ | |
| 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 |