Skip to content

fix(agent): spend required tool_choice and forced choices on resume turns - #49

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796216235-forced-tool-choice-required-and-resume
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796216235-forced-tool-choice-required-and-resume

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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_choice one-shot on in-loop follow-ups. Two paths still re-sent a forced choice after it had produced a tool call:

Path Before After
Follow-up turn, tool_choice="required" "required" every turn "auto"
Follow-up turn, {"type": "allowed_tools", "mode": "required", ...} unchanged every turn same tools, mode: "auto"
First turn after approval resume (approve_tool_calls / reject_tool_calls) original forced choice relaxed (specific dropped, required → auto)
First turn after client-tool resume (awaiting_client_tools) original forced choice relaxed

_clear_forced_tool_choice now 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 via next_turn_params is still preserved. This matches the TypeScript agent's relaxForcedToolChoice (one-shot forced choices, required → auto, allowed_tools keeps its allowlist).

Behaviour change: "required" was previously asserted as preserved on follow-ups; that test case now asserts "auto".

Testing

  • New cases in tests/unit/test_forced_tool_choice_one_shot.py (required / allowed_tools-required relaxing, approval resume, client-tool resume): 5 fail on main, all pass with the fix.
  • ruff check, ruff format --check, mypy src tests, pytest tests/unit (230 passed).

…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.
@devin-ai-integration

devin-ai-integration Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review December 2, 2026 12:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant