vllm.entrypoints.openai.responses.utils
¶
Functions:
-
build_response_output_items–Build the output items of one generation.
-
construct_chat_messages_with_tool_call–Build chat messages from response items.
-
convert_tool_responses_to_completions_format–Convert a flat Responses tool schema:
-
decode_custom_tool_input–Payload of a completed shim call; bare text is passed through.
-
decode_custom_tool_input_prefix–Longest decodable payload prefix of partial shim arguments, so that
-
decode_tool_search_arguments–Arguments of a
tool_search_call; text that is not JSON is kept as is. -
extend_custom_tool_input_prefix–decode_custom_tool_input_prefixof arguments, decoding only -
extract_tool_types–Extracts the tool types from the given tools.
-
render_loaded_tools–Tool-message text for a
tool_search_output: one schema per line. -
response_item_status–Status of the output item that ended a generation with
finish_reason. -
reuse_streamed_item_ids–Give rebuilt output items the ids already streamed for the same message.
-
should_continue_final_message–Determine if the last input message is a partial assistant message
-
tool_search_names–Names of the functions that are client-executed
tool_searchcalls. -
tool_search_output_content–Tool-message content for a
tool_search_output.
_construct_message_from_response_item(item, prev_msg=None, tool_reference_names=None)
¶
Returns a new message or None. If None, prev_msg might be updated.
If prev_msg is None, a new message is always returned.
_loaded_function_tools(tools)
¶
The functions a tool_search_output loads, named as the model sees
them (namespace members as <namespace>__<name>). Tool types that cannot
be loaded are skipped.
_warn_unloadable_deferred_tools(tools)
¶
Warn about tools the model is told to load but cannot.
Only a client-executed tool_search is shown to the model, so with any
other setup a chat template that lists deferred functions without their
schema leaves the model to guess the arguments. Templates that ignore
defer_loading still show the full schema, so this is not an error.
build_response_output_items(reasoning, content, tool_calls, logprobs=None, tools=None, finish_reason=None)
¶
Build the output items of one generation.
Only the last item can have been cut short, so finish_reason decides
that item's status and every earlier item is completed.
construct_chat_messages_with_tool_call(input_messages, tool_reference_names=None)
¶
Build chat messages from response items.
Some chat messages span multiple response items (e.g., reasoning + tool calls).
See tool_search_output_content for tool_reference_names.
convert_tool_responses_to_completions_format(tool)
¶
Convert a flat Responses tool schema
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into a Chat Completions tool param for chat-template rendering.
decode_custom_tool_input(arguments)
¶
Payload of a completed shim call; bare text is passed through.
decode_custom_tool_input_prefix(arguments)
¶
Longest decodable payload prefix of partial shim arguments, so that
streamed custom_tool_call_input deltas stay a prefix of the final input.
decode_tool_search_arguments(arguments)
¶
Arguments of a tool_search_call; text that is not JSON is kept as is.
extend_custom_tool_input_prefix(arguments, payload, end)
¶
decode_custom_tool_input_prefix of arguments, decoding only
arguments[end:]. payload and end come from the previous call on a
prefix of arguments ("" and 0 at first). Returns None when the
arguments do not start as encode_custom_tool_input writes them,
or once the payload string closes; only a full decode is exact then.
extract_tool_types(tools)
¶
Extracts the tool types from the given tools.
render_loaded_tools(tools)
¶
Tool-message text for a tool_search_output: one schema per line.
Each loaded function is written the way the chat template is given functions, so the model can call it by that name.
response_item_status(finish_reason)
¶
Status of the output item that ended a generation with finish_reason.
reuse_streamed_item_ids(items, streamed_items)
¶
Give rebuilt output items the ids already streamed for the same message.
Items are paired by type in order; an item without a streamed counterpart keeps its own id.
should_continue_final_message(request_input)
¶
Determine if the last input message is a partial assistant message that should be continued rather than starting a new generation.
This enables partial message completion similar to Anthropic's Messages API, where users can provide an incomplete assistant message and have the model continue from where it left off.
A message is considered partial if: 1. It's a ResponseOutputMessage or ResponseReasoningItem 2. Its status is "in_progress" or "incomplete"
Parameters:
Returns:
-
bool–True if the final message should be continued, False otherwise
tool_search_names(tools)
¶
Names of the functions that are client-executed tool_search calls.
tool_search_output_content(tools, tool_reference_names)
¶
Tool-message content for a tool_search_output.
tool_reference_names is set when the chat template renders
tool_reference parts (GLM-5.3 prints each referenced definition from
tools) and holds the functions the template is given. If every loaded
function is one of them, the result is one tool_reference part per
function, as /v1/messages sends tool search results. Otherwise it is one
schema line per function: the template cannot expand a reference to a
function it is not given, and GLM-5.3 renders only the references when the
first part is one, so the two are not mixed.