Skip to content

feat: option to disable named tool choice#322

Merged
gaomeng1900 merged 1 commit intomainfrom
feat/optional-toolchoice
Mar 20, 2026
Merged

feat: option to disable named tool choice#322
gaomeng1900 merged 1 commit intomainfrom
feat/optional-toolchoice

Conversation

@gaomeng1900
Copy link
Collaborator

What

Some LLMs do not support named tool_choice as
in

{"type": "function", "name": "FunctionName"}

Give an option to use "required" as tool_choice

Type

  • Bug fix
  • Feature / Improvement
  • Refactor
  • Documentation
  • Website
  • Demo / Testing
  • Breaking change

Testing

  • Tested in modern browsers
  • No console errors
  • Types/doc added

Closes

Requirements / 要求

  • I have read and follow the Code of Conduct and Contributing Guide . / 我已阅读并遵守行为准则。
  • This PR is NOT generated by a bot or AI agent acting autonomously. I have authored or meaningfully reviewed every change. / 此 PR 不是由 bot 或 AI 自主生成的,我已亲自编写或充分审查了每一处变更。

Copilot AI review requested due to automatic review settings March 20, 2026 09:43
@gaomeng1900 gaomeng1900 merged commit 93b1e52 into main Mar 20, 2026
5 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configuration flag to avoid sending named/object-form tool_choice to OpenAI-compatible APIs, improving compatibility with providers that only accept string tool_choice values (e.g., required).

Changes:

  • Introduce disableNamedToolChoice in LLMConfig, with defaulting in parseLLMConfig.
  • Update OpenAIClient to fall back to tool_choice: "required" when named tool choice is disabled.
  • Expose the option in the extension settings UI and document it on the website.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/website/src/pages/docs/advanced/page-agent-core/page.tsx Documents the new disableNamedToolChoice config option in the LLM config reference.
packages/llms/src/types.ts Adds disableNamedToolChoice to LLMConfig (but the new JSDoc needs to match actual behavior).
packages/llms/src/index.ts Ensures disableNamedToolChoice is normalized to false by default in parseLLMConfig.
packages/llms/src/OpenAIClient.ts Implements the runtime behavior: use named tool choice only when enabled, otherwise use "required".
packages/extension/src/components/ConfigPanel.tsx Adds a settings toggle to control disableNamedToolChoice.
packages/extension/src/agent/useAgent.ts Plumbs the new toggle through extension config persistence (currently stored under advancedConfig).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +100
* remove the tool_choice field from the request.
* @note fix "Invalid tool_choice type: 'object'" for some LLMs.
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc for disableNamedToolChoice is misleading: it says this option removes the tool_choice field, but the implementation keeps tool_choice and uses the string value "required" (and only disables the named/object form when toolChoiceName is provided). Please update the comment to accurately describe the behavior and when it applies.

Suggested change
* remove the tool_choice field from the request.
* @note fix "Invalid tool_choice type: 'object'" for some LLMs.
* Disable the named/object tool_choice form when forcing a specific tool.
* When used together with `toolChoiceName`, the client sends `tool_choice: "required"`
* instead of `{ type: "function", function: { name: toolChoiceName } }`, keeping the
* `tool_choice` field but avoiding the object form that some LLMs reject with
* errors like "Invalid tool_choice type: 'object'".

Copilot uses AI. Check for mistakes.
Comment on lines 127 to 131
experimentalLlmsTxt,
disableNamedToolChoice,
...llmConfig
}: ExtConfig) => {
await chrome.storage.local.set({ llmConfig })
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disableNamedToolChoice is part of LLMConfig, but it’s destructured out here and therefore not included in the llmConfig object persisted to storage. That duplicates config concerns (it then gets stored under advancedConfig) and means anything reading only llmConfig will miss the flag. Consider keeping disableNamedToolChoice within llmConfig and out of AdvancedConfig so it persists with the other LLM settings.

Copilot uses AI. Check for mistakes.
@gaomeng1900 gaomeng1900 deleted the feat/optional-toolchoice branch March 20, 2026 11:00
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.

[Bug] 使用qwen3.5-35b-a3b本地模型 [Bug] 讯飞API调用失败

2 participants