Repository navigation
fix(agent): spend required tool_choice and forced choices on resume turns - #49
Open
alexb-openrouter wants to merge 1 commit into
Open
alexb-openrouter wants to merge 1 commit into
alexb-openrouter wants to merge 1 commit into
Conversation
…urns A forced tool_choice of "required" or allowed_tools with mode "required" was re-sent on every follow-up turn, and a specific forced choice was re-sent on the first turn after an approval or client-tool resume. In both cases the model was compelled to call a tool again after the forced call had already run. Relax these to auto on follow-up and resume turns, matching the TypeScript agent.
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
This branch has not been deployed
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
Risk: an app that forces a tool call on the first turn could have the agent compel the model to call a tool again after the forced call had already run, so a state-changing tool (payment, message, write) could execute twice unless the app de-duplicates it.
#46 made a specific forced
tool_choiceone-shot on in-loop follow-ups. Two paths still re-sent a forced choice after it had produced a tool call:tool_choice="required""required"every turn"auto"{"type": "allowed_tools", "mode": "required", ...}tools,mode: "auto"approve_tool_calls/reject_tool_calls)required→auto)awaiting_client_tools)_clear_forced_tool_choicenow does the relaxing and is applied in_build_followup_request(as before),_build_resume_request, and on the client-tool resume turn. A choice set explicitly vianext_turn_paramsis still preserved. This matches the TypeScript agent'srelaxForcedToolChoice(one-shot forced choices,required→auto,allowed_toolskeeps its allowlist).Behaviour change:
"required"was previously asserted as preserved on follow-ups; that test case now asserts"auto".Testing
tests/unit/test_forced_tool_choice_one_shot.py(required / allowed_tools-required relaxing, approval resume, client-tool resume): 5 fail onmain, all pass with the fix.ruff check,ruff format --check,mypy src tests,pytest tests/unit(230 passed).