Skip to content

feat: add response request tool render in chat_template and restructure output#1

Merged
Leoyzen merged 1 commit intoLeoyzen:fix/response-api-tool-type-constraintfrom
LuYanFCP:fix/response-chat-template
Feb 9, 2026
Merged

feat: add response request tool render in chat_template and restructure output#1
Leoyzen merged 1 commit intoLeoyzen:fix/response-api-tool-type-constraintfrom
LuYanFCP:fix/response-chat-template

Conversation

@LuYanFCP
Copy link

@LuYanFCP LuYanFCP commented Feb 6, 2026

Add Feature in you patch

  • Tool rendering in chat_template: Convert the flat ResponseTool format to the nested Tool/Function format used by ChatCompletionRequest, so that tools are correctly passed to the chat template during prompt construction. This ensures models can see tool definitions in their expected format.
  • Tool call parsing in response output: Integrate FunctionCallParser to detect and parse tool calls from model output. When tool_call_parser is configured and tools are provided, the response will properly extract function_call items instead of returning raw tool call text.

Test in Qwen3-Coder-Next

curl -X POST "http://localhost:30000/v1/responses" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-Coder-Next",
    "input": "What is the weather like in Boston today?",
    "tools": [
      {
        "type": "function",
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"]
            }
          },
          "required": ["location", "unit"]
        }
      }
    ],
    "tool_choice": "auto"
  }'

before patch
image

after patch
image

@gemini-code-assist
Copy link

Summary of Changes

Hello @LuYanFCP, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the system's capability to handle tool interactions by introducing robust mechanisms for both tool definition rendering and tool call parsing. It ensures that tool specifications are correctly formatted and passed to models via chat templates, and that model-generated tool calls are accurately identified and structured in the output. These improvements are crucial for enabling advanced function calling features and improving the overall integration of external tools with the language model.

Highlights

  • Tool Format Conversion: Implemented conversion of flat ResponseTool objects to the nested Tool/Function format required by ChatCompletionRequest for proper tool definition rendering in chat templates.
  • Tool Call Parsing: Integrated FunctionCallParser to detect and extract tool calls from model outputs, restructuring the response to include ResponseFunctionToolCall items instead of raw text when tools are used.
  • Enhanced ChatCompletionRequest: The ChatCompletionRequest now supports tools and tool_choice parameters, enabling more sophisticated tool-use scenarios.
  • Minor Copy Fix: Updated a copy() call to copy.copy() for explicit shallow copying of prev_response.output.
Changelog
  • python/sglang/srt/entrypoints/openai/serving_responses.py
    • Added necessary imports for Function, Tool, and FunctionCallParser to support new tool handling logic.
    • Introduced logic within _make_request to transform ResponseTool objects into the Tool and Function nested structure expected by ChatCompletionRequest.
    • Modified ChatCompletionRequest instantiation to pass tools and tool_choice parameters.
    • Implemented a new section in _make_response_output_items to utilize FunctionCallParser for detecting and parsing tool calls from model content, converting them into structured ResponseFunctionToolCall objects.
    • Corrected a copy operation to copy.copy for explicit shallow copying of prev_response.output.
Activity
  • The pull request introduces two core features: tool rendering in chat templates and tool call parsing in response output.
  • The author, LuYanFCP, provided a clear problem statement and solution approach in the PR description.
  • Detailed test instructions with a curl example and visual comparisons ("before patch" and "after patch" images) were included to demonstrate the functionality.
  • The changes are concentrated in serving_responses.py, indicating a focused modification to the OpenAI API serving layer.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds tool rendering in chat_template and tool call parsing in the response output, which is a great enhancement for function calling capabilities. The changes in serving_responses.py correctly implement the logic for converting tool formats and parsing tool calls from the model output. My review includes suggestions to refactor duplicated code and remove an unused variable to improve code quality and maintainability. The bug fix for the copy call is also correct. Overall, the implementation looks solid.

@Leoyzen Leoyzen changed the base branch from main to fix/response-api-tool-type-constraint February 6, 2026 14:05
@Leoyzen
Copy link
Owner

Leoyzen commented Feb 6, 2026

@LuYanFCP Plz fix the issues so I can merge it into the branch.

@LuYanFCP LuYanFCP force-pushed the fix/response-chat-template branch from 83582b4 to 6e776d6 Compare February 7, 2026 12:29
@LuYanFCP
Copy link
Author

LuYanFCP commented Feb 7, 2026

Fixed

@Leoyzen Leoyzen merged commit 7617a89 into Leoyzen:fix/response-api-tool-type-constraint Feb 9, 2026
1 check passed
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.

2 participants