[PR #24014] [CLOSED] fix: native tool-call continuation for Kimi thinking models #66333

Closed
opened 2026-05-06 12:38:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24014
Author: @safzanpirani
Created: 4/22/2026
Status: Closed

Base: devHead: fix-kimi-tool-reasoning-continuation


📝 Commits (1)

  • 2383e94 Fix Kimi tool-call continuation reasoning

📊 Changes

3 files changed (+283 additions, -3 deletions)

View changed files

backend/open_webui/test/util/test_misc.py (+158 -0)
📝 backend/open_webui/utils/middleware.py (+12 -3)
📝 backend/open_webui/utils/misc.py (+113 -0)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.

This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch. PRs targeting main will be immediately closed.
  • Description: Provide a concise description of the changes made in this pull request down below.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Add docs in Open WebUI Docs Repository. Document user-facing behavior, environment variables, public APIs/interfaces, or deployment steps.
  • Dependencies: No new or upgraded dependencies are introduced in this PR.
  • Testing: Performed manual tests to verify the implemented fix works as intended and does not break the native tool continuation flow. Repro steps and results are documented below.
  • Agentic AI Code: This change was AI-assisted. It was manually reviewed and tested on a live deployment before submitting this PR.
  • Code review: Performed a self-review of the code and kept the change scoped to one bug fix.
  • Design & Architecture: Kept the fix local to provider-specific continuation handling instead of changing generic message reconstruction for every backend.
  • Git Hygiene: PR is atomic, rebased onto dev, and only contains the continuation fix and regression coverage.
  • Title Prefix: PR title uses the fix: prefix.

Changelog Entry

Description

  • Preserve reasoning_content when Open WebUI rebuilds assistant tool-call messages for Kimi/Moonshot continuation turns so native tool calling can continue to a final answer.

Added

  • Regression coverage for reattaching reasoning content to the correct assistant tool-call message boundaries.

Changed

  • Moved provider-specific reasoning-content restoration into middleware continuation handling instead of changing convert_output_to_messages() globally.

Deprecated

  • None.

Removed

  • None.

Fixed

  • Fixed native tool-call continuation for Kimi thinking models where the first tool call succeeds, tool output is returned, and the follow-up request fails because the reconstructed assistant tool-call message is missing top-level reasoning_content.

Security

  • None.

Breaking Changes

  • BREAKING CHANGE: None.

Additional Information

  • Provider-side failure reproduced against the OpenAI-compatible backend as:
thinking is enabled but reasoning_content is missing in assistant tool call message at index 1
  • Kimi documentation for preserved thinking / multi-step tool calls:
  • Implementation details:
    • Only reattach reasoning_content for model IDs that look like Kimi/Moonshot.
    • Reattach it in both native tool continuation paths in streaming_chat_response_handler.
    • Map reasoning back onto the matching assistant message boundaries instead of copying one global reasoning blob onto every earlier tool-call message.

Screenshots or Videos

  • No screenshots attached. Validation was done against a live Open WebUI deployment where the original browser-chat failure reproduced after successful tool execution.

Testing Performed

  • Live browser validation against a private Open WebUI deployment using kimi-k2.6 in native tool mode:
    • Prompt: list my notes
    • Expected/observed: search_notes executed and the assistant returned a normal final answer instead of stopping after the tool result.
  • Live browser validation of the web-search path on the same deployment:
    • Prompt flow: retried a historical web search for "Rakhi Kaag" conversation that previously stopped after search_web.
    • Expected/observed: search_web executed and the assistant returned a normal final answer after the tool result.
  • Provider-level reproduction against the OpenAI-compatible backend:
    • Without top-level reasoning_content on the assistant tool-call message, the continuation request failed with the error quoted above.
    • With reasoning_content preserved, the provider returned a normal final answer.
  • Static validation:
    • python3 -m py_compile backend/open_webui/utils/misc.py backend/open_webui/utils/middleware.py backend/open_webui/test/util/test_misc.py
  • Targeted helper verification:
    • Directly exercised add_reasoning_content_to_tool_messages() with multi-step tool-call output sequences to confirm reasoning is reattached to the matching assistant tool-call turn.

Contributor License Agreement

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/24014 **Author:** [@safzanpirani](https://github.com/safzanpirani) **Created:** 4/22/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-kimi-tool-reasoning-continuation` --- ### 📝 Commits (1) - [`2383e94`](https://github.com/open-webui/open-webui/commit/2383e9498595d0862ed7914d787ea27c5bf48acf) Fix Kimi tool-call continuation reasoning ### 📊 Changes **3 files changed** (+283 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `backend/open_webui/test/util/test_misc.py` (+158 -0) 📝 `backend/open_webui/utils/middleware.py` (+12 -3) 📝 `backend/open_webui/utils/misc.py` (+113 -0) </details> ### 📄 Description <!-- ⚠️ CRITICAL CHECKS FOR CONTRIBUTORS (READ, DON'T DELETE) ⚠️ 1. Target the `dev` branch. PRs targeting `main` will be automatically closed. 2. Do NOT delete the CLA section at the bottom. It is required for the bot to accept your PR. --> # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request. This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Verify that the pull request targets the `dev` branch. **PRs targeting `main` will be immediately closed.** - [x] **Description:** Provide a concise description of the changes made in this pull request down below. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Add docs in [Open WebUI Docs Repository](https://github.com/open-webui/docs). Document user-facing behavior, environment variables, public APIs/interfaces, or deployment steps. - [x] **Dependencies:** No new or upgraded dependencies are introduced in this PR. - [x] **Testing:** Performed manual tests to verify the implemented fix works as intended and does not break the native tool continuation flow. Repro steps and results are documented below. - [x] **Agentic AI Code:** This change was AI-assisted. It was manually reviewed and tested on a live deployment before submitting this PR. - [x] **Code review:** Performed a self-review of the code and kept the change scoped to one bug fix. - [x] **Design & Architecture:** Kept the fix local to provider-specific continuation handling instead of changing generic message reconstruction for every backend. - [x] **Git Hygiene:** PR is atomic, rebased onto `dev`, and only contains the continuation fix and regression coverage. - [x] **Title Prefix:** PR title uses the `fix:` prefix. # Changelog Entry ### Description - Preserve `reasoning_content` when Open WebUI rebuilds assistant tool-call messages for Kimi/Moonshot continuation turns so native tool calling can continue to a final answer. ### Added - Regression coverage for reattaching reasoning content to the correct assistant tool-call message boundaries. ### Changed - Moved provider-specific reasoning-content restoration into middleware continuation handling instead of changing `convert_output_to_messages()` globally. ### Deprecated - None. ### Removed - None. ### Fixed - Fixed native tool-call continuation for Kimi thinking models where the first tool call succeeds, tool output is returned, and the follow-up request fails because the reconstructed assistant tool-call message is missing top-level `reasoning_content`. ### Security - None. ### Breaking Changes - **BREAKING CHANGE**: None. --- ### Additional Information - Provider-side failure reproduced against the OpenAI-compatible backend as: ```text thinking is enabled but reasoning_content is missing in assistant tool call message at index 1 ``` - Kimi documentation for preserved thinking / multi-step tool calls: - <https://platform.kimi.ai/docs/guide/use-kimi-k2-thinking-model#accessing-the-reasoning-content> - Implementation details: - Only reattach `reasoning_content` for model IDs that look like Kimi/Moonshot. - Reattach it in both native tool continuation paths in `streaming_chat_response_handler`. - Map reasoning back onto the matching assistant message boundaries instead of copying one global reasoning blob onto every earlier tool-call message. ### Screenshots or Videos - No screenshots attached. Validation was done against a live Open WebUI deployment where the original browser-chat failure reproduced after successful tool execution. ### Testing Performed - Live browser validation against a private Open WebUI deployment using `kimi-k2.6` in native tool mode: - Prompt: `list my notes` - Expected/observed: `search_notes` executed and the assistant returned a normal final answer instead of stopping after the tool result. - Live browser validation of the web-search path on the same deployment: - Prompt flow: retried a historical `web search for "Rakhi Kaag"` conversation that previously stopped after `search_web`. - Expected/observed: `search_web` executed and the assistant returned a normal final answer after the tool result. - Provider-level reproduction against the OpenAI-compatible backend: - Without top-level `reasoning_content` on the assistant tool-call message, the continuation request failed with the error quoted above. - With `reasoning_content` preserved, the provider returned a normal final answer. - Static validation: - `python3 -m py_compile backend/open_webui/utils/misc.py backend/open_webui/utils/middleware.py backend/open_webui/test/util/test_misc.py` - Targeted helper verification: - Directly exercised `add_reasoning_content_to_tool_messages()` with multi-step tool-call output sequences to confirm reasoning is reattached to the matching assistant tool-call turn. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA. --> - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 12:38:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#66333