Jivan01 commited on
Commit
4a63c86
·
1 Parent(s): 50a0917

Expose 3 graded tasks and strict in-range task scores for phase 2

Browse files
AgentBox/src/env.py CHANGED
@@ -24,11 +24,20 @@ class CodeGuardEnv:
24
  # Strict score interval for validator compatibility.
25
  return max(0.01, min(0.99, base_score))
26
 
 
 
 
 
 
 
 
27
  def reset(self) -> Dict[str, Any]:
28
  self.state = {
29
- "score": 0.0,
30
  "history": [],
31
  "task": TASKS[self.task_key],
 
 
32
  }
33
  self.current_step = 0
34
  self.done = False
@@ -59,7 +68,8 @@ class CodeGuardEnv:
59
 
60
  reward: float = compute_reward(self.state, action, base_score)
61
 
62
- self.state["score"] = reward
 
63
  self.state["history"].append(
64
  {
65
  "step": self.current_step,
 
24
  # Strict score interval for validator compatibility.
25
  return max(0.01, min(0.99, base_score))
26
 
27
+ def _get_all_task_scores(self, action: str) -> Dict[str, float]:
28
+ scores: Dict[str, float] = {}
29
+ for key, grader in GRADERS.items():
30
+ score = float(grader(action))
31
+ scores[key] = max(0.01, min(0.99, score))
32
+ return scores
33
+
34
  def reset(self) -> Dict[str, Any]:
35
  self.state = {
36
+ "score": 0.01,
37
  "history": [],
38
  "task": TASKS[self.task_key],
39
+ "tasks": list(TASKS.values()),
40
+ "task_scores": {k: 0.01 for k in GRADERS.keys()},
41
  }
42
  self.current_step = 0
43
  self.done = False
 
68
 
69
  reward: float = compute_reward(self.state, action, base_score)
70
 
71
+ self.state["score"] = max(0.01, min(0.99, base_score))
72
+ self.state["task_scores"] = self._get_all_task_scores(action)
73
  self.state["history"].append(
74
  {
75
  "step": self.current_step,
AgentBox/src/tasks/easy.py CHANGED
@@ -10,6 +10,8 @@ def get_task() -> Dict:
10
  return {
11
  "name": "lint_fix",
12
  "description": "Fix syntax errors in the given Python code.",
 
 
13
  }
14
 
15
 
 
10
  return {
11
  "name": "lint_fix",
12
  "description": "Fix syntax errors in the given Python code.",
13
+ "grader": "grade",
14
+ "score_range": [MIN_TASK_SCORE, MAX_TASK_SCORE],
15
  }
16
 
17
 
AgentBox/src/tasks/hard.py CHANGED
@@ -10,6 +10,8 @@ def get_task() -> Dict:
10
  return {
11
  "name": "refactor_types",
12
  "description": "Refactor code and add type hints.",
 
 
13
  }
14
 
15
 
 
10
  return {
11
  "name": "refactor_types",
12
  "description": "Refactor code and add type hints.",
13
+ "grader": "grade",
14
+ "score_range": [MIN_TASK_SCORE, MAX_TASK_SCORE],
15
  }
16
 
17
 
AgentBox/src/tasks/medium.py CHANGED
@@ -11,6 +11,8 @@ def get_task() -> Dict:
11
  return {
12
  "name": "vuln_patch",
13
  "description": "Remove unsafe function usage while preserving functionality.",
 
 
14
  }
15
 
16
 
 
11
  return {
12
  "name": "vuln_patch",
13
  "description": "Remove unsafe function usage while preserving functionality.",
14
+ "grader": "grade",
15
+ "score_range": [MIN_TASK_SCORE, MAX_TASK_SCORE],
16
  }
17
 
18
 
src/__init__.py ADDED
File without changes
src/env.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.env import * # noqa: F401,F403
src/reward.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.reward import * # noqa: F401,F403
src/tasks/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.tasks import * # noqa: F401,F403
src/tasks/easy.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.tasks.easy import * # noqa: F401,F403
src/tasks/hard.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.tasks.hard import * # noqa: F401,F403
src/tasks/medium.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from AgentBox.src.tasks.medium import * # noqa: F401,F403