Skip to content

fix(agent): catch a tool plan written in place of doing the work - #6847

Merged
kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:fix/announced-plan-guard
Nov 7, 2026
Merged

kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:fix/announced-plan-guard

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Asked for net revenue by region, Gemma 4 E4B on the NPU ran one data-file analysis, then answered with a five-step plan ("1. I will use the run_python tool to load the CSV… 5. I will print the final results") and "This should give you the exact breakdown you asked for." Nothing ran after that, and the plan was handed over as the answer. #6787's guard only reads the last sentence, and this answer ends on a closing line. Now an answer that ends on a plan of "I will" steps naming a tool, with no results after it, is sent back to do the work. If the model still only plans, the turn ends with "I didn't finish".

Follow-up to #6787. Refs #6753

Evals to watch on the next RC: gaia_data, gaia_rag, gaia_honesty, tool_selection, error_recovery.

Test plan

  • pytest tests/unit/agents/test_announced_action_guard.py: the saved answer (verbatim fixture) is caught, the re-prompt quotes its run_python step, and the turn ends honestly at the cap. Both tests failed before the fix. Look-alikes still pass through: a tutorial that names no tool, a plan followed by its results, a drafted email with a plan, and a quoted plan.
  • pytest tests/unit/agents/ tests/unit/test_agent*.py: no new failures (the 16 sidecar-manager failures also fail on main on this Windows box).
  • python util/lint.py --black --isort --flake8
  • Replay the revenue-by-region question in the app on Gemma 4 E4B (NPU)

Asked for net revenue by region, Gemma 4 E4B on the NPU ran one
analyze_data_file call, then answered with "Here is the plan: 1. I will
use the `run_python` tool to load the CSV… 5. I will print the final
results" and "This should give you the exact breakdown". No tool ran, and
the plan was handed over as the answer.

An answer that ends on a list of two or more "I will" steps, one naming a
tool, with at most a short closing line and no figures after it, now
counts as an announced step. The re-prompt quotes its first tool step.
Tutorials that name no tool, a plan followed by its results, drafted
emails and quoted plans still pass through.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked against the real answers from the integration build. Gemma's saved revenue answer (a numbered plan, "1. I will use the run_python tool…") is now caught. The earlier "Executing the final write now." answer is still caught. The drafted email ending "I will review it and send comments by Friday." still passes. All 78 guard tests pass.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This catches the real failure: an answer that lays out a tool plan ("1. I will use the run_python tool…") and stops, now goes back to the model to do the work. The new check is too broad, though. It also fires when the user asked for a plan and the agent is waiting for a go-ahead, and when a plan names code identifiers rather than tools.

  • A plan that asks for confirmation gets overruled. Take "Here's the plan: 1. I'll use the list_files tool to find old files. 2. I'll move them to Archive. Want me to go ahead?" The model is told to "Do it now with a tool call", and if it keeps asking, the user's reply is replaced with "I didn't finish". Skip the check when the closing line is a question or asks for permission, and add a look-alike test for that case.
  • Code plans count as tool plans. Any snake_case name in backticks counts as a tool, so "1. I will rename load_config… 2. I will add a test. Let me know if that works." is treated as unfinished work. Only count a name when the step says it calls, runs or uses it, or when the name is a registered tool.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on reading the code and tracing the new check by hand against the cases above, because this runner has no Python environment that can import gaia. The PR's own replay on Gemma 4 E4B (NPU) is still unchecked.

🔍 Technical details

Rubric and missed-bug-classes files were both read.

🟡 Important

1. A plan that asks for the go-ahead is flagged as narration (src/gaia/agents/base/agent.py:1641-1647). I traced _tool_plan_step by hand on "Here's the plan:\n1. I'll use the list_files tool to find files older than 30 days.\n2. I'll move them to an Archive folder.\n\nWant me to go ahead?":

  • _DRAFT_PATTERN doesn't match, because "plan" isn't one of its nouns.
  • plan_at=-1 finds no list items.
  • plan_at=-2: the closing line is under 300 characters and has no digit, there are two future items, and one says "tool". The result is "narration".
  • The re-prompt then says "Do it now with a tool call". At the cap, _unfinished_step_answer swaps the plan the user asked for with "I didn't finish: …".

