mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-31 14:00:34 -05:00
[PR #21668] [CLOSED] fix: prevent recursive RAG template nesting during multi-turn tool calling #41824
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/21668
Author: @Classic298
Created: 2/20/2026
Status: ❌ Closed
Base:
dev← Head:rag-fix📝 Commits (3)
e8e9981Update middleware.py43aedfcUpdate middleware.py61d2795fix: prevent recursive RAG template nesting during multi-turn tool calling📊 Changes
1 file changed (+33 additions, -13 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+33 -13)📄 Description
When native tool calling produced multiple sequential tool calls with
citation sources (e.g. repeated search_web or fetch_url), the RAG
template was recursively injected into the user message on each
iteration. This caused the user message to grow exponentially, wasting
context window and potentially confusing models into parroting the RAG
instructions into subsequent tool call arguments.
Fix: save the original user message before the tool-calling loop and
restore it before each re-application. Sources now accumulate across
iterations so the RAG template is applied once with a growing source
list, rather than being recursively nested N times.
Tested locally
Fixes: https://github.com/open-webui/open-webui/issues/21663
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.