[PR #20933] [CLOSED] fix: set finish_reason to "tool_calls" when tool calls are present in API responses #41470

Closed
opened 2026-04-25 13:42:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20933
Author: @Classic298
Created: 1/25/2026
Status: Closed

Base: devHead: tool-call-early-stop


📝 Commits (1)

  • dea3e4e fix: set finish_reason to "tool_calls" when tool calls are present in API responses

📊 Changes

1 file changed (+4 additions, -2 deletions)

View changed files

📝 backend/open_webui/utils/misc.py (+4 -2)

📄 Description

fix: set finish_reason to "tool_calls" when tool calls are present in API responses

When Open WebUI converts Ollama responses to OpenAI format, finish_reason was always set to "stop" even when tool_calls were present. This caused external API clients (like OpenCode) to stop after receiving tool calls instead of continuing the conversation.

Per the OpenAI API specification, finish_reason should be "tool_calls" when the model returns tool calls, signaling to clients that they should execute the tools and continue. This fix updates both streaming and non-streaming response templates to set the correct finish_reason based on whether tool_calls are present.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), 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.


🔄 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/20933 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/25/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `tool-call-early-stop` --- ### 📝 Commits (1) - [`dea3e4e`](https://github.com/open-webui/open-webui/commit/dea3e4ecdec60e9cf7258abd57c012c439d89ef3) fix: set finish_reason to "tool_calls" when tool calls are present in API responses ### 📊 Changes **1 file changed** (+4 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/misc.py` (+4 -2) </details> ### 📄 Description fix: set finish_reason to "tool_calls" when tool calls are present in API responses When Open WebUI converts Ollama responses to OpenAI format, finish_reason was always set to "stop" even when tool_calls were present. This caused external API clients (like OpenCode) to stop after receiving tool calls instead of continuing the conversation. Per the OpenAI API specification, finish_reason should be "tool_calls" when the model returns tool calls, signaling to clients that they should execute the tools and continue. This fix updates both streaming and non-streaming response templates to set the correct finish_reason based on whether tool_calls are present. ### Contributor License Agreement 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-04-25 13:42:51 -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#41470