Before this PR, a plan with two or more future steps passed on purpose (_FUTURE_ACTION_PATTERN's comment: "a plan or a tutorial the user asked for"). This branch overrides that whenever a tool is named, with nothing to stop it when the closing line asks for confirmation. One way to fix it:

        if closing and (
            len(closing[0]) > _CLOSING_LINE_MAX_CHARS
            or re.search(r"\d", closing[0])
            or closing[0].rstrip().endswith("?")
            or re.search(r"\b(?:let me know|shall i|should i|want me to|would you like)\b", closing[0], re.IGNORECASE)
        ):
            return None

Add a plan-awaiting-confirmation case to test_plan_look_alikes_are_not_narration.

2. _TOOL_NAMING_PATTERN treats any backticked snake_case name as a tool (agent.py:1624-1626). "1. I will rename load_config to read_settings. 2. I will add a unit test.\n\nLet me know if that works for you." is classed as "narration", so code-change plans from the coding skill get re-prompted. The fixture still matches without the bare identifier, because it contains the word "tool". To keep the "call query_data" case from the comment, anchor the identifier to a verb:

_TOOL_NAMING_PATTERN = re.compile(
    r"\btools?\b|\b(?:call|run|invoke|use)\s+(?:the\s+)?`[a-z][a-z0-9]*_[a-z0-9_]+`",
    re.IGNORECASE,
)

A stronger fix is to check the name against self._tools_registry at the call site.

🟢 Minor

3. Curly apostrophes lose the quoted step (agent.py:1669-1673). _unfinished_answer_kind changes ’ to ' before matching, but _split_announced_step passes the raw text to _tool_plan_step. When the plan says "I’ll use the run_python tool…", detection fires but the split finds no plan. The fallback then quotes nothing, so the re-prompt and the "I didn't finish" message lose the step. Normalize the paragraphs used for matching the same way, and slice the body from the raw text.

Strengths

  • The fixture is the model's own answer, saved word for word, and the end-to-end test proves the re-prompt quotes the right step and that the turn ends honestly at the cap.
  • The look-alike tests (tutorial, plan followed by results, drafted email, quoted plan) are the right negatives. Item 1 needs one more.
  • The PR also fixes the test-module docstring, which had literal \n escapes in it.

A plan the user asked for ("1. I'll use the `list_files` tool… 2. I'll
move them to Archive. Want me to go ahead?") was overruled with "do it
now", and a code plan ("I will rename `load_config`… Let me know if that
works.") counted as a tool plan because any snake_case name did.

The plan check now skips a closing line that asks a question or for the
go-ahead, and counts a step only when it uses, calls or runs a tool. It
also matches curly apostrophes while still quoting the step as written.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Both false positives are fixed. A plan that ends by asking for the go-ahead ("Want me to go ahead?", "Let me know and I'll start.") now passes as the answer. A code plan that only names identifiers ("I will rename load_config…") no longer counts as a tool plan. The Gemma answer from the app is still caught. The curly-apostrophe point is fixed too, so a plan written with I’ll still gets its step quoted. The branch is merged with main.

🔍 Technical details
  • b8a758f61: _ASKS_GO_AHEAD_PATTERN rejects a closing line that ends in ? or asks for the go-ahead ("let me know", "want me to", "shall I", "would you like", …).
  • _TOOL_NAMING_PATTERN now needs a verb: "use/call/run/invoke [the] x tool", "… x tool", or "call snake_name". A bare backticked identifier no longer counts. I didn't check names against _tools_registry: the classifier is module-level and runs without an agent instance, and the verb anchor alone separates the cases you raised.
  • Plan items are matched with ’ normalised to ', but sliced from the raw text, so the quote keeps the model's own wording.
  • New tests, written to fail first (all 5 did): plan-awaiting-confirmation, plan-asks-permission, code-plan-with-identifiers, code-plan-no-closing-line, and test_tool_plan_step_is_quoted_with_curly_apostrophes. The verbatim fixture tests still pass.
  • Agent suites: 5726 passed. The 16 test_agent_sidecar_manager.py failures also fail on main on this Windows box. Lint is clean.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked b8a758f against the real answers from testing, plus the review's look-alikes. Still caught: Gemma's numbered plan ("1. I will use the run_python tool…") and "Executing the final write now.". No longer caught: a plan that ends "Want me to go ahead?", a plan that only renames load_config, and the drafted email ending "I will review it…". All 83 tests in the guard's test file pass.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

🟡 Both earlier findings are fixed when there's a blank line before the closing question. Without one, a plan that waits for the go-ahead is still treated as unfinished work. Take "Here's the plan:\n1. I'll use the list_files tool to find old files.\n2. I'll move them to Archive.\nWant me to go ahead?" with no blank line before the question. The model is told to do it now, and at the cap the plan the user asked for is replaced with "I didn't finish". Models often put the closing line right under the list, so run the same go-ahead check on any line in the plan paragraph that isn't a list item, and add that case to the look-alike tests.

🔍 Technical details

src/gaia/agents/base/agent.py _tool_plan_step: when plan_at == -1, closing is [], so _ASKS_GO_AHEAD_PATTERN is never applied. _PLAN_ITEM_PATTERN skips the trailing "Want me to go ahead?" line, so the paragraph still shows two future steps, one of them naming a tool, and the function returns "narration". For the same reason, a results line directly under the list skips the digit check and is flagged too.

One fix: treat the non-item lines after the last list item as closing text.

lines = paragraphs[plan_at].splitlines()
last_item = max((i for i, l in enumerate(lines) if _PLAN_ITEM_PATTERN.match(l)), default=-1)
tail = "\n".join(lines[last_item + 1 :]).strip()
closing = [c for c in [tail, *paragraphs[plan_at + 1 :]] if c]

Then run the existing length, digit and go-ahead checks against closing[0].

Test case to add to test_plan_look_alikes_are_not_narration:
"Here's the plan:\n1. I'll use the list_files tool to find old files.\n2. I'll move them to Archive.\nWant me to go ahead?"

kovtcharov and others added 3 commits November 6, 2026 15:22
A plan ending in "Once you confirm, I'll start.", "Reply 'go' to
proceed." or "Nothing has been changed yet." is the answer the user
asked for, but the tool-plan check read it as unfinished work and
re-prompted. The go-ahead check now also covers confirm, proceed,
approve, "once you", "reply ... to" and "nothing has been changed yet".
Closing lines that only look similar ("Once it runs...", "Nothing else
is needed", "...to reply to first") are still caught.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 7, 2026
Merged via the queue into amd:main with commit 02ed3a1 Nov 7, 2026
38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/announced-plan-guard branch November 7, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants