fix(bot): force a tool-free final answer when subagent hits iteration limit (parity with #2810)#2881
Open
r266-tech wants to merge 1 commit into
Open
Conversation
… limit PR volcengine#2810 made the main agent loop, on reaching the tool-use iteration limit, re-prompt the model with tools=[] to produce a real final answer. The subagent loop never got the same handling: when iteration 15 still emits tool calls, the loop exits with final_result=None and returns the placeholder 'Task completed but no final response was generated.', discarding every round of search/file work the subagent performed. Mirror the volcengine#2810 pattern in the subagent loop: on hitting the limit with no final content, append a 'do not call any more tools' instruction and make one tools=[] call to summarize the gathered context. Falls back to the placeholder only if that final call is also empty. Adds a regression test that drives 15 tool-call iterations and asserts the extra tools=[] call returns a real answer.
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.
Follow-up to #2810, on the sister subagent path it never covered.
#2810 made the main agent loop, on reaching the tool-use iteration limit, re-prompt the model with
tools=[]to produce a real final answer. The subagent loop (bot/vikingbot/agent/subagent.py) was missed: when iteration 15 still emits tool calls, thewhile iteration < max_iterationsloop exits withfinal_result=Noneand returns the placeholder"Task completed but no final response was generated.", throwing away all 15 rounds of search/file work the subagent performed.Fix — mirror the #2810 pattern in the subagent loop: on hitting the limit with no final content, append a "do not call any more tools" instruction and make one
tools=[]call to summarize the gathered context. The placeholder fallback now only triggers if that final call is also empty.subagent.pycallsprovider.chatdirectly (not loop.py's_chat_with_stream_events), so this mirrors the pattern, not the exact streaming call.Added a regression test mirroring
test_agent_loop_makes_final_no_tool_call_when_iteration_limit_reached: it drives 15 tool-call iterations and asserts the extratools=[]call returns a real answer with the gathered tool results still in context.