fix: strip <answer> XML tags before do/finish markers in _parse_response#414
Open
nankingjing wants to merge 2 commits into
Open
fix: strip <answer> XML tags before do/finish markers in _parse_response#414nankingjing wants to merge 2 commits into
nankingjing wants to merge 2 commits into
Conversation
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
Fixes an ordering bug in
ModelClient._parse_response(phone_agent/model/client.py) that corrupts every action when the model answers in the tagged format requested by the system prompt.The bug
The system prompt (
phone_agent/config/prompts_zh.py/prompts_en.py) instructs the model to output:where
{action}is ado(...)orfinish(...)call._parse_responsechecked its rules in this order:finish(message=markerdo(action=marker<answer>XML tags (documented as the fallback)Because a tagged answer always contains a
do(action=orfinish(message=call inside the<answer>block, Rule 1/2 match before the tags are stripped. For input:the old code returned:
thinking = '<think>I should tap the search box</think><answer>'(tags leaked in)action = 'do(action="Tap", element=[500, 300])</answer>'(trailing</answer>)The action string is not valid Python, so the downstream
parse_action(phone_agent/actions/handler.py) raisesValueError. InPhoneAgent._execute_stepthat exception is swallowed and turned intofinish(message=<raw string>), so the agent ends the task immediately instead of tapping. As a consequence, Rule 3 (the XML-tag path) was effectively dead code — it could never be reached for a real action.The fix
Check for the
<answer>tag first. When present, strip<think>/</think>/<answer>/</answer>and return the clean thinking/action pair. Tag-less responses (the AutoGLM-Phone-9B happy path) are unchanged: they fall through to the unchangedfinish(message=/do(action=marker rules.This is a pure reordering — no tag-less behaviour changes.
Tests
Adds
tests/test_parse_response_order.py:do/finishresponses now yield a clean action with no</answer>remnant (regression cases).do,finish, finish-precedes-do, and plain-text fallback still behave exactly as before.Verification
Not executed in CI here. Verified by reading the code path end-to-end and by simulating the reordered
_parse_responseagainst all test inputs (all produce the asserted(thinking, action)tuples). Both edited files passast.parse.