Skip to content

fix(agent): gate tool execution on completed status and make forced tool_choice one-shot - #46

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796091779-tool-loop-status-and-tool-choice
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796091779-tool-loop-status-and-tool-choice

Conversation

@alexb-openrouter

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

Copy link
Copy Markdown
Contributor

Summary

Fixes two tool-loop execution bugs in ModelResult (src/openrouter_agent/model_result.py):

  1. Refuse tool execution on non-completed model turns: ModelResult._run previously extracted and executed tool calls without checking response.status. It now only extracts tool calls when get_field(response, "status") == "completed", stopping the loop without running tools, approval gates, or follow-up turns for incomplete (max_output_tokens, content_filter), failed, cancelled, in_progress, queued, or missing-status responses.
  2. Make specific forced tool_choice one-shot across follow-up turns: _build_followup_request previously carried a specific forced tool_choice / toolChoice (e.g. {"type": "function", "name": "..."}, OpenAIResponsesToolChoiceFunction, or named server-tool choices) into subsequent turns after the tool already executed. Forced specific tool choices are now stripped on follow-up turns unless explicitly re-set via next_turn_params. Non-specific modes ("auto", "none", "required", and {"type": "allowed_tools", ...}) are preserved.

Testing

  • Added unit tests in tests/unit/test_non_completed_response_tools.py covering non-completed statuses, streamed response.incomplete events, approval/final-response paths, and multi-turn runs.
  • Added unit tests in tests/unit/test_forced_tool_choice_one_shot.py covering snake_case/camelCase/Pydantic forced choices, next_turn_params overrides, and preserved non-specific modes.
  • Verified locally with ruff check ., ruff format --check ., mypy src tests, and pytest tests/unit --cov --cov-fail-under=83 (195 passed, 85.33% coverage).
@devin-ai-integration

devin-ai-integration Bot commented Dec 1, 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

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

1 participant