Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions examples/geo3k_vlm_multi_turn/env_geo3k.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ class Geo3kEnv(BaseInteractionEnv):

The model is expected to emit a <tool_call>{...}</tool_call> payload that includes
an `answer` argument. We run the math reward checker against the ground truth and
return the score as the next observation. The episode ends immediately after each
step; responses are provided but no further turns are taken.
return feedback for wrong answers. The episode ends when the answer is correct,
when max_turns is reached, or when the response has no valid tool call; in the
last case we still try to score a boxed/text answer, matching SkyRL's env.
"""

def __init__(self, *, ground_truth: str | None = None, max_turns: int | None = None):
self.ground_truth = str(ground_truth) if ground_truth is not None else None
self.tool_calls: list[dict[str, Any]] = []
self.last_tool_score: float | None = None
self.correct = False
self.turn = 0
self.max_turns = max_turns

def reset(self):
self.tool_calls.clear()
self.last_tool_score = None
self.correct = False
self.turn = 0
# No initial observation is needed; the question lives in the prompt.
observation: dict[str, Any] = {}
Expand Down Expand Up @@ -186,10 +189,17 @@ def step(self, response_text: str):
info: dict[str, Any] = {"tool_call": deepcopy(tool_call)}

if not tool_call:
answer_text = self._extract_answer_from_text(response_text)
score = self._score_answer(answer_text) if answer_text else 0.0
self.last_tool_score = score
self.correct = score == 1.0
info["tool_executed"] = False
info["answer"] = answer_text
info["score"] = score
obs = {
"obs_str": "No tool call detected; ending the episode.",
"obs_str": "No valid tool call detected; ending the episode.",
"role": "tool",
"tool_score": score,
}
return obs, True, info

Expand Down Expand Up @@ -224,6 +234,7 @@ def step(self, response_text: str):

score = self._score_answer(parsed_answer)
self.last_tool_score = score
self.correct = score == 1.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup (redundant state). self.correct is only read immediately below at L249; it doesn't need to live on the env. A local correct = score == 1.0 plus return obs, correct or is_final_turn, info removes the field and its init/reset at L42/L49.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix. This is truly redundant.

tool_record = {"name": name, "answer": parsed_answer, "score": score}
self.tool_calls.append(tool_record)
info.update(tool_record)
Expand All @@ -235,7 +246,7 @@ def step(self, response_text: str):
"tool_score": score,
}

return obs, is_final_turn, info
return obs, self.correct or is_final_turn, info

def _parse_tool_payload(self, raw_json: str) -> dict[str, Any] | None:
"""Parse tool payload strictly as JSON. Malformed payloads are rejected."""
Expand Down
Loading