Skip to content

fix(infer): validate explicit tool choices - #9871

Closed
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/unknown-tool-choice
Closed

fix(infer): validate explicit tool choices#9871
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/unknown-tool-choice

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

An explicit tool_choice can name a function that is absent from the
request's tools list. ChatCompletionRequestMixin intended to report this
as a ValueError, but next() raised StopIteration before the validation
branch could run.

This change gives next() a None default so the existing, actionable error
is raised:

ValueError: Tool choice 'missing' not found in tools.

Valid explicit choices retain the existing behavior of narrowing tools to
the selected function. Automatic and disabled tool selection are unchanged.

Experiment results

Before:

StopIteration: <empty message>

After:

ValueError: Tool choice 'missing' not found in tools.

Verification:

.venv/bin/python tests/run.py --test_dir tests/infer --pattern test_protocol.py
SUCCESS (Runs=2, success=2)

.venv/bin/pre-commit run --files swift/infer_engine/protocol.py tests/infer/test_protocol.py
All hooks passed

Return the intended validation error when an explicit tool choice does not exist in the request's tools list.

Test: python tests/run.py --test_dir tests/infer --pattern test_protocol.py
@RerankerGuo

Copy link
Copy Markdown
Contributor Author

CI note: lint and the NPU unittest pass; the CUDA failure is the repository-wide Gemma3 dependency issue, not this protocol validation change. I traced the exact runtime downgrade and documented it on #9862: test_merged_linear.py loads remote StructBERT requirements that replace Transformers 4.57.6 with 4.48.3 before test_gemma3_template.py runs. See #9862 (comment).

@RerankerGuo

Copy link
Copy Markdown
Contributor Author

Closing this to reduce the active review queue to the agreed maintenance capacity. The explicit-tool validation improves the error path but has lower user impact than the retained fixes and no maintainer signal. The one-line fix and regression tests remain preserved at 1eb3c03abfdb7611534a56906ce2329a1212c877 for reopening or salvage.

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