Repository navigation
fix(agent): answer from what it found when the step limit runs out - #4373
Conversation
An agent that ran out of steps replied with a canned note that never said what it found or why it stopped. In a benchmark run GitHub rate-limited every `gh` call; the agent spent all 30 steps on workarounds and never mentioned the rate limit. The note's "tools used" list was also always empty. At the step limit the agent now makes one more model call on the loop's own path, with no tools offered, asking for a final answer from what the tool results show: what it found, what it couldn't finish and why, and what the user can do next. The run still reports "incomplete" and sets max_steps_reached. If that call fails or doesn't answer, the canned note comes back with a line saying why and a warning is logged. The note now lists the tools that actually ran.
On the Claude backend the step-limit summary would always have failed: Anthropic rejects a request whose history holds tool calls and results when it defines no tools, so the user got the canned note every time. The closing call now sends the same tools as the loop with tool_choice="none", which every backend accepts and which leaves the tool schemas at the front of the prompt unchanged. tool_choice is now an explicit parameter on the Lemonade and Claude providers and on LemonadeClient.chat_completions. Lemonade sends it unchanged, top-level on the streaming path too, and only when set. Claude maps "none" and "auto" to Anthropic's shape and raises on anything else. Both raise when tool_choice comes without tools. A reply that calls a tool anyway still counts as a failed summary.
…anyway Answering "n" at "Continue with 50 more steps?" — or pressing Ctrl-C there — left `final_answer` empty and `cancelled_by_console` false, so the step-cap wrap-up call fired and produced the answer the user had just declined. Only the Agent UI Stop button sets `cancelled_by_console`; the two interactive breaks set nothing. They now set `user_stopped`, which the wrap-up decision reads. Silent mode is untouched: running out of steps unattended still gets the closing answer. Not unit-covered: the continue prompt only runs on a step that is neither a tool call nor an answer, which the existing harness cannot script. Co-Authored-By: Claude Opus 5 <[email protected]>
|
The one red check, 🔍 Technical details
|
|
Verdict: Approve with suggestions — no blocking issues. A step-capped run now ends with the agent actually saying what it found and what it couldn't finish, instead of a canned notice whose "tools used" list was always empty. The closing model call reuses the loop's own path with the tools kept and calling them forbidden, which is the right shape, and it's backed by tests that assert the real request body rather than "a method was called." Two things worth a look before this pattern spreads further:
Real-world evidenceThe evidence bundle reports that the harness errored before producing evidence, so it certifies nothing. The stage did leave partial artifacts in the tree ( Before (base) vs after (this PR), same scripted scenario, step limit reached: Request bodies captured on the wire ( Failure path ( Not exercised here: the HTTP API scenario aborted ( 🔍 Technical detailsIssues🟡 Failed closing call never reaches the console ( The 🟡 No overflow recovery on the closing call (
🟢 Final-answer event under-reports tokens at the cap (
🟢
🟢 Duplicated call plumbing — Strengths
|
One conflict, in the turn's result status. `main` (#4373) made a step-capped turn report "incomplete" even when the closing call answered; this branch made a turn with completion gaps report "incomplete" too. Both conditions kept, with the branch's errors-first ordering: "success" now needs a valid answer, no completion gaps, and no step cap.
amd#4373 landed this PR's step-cap half on main (replicating amd#4028), and amd#3908 merged as a squash, so both of this branch's stacked parents are now upstream. Nine conflicts in agent.py, all in the code the two changes share: - `_answer_at_step_cap` → `_closing_answer(messages, conversation, instruction, step)`. This PR generalises the method so the loop-guard path can reuse it; the step-cap call site now passes `_STEP_CAP_ANSWER_PROMPT` as the instruction. Same request, same prompt. - `max_steps_reached` keeps main's `user_stopped` term. That is this PR's own first review finding — declining "Continue with 50 more steps?" or pressing Ctrl-C must not fire another model call — and amd#4373 fixed it while this branch was open. - Both loop-guard call sites drop main's `_build_loop_break_summary` assignment: `_answer_after_repeated_calls` builds that summary itself and returns it for repeats that failed or were refused. - `_build_loop_break_summary` keeps the extracted `_repeats_carry_a_failure` predicate over main's inline condition; they are equivalent, and `denied` is still used further down. - `min_context_size`'s docstring takes main's wording, which describes the resolver that is now in place. The closing answer is now printed, not just returned. The normal and step-cap paths call `print_final_answer` where they set `final_answer`; the loop guard returned its answer and broke out, so on the CLI — where the console is the only thing that prints — the turn ended on the repeat warning and the answer this path exists to produce was never shown. Confirmed by driving a real loop-guard break: `print_final_answer` was called zero times while the answer sat in `result["result"]`, which is why every existing test missed it. The post-loop block mirrors the step-cap one, so the printed text carries its verification-scope line and the turn record is sealed before it prints.
When an agent ran out of steps, the user got a canned "Reached maximum steps limit" note with an empty tool list and no word on what happened. In a benchmark where GitHub rate-limited every
ghcall, GAIA spent all 30 steps on workarounds and never mentioned the rate limit. Now, at the step limit, the agent gets one more model call in which it can't use tools, and answers from what its tool results show: what it found, what it couldn't finish and why, and what to do next. If that call fails, the old note comes back with a line saying why.Replicates #4028, which lives on the
kovtcharov/gaiafork — push access was revoked mid-review, so that PR could no longer be refreshed against main and was stuckCONFLICTING. Same content, re-resolved against current main. No content changes beyond the conflict resolution.Test plan
python -m pytest tests/unit/agents/test_step_cap_final_answer.py tests/unit/test_claude_provider.py tests/unit/test_lemonade_tool_choice.py— 89 passedpython -m pytest tests/unit/agents— 1511 passed, 50 skipped, 0 failed-k "claude or lemonade or provider") diffed against a clean-mainworktree baseline — identical failure sets, zero regressions (the 12 remaining are pre-existing macOS/posix tests failing on a Windows host)python util/lint.py --black --isort --fixclean, no changes;python util/lint.py --flake8passesgaia eval agent --category tool_selection— not run here; carried over unchecked from fix(agent): answer from what it found when the step limit runs out #4028fireworks.kimi-k2p7-coderun accepted the closing call with tools +tool_choice="none"and answered from its results); NPU/FLM still unchecked🔍 Technical details
Replication method. #4028 was stacked on #3908, which main squash-merged as
69fc540b5. A plain merge would re-apply #3908's fork commit on top of its own squash, so instead the three commits that are #4028's own work were cherry-picked onto main:2dc1e47d7,50aa38fb0,429de6a48. #3908's fork commit and main's squash were verified byte-identical before dropping it.Only conflict:
src/gaia/llm/providers/claude.py. Main changed_build_paramsto also return aname_map(_to_anthropic_toolsnow returns a tuple); #4028 added atool_choiceparameter and passed it through fromchat. Both kept — the signature takestool_choiceand returnstuple[dict, Dict[str, str]]. This is the identical resolution the author made in26d80fcfaon the fork, confirmed by reading that merge's combined diff; it was the only evil-merge content across all three of the branch's merge commits, so the replicated tree reproduces the PR head exactly. Verified by matching symbol counts for_STEP_CAP_ANSWER_PROMPT,_answer_at_step_cap,max_steps_reached,user_stoppedandtool_choiceagainstrefs/pull/4028/head.Review findings from #4028 are all addressed in the replicated commits. The
user_stoppedguard (declining "Continue with 50 more steps?" no longer fires the wrap-up call) landed in429de6a48, and the Claude structural fix (keep the tools, sendtool_choice="none") in50aa38fb0.self.chat.send_messagesorsend_messages_stream, with the loop'smessagesplus one user instruction, the same system prompt, the same tools, andtool_choice="none". Tools stay because Anthropic rejects tool_use/tool_result history on a request with no tools. A model without native tool calling sends no tools and notool_choice.tool_choiceis a new explicit parameter onLemonadeProvider.chat,ClaudeProvider.chatandLemonadeClient.chat_completions. Both raise if it comes without tools; Claude maps"none"/"auto"and raises on anything else._generate_max_steps_messagelooked for OpenAI-styletool_callson assistant entries, which GAIA'sconversationnever contains, so the "tools used" list was always empty. It now countsrole: toolentries.max_steps_reachedis new on every result.Stacking. #3908 is merged. #4035 sits on top of this PR and generalises the closing call to the loop-guard path (
_closing_answer); it will need retargeting onto this branch once this lands.