mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #19578] [CLOSED] feat: Transform tool calls into proper messages #25253
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/19578
Author: @Oleg52
Created: 11/28/2025
Status: ❌ Closed
Base:
dev← Head:feature/tools-system📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/devfc68071transform tool calls into proper messages96c7c94add env to control tool execution resultd10a71cfix parseDoubleEncodedString0422b5efix formatting0790cc8fix formatting📊 Changes
4 files changed (+161 additions, -53 deletions)
View changed files
📝
backend/open_webui/env.py(+15 -0)📝
backend/open_webui/utils/middleware.py(+15 -5)📝
src/lib/components/chat/Chat.svelte(+73 -39)📝
src/lib/utils/index.ts(+58 -9)📄 Description
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch will lead to immediate closure of the PR.Changelog Entry
Description
Since server side already sends proper structure when it handles tool call requests, this change should not break anything.
Messages structure that is sent before change:
Messages structure that is sent after change:
Messages structure that is sent after change when tool call had failed(attribute done=false):
Why this matters: my MCP tool returns lengthy json string(around 30k tokens), with the current implementation tool result is sent as html encoded string and it results in drastic tokens count increase(up to 1.5M tokens!), also tool calling context is not passed to the model.
Added
This change also introduces 2 non-persistent environment variables:
ENABLE_WRAP_TOOL_RESULT- enables or disables tool result wrapping intoresultsarray.TOOL_RESULT_INDENT_SIZE- sets indent count forjson.dumpsfunction when serializing tool result. If it's set to 0, compact json will be produced. In my case it saves ~14k tokens on a lengthy json.Additional Information
I tested it with my private MCP server with both Default and Native function calling types. Single and multiple function calls are passed properly.
There's an open discussion #18622 that also addresses tool call messages structure, but it suggest database schema modification.
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.