A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 23:45 UTC
Replace `--expand-tools-even-if-tool-choice-none` with `--exclude-tools-when-tool-choice-none` for v0.10.0 (#20544)
Signed-off-by: okada <kokuzen@gmail.com> Signed-off-by: okada shintarou <okada@preferred.jp> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Shintarou Okada committed
Jul 24, 2025 at 18:56 UTC
6eca337ce09e7dfa05ce57c4183ddb5d4488c85e
4 files changed
+13
-2
docs/features/tool_calling.md
+2
-1
@@ -103,7 +103,8 @@ When tool_choice='required' is set, the model is guaranteed to generate one or m
103
104
vLLM supports the `tool_choice='none'` option in the chat completion API. When this option is set, the model will not generate any tool calls and will respond with regular text content only, even if tools are defined in the request.
105
106
-However, when `tool_choice='none'` is specified, vLLM includes tool definitions from the prompt.
106
+!!! note
107
+ When tools are specified in the request, vLLM includes tool definitions in the prompt by default, regardless of the `tool_choice` setting. To exclude tool definitions when `tool_choice='none'`, use the `--exclude-tools-when-tool-choice-none` option.
108
109
## Automatic Function Calling
110
vllm/entrypoints/openai/api_server.py
+2
@@ -1646,6 +1646,8 @@ async def init_app_state(
1646
chat_template_content_format=args.chat_template_content_format,
1647
return_tokens_as_token_ids=args.return_tokens_as_token_ids,
1648
enable_auto_tools=args.enable_auto_tool_choice,
1649
+ exclude_tools_when_tool_choice_none=args.
1650
+ exclude_tools_when_tool_choice_none,
1651
tool_parser=args.tool_call_parser,
1652
reasoning_parser=args.reasoning_parser,
1653
enable_prompt_tokens_details=args.enable_prompt_tokens_details,
vllm/entrypoints/openai/cli_args.py
+3
@@ -133,6 +133,9 @@ schema. Example: `[{"type": "text", "text": "Hello world!"}]`"""
133
"""If specified, API server will add X-Request-Id header to responses.
134
Caution: this hurts performance at high QPS."""
135
enable_auto_tool_choice: bool = False
136
+ """If specified, exclude tool definitions in prompts when
137
+ tool_choice='none'."""
138
+ exclude_tools_when_tool_choice_none: bool = False
139
"""Enable auto tool choice for supported models. Use `--tool-call-parser`
140
to specify which parser to use."""
141
tool_call_parser: Optional[str] = None
vllm/entrypoints/openai/serving_chat.py
+6
-1
@@ -63,6 +63,7 @@ class OpenAIServingChat(OpenAIServing):
63
return_tokens_as_token_ids: bool = False,
64
reasoning_parser: str = "",
65
enable_auto_tools: bool = False,
66
+ exclude_tools_when_tool_choice_none: bool = False,
67
tool_parser: Optional[str] = None,
68
enable_prompt_tokens_details: bool = False,
69
enable_force_include_usage: bool = False,
@@ -111,6 +112,8 @@ class OpenAIServingChat(OpenAIServing):
112
raise TypeError("Error: --enable-auto-tool-choice requires "
113
f"tool_parser:'{tool_parser}' which has not "
114
"been registered") from e
115
+ self.exclude_tools_when_tool_choice_none = (
116
+ exclude_tools_when_tool_choice_none)
117
118
self.enable_prompt_tokens_details = enable_prompt_tokens_details
119
self.enable_force_include_usage = enable_force_include_usage
@@ -174,7 +177,9 @@ class OpenAIServingChat(OpenAIServing):
177
"--enable-auto-tool-choice and --tool-call-parser to be set"
178
)
179
177
- if request.tools is None:
180
+ if (request.tools is None
181
+ or (request.tool_choice == "none"
182
+ and self.exclude_tools_when_tool_choice_none)):
183
tool_dicts = None
184
else:
185
tool_dicts = [tool.model_dump() for tool in request.tools]