fix: handle JSON-string finish arguments in ToolEnvironment._extract_llm_answer - #2049
Open
howl-anderson wants to merge 1 commit into
Open
fix: handle JSON-string finish arguments in ToolEnvironment._extract_llm_answer#2049howl-anderson wants to merge 1 commit into
howl-anderson wants to merge 1 commit into
Conversation
howl-anderson
requested review from
abheesht17,
hgao327,
jiangyangmu,
lc5211,
s-noghabi,
sizhit2,
tianshub and
wang2yn84
as code owners
August 31, 2026 18:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ToolEnvironment._extract_llm_answerraisesAttributeError: 'str' object has no attribute 'get'when the model ends an episode with an explicitfinishtool call (e.g. Qwen-format<tool_call>{"name": "finish", "arguments": {"response": "..."}}</tool_call>) instead of plain text.Root cause
The two code paths in
ToolAgent.update_from_modelproduce inconsistent types forfunction.arguments:finish):argumentsis a dict ({"response": response}).argumentsisjson.dumps-stringified:_extract_llm_answeronly handles the dict shape:So any model that learned to emit
finishthrough the documented tool-call format crashes the rollout during reward computation. (The episode-termination check just above,name == "finish", matches fine — only the answer extraction breaks.)Fix
Make
_extract_llm_answertolerant of the stringified form: parse JSON-string arguments, and fall back to returning the raw string when it isn't valid JSON. ChangingToolAgentto stop stringifying was considered, but other consumers may rely on the string form, so this is the narrower fix.Testing
Added
tests/rl/agentic/environments/tool_environment_test.pycovering:env.step()with a JSON-stringfinishcall producing the correct rewardFixes #2050