open-webui/backend/open_webui
Classic298 d3cfcd801e
fix: preserve system prompt across tool calls when memories are enabled (#26857)
* fix: preserve system prompt across tool calls when memories are enabled

The native tool-call loop runs generate_chat_completion with
bypass_system_prompt=True, so the provider layer does not re-apply the
model's default system prompt on tool-call iterations. It relies instead
on metadata['system_prompt'], captured in process_chat_payload, to carry
the full system prompt forward and restore it after RAG injection.

That capture read the model default system prompt from
form_data['params']['system'], but apply_params_to_form_data had already
popped 'params' from form_data, so model_system_prompt was always empty.
metadata['system_prompt'] therefore only captured whatever was already
materialized in the messages. With memories enabled, that is the injected
<memory_context> system message, so tool-call requests were restored with
memory-only system content and the model's system prompt was dropped.
Without memories there was no system message to capture at all.

Capture the model default system prompt from form_data['params'] before
apply_params_to_form_data pops it, and use that value when building
metadata['system_prompt'].

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014Z4L51mvxDJCx1EDxP2vFN

* refactor: condense system prompt capture comment to a single line

Replace the four-line explanation above the model_system_prompt capture with a one-line note. The variable name and the surrounding code already convey what happens; the comment only needs to state why the capture sits before apply_params_to_form_data.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-27 02:13:28 -04:00
..
data refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
internal perf: cut per-request database session overhead (#27385) 2026-07-23 17:49:48 -05:00
migrations chore: format 2026-07-27 00:12:47 -04:00
models refac 2026-07-27 02:11:10 -04:00
retrieval refac: owner-bind ephemeral web-search RAG collections (#26706) 2026-07-27 02:08:04 -04:00
routers refac: owner-bind ephemeral web-search RAG collections (#26706) 2026-07-27 02:08:04 -04:00
socket refac 2026-07-26 23:49:03 -04:00
static refac 2026-07-20 22:27:13 -04:00
storage refac: modernize type annotations (PEP 604 / PEP 585) 2026-05-12 17:10:15 +09:00
tools refac 2026-07-27 01:59:17 -04:00
utils fix: preserve system prompt across tool calls when memories are enabled (#26857) 2026-07-27 02:13:28 -04:00
__init__.py refac 2026-06-17 03:01:11 +02:00
alembic.ini fix: Alembic CLI commands from failing 2025-08-15 04:17:47 -04:00
config.py chore: format 2026-07-27 00:12:47 -04:00
constants.py refac 2026-06-29 05:46:51 -05:00
env.py refac 2026-07-27 01:21:32 -04:00
events.py refac 2026-07-26 19:10:41 -04:00
functions.py refac 2026-07-23 03:39:56 -04:00
main.py perf: stop refetching the model row and user groups in the completion access check (#27378) 2026-07-27 01:52:04 -04:00
tasks.py refac 2026-07-26 22:45:11 -04:00