File size: 1,613 Bytes
65ae195
 
14b6f9b
 
 
 
 
 
65ae195
 
 
14b6f9b
 
 
65ae195
14b6f9b
65ae195
14b6f9b
 
961dad9
 
 
 
 
 
 
 
 
 
 
 
 
 
14b6f9b
 
65ae195
 
 
961dad9
65ae195
 
 
961dad9
 
 
 
 
 
 
 
 
 
 
 
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
from pydantic import BaseModel, validator
from typing import List, Optional, Dict, Literal

# What agent sees
class Observation(BaseModel):
    code: str
    intent: str
    constraints: List[str]
    task_id: str
    difficulty: Literal["easy", "medium", "hard"]
    step_index: int

# What agent sends
class Action(BaseModel):
    action_type: Literal["detect", "risk", "fix"]
    detected_issues: Optional[List[str]] = None
    risk_level: Optional[Literal["low", "medium", "high"]] = None
    suggested_fix: Optional[str] = None

# Structured agent response for RL training
class AgentResponse(BaseModel):
    """Structured response from LLM agent with confidence and reasoning"""
    issues_detected: List[str] = []
    risk_level: Literal["low", "medium", "high"] = "low"
    fix: str = ""
    confidence: float = 0.5
    reasoning: str = ""
    reward_breakdown: Dict[str, float] = {}
    
    @validator('confidence')
    def clamp_confidence(cls, v):
        return max(0.0, min(1.0, v))

# What env returns
class Reward(BaseModel):
    value: float
    feedback: str
    partial_scores: Dict[str, float]
    breakdown: Dict[str, float] = {}  # Detailed reward breakdown per step
    
    @validator('value')
    def clamp_value(cls, v):
        return max(0.0, min(1.0, v))

# Agent state for RL learning
class AgentState(BaseModel):
    """State tracking for RL agent learning"""
    episode: int = 0
    total_reward: float = 0.0
    best_score: float = 0.0
    prompt_strategy: str = "default"
    past_failures: List[str] = []
    learning_rate: float = 0.1
    improvement_history: List[float] = []