[PR #19862] [CLOSED] fix: preserve parameters through tool calling loops #48415

Closed
opened 2026-04-30 00:15:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/19862
Author: @Haervwe
Created: 12/10/2025
Status: Closed

Base: devHead: fix/tool-calling-parameter-persistence


📝 Commits (7)

📊 Changes

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

View changed files

📝 backend/open_webui/utils/payload.py (+7 -4)

📄 Description

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch. Branch is based on upstream/dev
  • Description: Provide a concise description of the changes made in this pull request down below. Provided below
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description. Included below
  • Documentation: If necessary, update relevant documentation Open WebUI Docs like environment variables, the tutorials, or other documentation sources. N/A - Backend fix only, no new user-facing features or env vars
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation? No new dependencies
  • Testing: Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Manually tested with filter setting body["options"]["think"] = False and verified parameter persists through tool call loops
  • Agentic AI Code: Confirm this Pull Request is not written by any AI Agent or has at least gone through additional human review AND manual testing. Code has been reviewed and manually tested - fix is minimal and focused (7 insertions, 4 deletions)
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? Self-reviewed - changes follow existing code patterns
  • Title Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following: Using fix: prefix

Description

Fixes parameter reset issue during native tool calls where filter-set or UI-set parameters (like Ollama's think) were being lost after tool execution, causing inconsistent behavior in hybrid models during tool calling loops.

Problem

When parameters are set via filters or frontend settings, they get reset after native tool calls. The convert_payload_openai_to_ollama() function was:

  1. Creating a new empty dictionary, losing previously moved root-level parameters
  2. Using references instead of copies for the options dict, causing mutation issues
  3. Being called multiple times during tool calling loops, resetting parameters each time

This caused hybrid models to ignore configured parameters during tool execution, leading to inconsistent thinking behavior.

Solution

Modified convert_payload_openai_to_ollama() in backend/open_webui/utils/payload.py:

  1. Preserve all fields during conversion:

    # Before: ollama_payload = {}
    # After: ollama_payload = {**openai_payload}
    

    This maintains root-level parameters like think across multiple conversions.

  2. Fix options dict mutation:

    # Before: ollama_options = openai_payload["options"]
    # After: ollama_options = dict(openai_payload["options"])
    

    Creates proper copy to avoid mutating the original payload.

  3. Fix incorrect deletion target:

    # Before: del openai_payload["max_tokens"]
    # After: del ollama_payload["max_tokens"]
    

    Deletes from the correct dictionary.

Testing Performed

  • Tested with filter setting body["options"]["think"] = False
  • Verified parameter persists through multiple tool call iterations
  • Confirmed hybrid models respect thinking parameter throughout conversation
  • Validated both filter-set and UI-set parameters are maintained
  • Verified existing functionality remains unaffected

Impact

  • No breaking changes - all existing functionality preserved
  • Fixes filter and UI setted parameter persistence for Ollama models
  • Improves tool calling reliability
  • Ensures UI parameter settings are respected throughout conversations

Changelog Entry

Description

Fixed parameter preservation in Ollama payload conversion function to ensure filter-set and UI-set parameters persist through native tool calling loops, resolving inconsistent behavior where parameters like think were being reset after tool execution.

Added

  • None

Changed

  • convert_payload_openai_to_ollama() now preserves all fields by copying entire payload instead of creating empty dict
  • Options dictionary is now properly copied instead of referenced to prevent mutation issues
  • Fixed deletion target from openai_payload to ollama_payload for max_tokens

Deprecated

  • None

Removed

  • None

Fixed

  • Fixed parameter reset during native tool calls where filter-set parameters were lost
  • Fixed convert_payload_openai_to_ollama() losing root-level parameters like think during multiple conversions
  • Fixed options dict mutation issues causing unintended side effects
  • Fixed incorrect dictionary mutation when deleting max_tokens
  • Resolved inconsistent thinking behavior in hybrid models during tool execution

Security

  • None

Breaking Changes

  • None

Additional Information

Root Cause Analysis:
The conversion function was creating a new empty dictionary (ollama_payload = {}) and only copying specific known fields. During tool calling loops, this function is called multiple times:

  1. First call: think parameter moves from options to root level
  2. Tool call loop creates new request with all fields
  3. Second call: Empty dict created again, losing root-level think
  4. Parameters reset to defaults

Additionally, using ollama_options = openai_payload["options"] created a reference, causing mutations to affect the original payload.

Files Modified:

  • backend/open_webui/utils/payload.py (7 insertions, 4 deletions)

Related Context:

  • Affects Ollama models using parameters like think, keep_alive, format
  • Critical for filters modifying model behavior during tool calls
  • Ensures consistent parameter handling in multi-turn tool calling scenarios
  • Fixes behavior for hybrid models (e.g., qwen3 14b with native tool calling)

Screenshots or Videos

BEFORE:

Screenshot from 2025-12-10 10-55-14

AFTER:

Screenshot from 2025-12-10 11-28-11

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.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/19862 **Author:** [@Haervwe](https://github.com/Haervwe) **Created:** 12/10/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/tool-calling-parameter-persistence` --- ### 📝 Commits (7) - [`fe6783c`](https://github.com/open-webui/open-webui/commit/fe6783c16699911c7be17392596d579333fb110c) Merge pull request #19030 from open-webui/dev - [`fc05e0a`](https://github.com/open-webui/open-webui/commit/fc05e0a6c5d39da60b603b4d520f800d6e36f748) Merge pull request #19405 from open-webui/dev - [`e3faec6`](https://github.com/open-webui/open-webui/commit/e3faec62c58e3a83d89aa3df539feacefa125e0c) Merge pull request #19416 from open-webui/dev - [`9899293`](https://github.com/open-webui/open-webui/commit/9899293f050ad50ae12024cbebee7e018acd851e) Merge pull request #19448 from open-webui/dev - [`140605e`](https://github.com/open-webui/open-webui/commit/140605e660b8186a7d5c79fb3be6ffb147a2f498) Merge pull request #19462 from open-webui/dev - [`6f1486f`](https://github.com/open-webui/open-webui/commit/6f1486ffd0cb288d0e21f41845361924e0d742b3) Merge pull request #19466 from open-webui/dev - [`df1786f`](https://github.com/open-webui/open-webui/commit/df1786f3ee7d4bcf3f8867f687be7db024b5ef8b) fix: preserve parameters through tool calling loops ### 📊 Changes **1 file changed** (+7 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/payload.py` (+7 -4) </details> ### 📄 Description # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Verify that the pull request targets the `dev` branch. ✅ Branch is based on `upstream/dev` - [x] **Description:** Provide a concise description of the changes made in this pull request down below. ✅ Provided below - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. ✅ Included below - [x] **Documentation:** If necessary, update relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs) like environment variables, the tutorials, or other documentation sources. ✅ N/A - Backend fix only, no new user-facing features or env vars - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? ✅ No new dependencies - [x] **Testing:** Perform manual tests to **verify the implemented fix/feature works as intended AND does not break any other functionality**. ✅ Manually tested with filter setting `body["options"]["think"] = False` and verified parameter persists through tool call loops - [x] **Agentic AI Code:** Confirm this Pull Request is **not written by any AI Agent** or has at least **gone through additional human review AND manual testing**. ✅ Code has been reviewed and manually tested - fix is minimal and focused (7 insertions, 4 deletions) - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? ✅ Self-reviewed - changes follow existing code patterns - [x] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: ✅ Using `fix:` prefix --- # Description Fixes parameter reset issue during native tool calls where filter-set or UI-set parameters (like Ollama's `think`) were being lost after tool execution, causing inconsistent behavior in hybrid models during tool calling loops. ## Problem When parameters are set via filters or frontend settings, they get reset after native tool calls. The `convert_payload_openai_to_ollama()` function was: 1. Creating a new empty dictionary, losing previously moved root-level parameters 2. Using references instead of copies for the options dict, causing mutation issues 3. Being called multiple times during tool calling loops, resetting parameters each time This caused hybrid models to ignore configured parameters during tool execution, leading to inconsistent thinking behavior. ## Solution Modified `convert_payload_openai_to_ollama()` in `backend/open_webui/utils/payload.py`: 1. **Preserve all fields during conversion:** ```python # Before: ollama_payload = {} # After: ollama_payload = {**openai_payload} ``` This maintains root-level parameters like `think` across multiple conversions. 2. **Fix options dict mutation:** ```python # Before: ollama_options = openai_payload["options"] # After: ollama_options = dict(openai_payload["options"]) ``` Creates proper copy to avoid mutating the original payload. 3. **Fix incorrect deletion target:** ```python # Before: del openai_payload["max_tokens"] # After: del ollama_payload["max_tokens"] ``` Deletes from the correct dictionary. ## Testing Performed - ✅ Tested with filter setting `body["options"]["think"] = False` - ✅ Verified parameter persists through multiple tool call iterations - ✅ Confirmed hybrid models respect thinking parameter throughout conversation - ✅ Validated both filter-set and UI-set parameters are maintained - ✅ Verified existing functionality remains unaffected ## Impact - No breaking changes - all existing functionality preserved - Fixes filter and UI setted parameter persistence for Ollama models - Improves tool calling reliability - Ensures UI parameter settings are respected throughout conversations --- # Changelog Entry ### Description Fixed parameter preservation in Ollama payload conversion function to ensure filter-set and UI-set parameters persist through native tool calling loops, resolving inconsistent behavior where parameters like `think` were being reset after tool execution. ### Added - None ### Changed - `convert_payload_openai_to_ollama()` now preserves all fields by copying entire payload instead of creating empty dict - Options dictionary is now properly copied instead of referenced to prevent mutation issues - Fixed deletion target from `openai_payload` to `ollama_payload` for `max_tokens` ### Deprecated - None ### Removed - None ### Fixed - Fixed parameter reset during native tool calls where filter-set parameters were lost - Fixed `convert_payload_openai_to_ollama()` losing root-level parameters like `think` during multiple conversions - Fixed options dict mutation issues causing unintended side effects - Fixed incorrect dictionary mutation when deleting `max_tokens` - Resolved inconsistent thinking behavior in hybrid models during tool execution ### Security - None ### Breaking Changes - None --- ### Additional Information **Root Cause Analysis:** The conversion function was creating a new empty dictionary (`ollama_payload = {}`) and only copying specific known fields. During tool calling loops, this function is called multiple times: 1. First call: `think` parameter moves from options to root level 2. Tool call loop creates new request with all fields 3. Second call: Empty dict created again, losing root-level `think` 4. Parameters reset to defaults Additionally, using `ollama_options = openai_payload["options"]` created a reference, causing mutations to affect the original payload. **Files Modified:** - `backend/open_webui/utils/payload.py` (7 insertions, 4 deletions) **Related Context:** - Affects Ollama models using parameters like `think`, `keep_alive`, `format` - Critical for filters modifying model behavior during tool calls - Ensures consistent parameter handling in multi-turn tool calling scenarios - Fixes behavior for hybrid models (e.g., qwen3 14b with native tool calling) ### Screenshots or Videos BEFORE: <img width="2301" height="1252" alt="Screenshot from 2025-12-10 10-55-14" src="https://github.com/user-attachments/assets/20470e19-de56-4bb3-8915-28afb87de675" /> AFTER: <img width="2301" height="1252" alt="Screenshot from 2025-12-10 11-28-11" src="https://github.com/user-attachments/assets/4920cdc6-cacf-4b9b-a44d-5de7d8395c36" /> ### 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. ` --- <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-30 00:15:14 -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#48415