File size: 2,803 Bytes
3ef7678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
Pydantic models for the Repair Strategy System V2 OpenEnv environment.
"""

from __future__ import annotations
from enum import Enum
from typing import Dict, List, Literal, Optional
from pydantic import BaseModel, Field


class ComponentStatus(str, Enum):
    healthy = "healthy"
    degraded = "degraded"
    down = "down"


class ActionType(str, Enum):
    restart_service = "restart_service"
    scale_up = "scale_up"
    clear_cache = "clear_cache"
    repair_database = "repair_database"
    inspect_database = "inspect_database"
    inspect_api = "inspect_api"
    inspect_cache = "inspect_cache"
    inspect_queue = "inspect_queue"
    no_op = "no_op"


class ComponentTarget(str, Enum):
    database = "database"
    api = "api"
    cache = "cache"
    queue = "queue"


class LogSeverity(str, Enum):
    INFO = "INFO"
    WARN = "WARN"
    ERROR = "ERROR"


class LogEntry(BaseModel):
    timestamp: int
    message: str
    severity: LogSeverity
    
    model_config = {"use_enum_values": True}


class ComponentMetrics(BaseModel):
    latency: int = Field(..., ge=0)
    error_rate: float = Field(..., ge=0.0, le=1.0)
    queue_load: float = Field(..., ge=0.0)
    cpu_usage: float = Field(..., ge=0.0, le=100.0)


class SymptomObservation(BaseModel):
    """V2 Observation: True state is hidden. The agent only sees symptoms."""
    metrics: Dict[str, ComponentMetrics]
    logs: List[LogEntry]
    step_count: int = Field(..., ge=0)
    max_steps: int = Field(..., ge=1)
    inspections_remaining: int = Field(..., ge=0)

    model_config = {"use_enum_values": True}


class InspectResult(BaseModel):
    component: ComponentTarget
    hint: str
    confidence: float = Field(..., ge=0.0, le=1.0)
    is_likely_root_cause: bool
    
    model_config = {"use_enum_values": True}


class Action(BaseModel):
    action_type: ActionType
    target: ComponentTarget

    model_config = {"use_enum_values": True}


class Diagnosis(BaseModel):
    root_causes: List[ComponentTarget]
    confidence: float = Field(..., ge=0.0, le=1.0)
    
    model_config = {"use_enum_values": True}


class Reward(BaseModel):
    value: float
    reason: str


class EpisodeResultV2(BaseModel):
    task_id: str
    steps_taken: int
    total_reward: float
    score: float
    success: bool
    final_health_ratio: float
    efficiency: float
    correct_root_fix_ratio: float

    model_config = {"use_enum_values": True}

# V3 Action Costs
ACTION_COSTS = {
    ActionType.repair_database: -0.5,
    ActionType.restart_service: -0.2,
    ActionType.clear_cache: -0.2,
    ActionType.scale_up: -0.5,
    ActionType.inspect_database: 0.0, # Handled dynamically (free vs paid)
    ActionType.inspect_api: 0.0,
    ActionType.inspect_cache: 0.0,
    ActionType.inspect_queue: 0.0,
    ActionType.no_op: 0.0
}