Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
138 lines (129 loc) · 4.42 KB
/
Copy pathmodels.py
File metadata and controls
138 lines (129 loc) · 4.42 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
Pydantic models for PythonDebugEnv.
Defines Action, Observation, and State types for the RL environment.
"""
from pydantic import BaseModel, Field, field_serializer
from typing import Literal, Optional
class DebugAction(BaseModel):
"""
Action submitted by the agent.
Contains the fixed/corrected Python code.
"""
fixed_code: str = Field(
...,
description="The corrected Python code submitted by the agent"
)
class DebugObservation(BaseModel):
"""
Observation returned to the agent.
Contains the buggy code and metadata about the problem.
"""
problem_id: str = Field(
...,
description="Unique identifier for this problem"
)
buggy_code: str = Field(
...,
description="The broken Python code that needs to be fixed"
)
description: str = Field(
...,
description="Human-readable description of what the code should do"
)
test_cases: list[dict] = Field(
...,
description="List of test cases (not shown to agent, used for grading)"
)
difficulty: Literal["easy", "medium", "hard"] = Field(
...,
description="Problem difficulty level"
)
category: str = Field(
"unknown",
description="Bug category (e.g., logic_error, off_by_one)"
)
task_id: Optional[str] = Field(
None,
description="Task ID if problem belongs to a task (e.g., fix_logic_bug, fix_algorithm_bug)"
)
task_name: Optional[str] = Field(
None,
description="Human-readable task name (e.g., 'Fix Logic Bugs')"
)
reward: float = Field(
0.0,
description="Reward for the last action (0.0 on reset). Range: [0.0, 1.0]"
)
test_score: float = Field(
0.0,
description="Test-based score (70% weight). Range: [0.0, 1.0]. Only set after step()."
)
llm_score: float = Field(
0.0,
description="DEPRECATED - kept for backward compatibility"
)
quality_score: float = Field(
0.0,
description="Code quality score from static analysis (30% weight). Range: [0.0, 1.0]. Session 8."
)
quality_feedback: Optional[dict] = Field(
None,
description="Detailed code quality feedback with breakdown of checks and improvements"
)
improvement: float = Field(
0.0,
description="Score improvement from previous attempt. Session 8 reward shaping."
)
improvement_bonus: float = Field(
0.0,
description="Bonus reward for improvement between steps. Session 8 reward shaping."
)
test_details: list[dict] = Field(
[],
description="Detailed test results from last step. Each dict has: input, expected, actual, status (pass/fail/error), error. Session 8."
)
error_summary: str = Field(
"",
description="Human-readable summary of test failures/errors. Session 8 rich observations."
)
hint: Optional[str] = Field(
None,
description="Common mistake hint based on bug category (PRIORITY 2.5)"
)
error_details: Optional[dict] = Field(
None,
description="Detailed error information with test failures breakdown (PRIORITY 2.7)"
)
attempt: int = Field(
0,
description="Current attempt number (0 on reset, 1-3 after steps)"
)
max_attempts: int = Field(
3,
description="Maximum number of attempts allowed per episode"
)
done: bool = Field(
False,
description="Whether the episode is complete. True after step(), False on reset()"
)
@field_serializer('reward', 'done', 'test_score', 'llm_score', 'quality_score', 'attempt', 'max_attempts', 'task_id', 'task_name', 'improvement', 'improvement_bonus', 'test_details', 'error_summary', 'quality_feedback', 'hint', 'error_details', when_used='always')
def serialize_always(self, value):
"""Force serialization of all result fields even when they're defaults."""
return value
class DebugState(BaseModel):
"""
Environment state metadata.
Tracks episode information and current progress.
"""
episode_id: str | None = Field(
None,
description="Unique identifier for the current episode"
)
step_count: int = Field(
0,
description="Number of steps taken in the current episode"
)
current_problem_id: str | None = Field(
None,
description="ID of the currently active problem"
)