mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 06:03:26 -05:00
[PR #24707] [CLOSED] fix: server-side native tool-calling loop for REST API requests #115105
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24707
Author: @PedroFCM
Created: 5/14/2026
Status: ❌ Closed
Base:
dev← Head:fix/native-tool-calling-api-loop-v2📝 Commits (1)
fe80419fix: real-time SSE streaming for native tool-calling loop📊 Changes
1 file changed (+169 additions, -7 deletions)
View changed files
📝
backend/open_webui/main.py(+169 -7)📄 Description
Summary
Problem: REST API consumers using
function_calling: nativewithtool_idsget rawtool_callsback — tools are never executed because the execution loop requires a WebSocket session managed by the frontend. This makes the REST API unusable for native tool calling, which is a common need for programmatic integrations, automation pipelines, and custom clients.This PR adds a server-side tool-calling loop that activates only for REST API requests (no
session_id) withfunction_calling == 'native'and tools present. It does not change the WebSocket path at all.Why this follow-up to #23581
The previous PR was closed with concerns about scope and approach. This implementation addresses those concerns:
execute_tool_server,_split_tool_calls,process_tool_result, andget_updated_tool_functionfrom the middleware. No new abstractions.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:
devdevfixChangelog Entry
Description
REST API consumers using
/api/chat/completionswithfunction_calling: nativeandtool_idsnever get tools executed server-side — tool calls are returned raw because the execution loop relies on a WebSocket session managed by the frontend. This PR adds a server-side tool-calling loop for the REST API path (nosession_id), making native tool calling work for API-only consumers.This is a follow-up to #23581 which was closed. The community interest remains (#9435), and this implementation addresses the feedback from @MrMakkarone about multiple tool calls being broken.
How to reproduce the issue (before this fix):
Result: Response contains raw
tool_callsthat are never executed. The LLM asks to call tools but nobody executes them.After this fix: Tools are executed server-side, results are fed back to the LLM, and the final answer is returned to the caller.
Added
session_id+function_calling == 'native'+ tools present)asyncio.gatherwith per-tool 30s timeoutexecute_tool_server_split_tool_callsChanged
function_callingparameter passes through configured value as-is instead of only recognizing'native'and falling back to'default'Deprecated
Removed
Fixed
tool_result_filesandtool_result_embedsare preserved in tool messagesSecurity
Breaking Changes
Additional Information
finallyblock after the response is returned — a lazy generator would lose the MCP session before tool execution beginsast.literal_evalprimary withjson.loadsfallback, matching the middleware's WebSocket pathScreenshots or Videos
N/A — API-only change, no UI impact. Validated via curl and k6 load tests.
Testing Evidence
Manually tested on AWS ECS Fargate with OpenWebUI 0.9.2 + this patch, using MCP tool servers (streamable HTTP).
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.