[PR #18375] [CLOSED] fix: native tool calling message updates for sequential tool calls #47818

Closed
opened 2026-04-29 23:12:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/18375
Author: @jmleksan
Created: 10/16/2025
Status: Closed

Base: devHead: fix/native-tool-calling-message-updates


📝 Commits (3)

  • 73dd626 Native tool calling message updates
  • 9f16eed Refactor awaitable result handling in tools.py
  • 91d79e4 Remove unnecessary blank lines in tools.py

📊 Changes

2 files changed (+54 additions, -4 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+26 -4)
📝 backend/open_webui/utils/tools.py (+28 -0)

📄 Description

Pull Request Checklist

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

  • Target branch: Verify that the pull request targets the dev branch. Not targeting the dev branch may lead to immediate closure of the PR.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: If necessary, update relevant documentation Open WebUI Docs like environment variables, the tutorials, or other documentation sources.
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Take this as an opportunity to make screenshots of the feature/fix and include it in the PR description.
  • 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. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.
  • 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?
  • Title Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

  • 🛠️ Fixed native tool calling to support sequential tool calls with shared context, allowing tools to access images and data from previous tool executions in the same conversation.

Description

Description

Fixed native tool calling to support sequential tool calls with shared context

In native function calling mode, tools were unable to access conversation history from previous tool calls within the same conversation. This prevented workflows like:

  1. User: "Generate an image of a bear"
  2. Tool generates image
  3. User: "Make the bear's eyes blue"
  4. Tool cannot find the previously generated image

This occurred because tool functions were created with frozen __messages__ parameters using functools.partial, which captured only the initial conversation state. Subsequent tool calls in the same conversation continued using the stale frozen parameters instead of the updated message history.

Solution: Modified the tool calling system to dynamically update context parameters (__messages__, __files__) on each tool execution in native mode by storing a reference to the original unwrapped function and re-applying parameters with current state.

Fixed

  • Fixed native tool calling mode to provide updated __messages__ and __files__ parameters to tools on each execution
  • Tools in native mode can now access data (images, files, etc.) generated by previous tool calls in the same conversation
  • Enables multi-step workflows where tools build upon each other's outputs (e.g., generate image → edit image)

Changed

  • backend/open_webui/utils/tools.py:
    • Modified get_async_tool_function_and_apply_extra_params() to store references to original function and initial parameters
    • Added get_tool_function_with_updated_params() helper function to re-call tools with updated context
  • backend/open_webui/utils/middleware.py:
    • Modified native tool execution path to check for stored original function and re-apply parameters with current form_data["messages"]

Additional Information

  • This fix only affects native function calling mode. Default mode was unaffected as it executes tools before the LLM in a single pass without recursion.
  • The solution maintains backward compatibility - tools without __original_function__ fall back to normal execution.

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/18375 **Author:** [@jmleksan](https://github.com/jmleksan) **Created:** 10/16/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/native-tool-calling-message-updates` --- ### 📝 Commits (3) - [`73dd626`](https://github.com/open-webui/open-webui/commit/73dd626a99fc6b700f02a111c6a23549e5b397f2) Native tool calling message updates - [`9f16eed`](https://github.com/open-webui/open-webui/commit/9f16eedf192dcaa08b98cd57daf7b11759e9ce9c) Refactor awaitable result handling in tools.py - [`91d79e4`](https://github.com/open-webui/open-webui/commit/91d79e4f00d9a508537d86f20a2a819887a00a25) Remove unnecessary blank lines in tools.py ### 📊 Changes **2 files changed** (+54 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+26 -4) 📝 `backend/open_webui/utils/tools.py` (+28 -0) </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. Not targeting the `dev` branch may lead to immediate closure of the PR. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [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. - [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. - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Take this as an opportunity to make screenshots of the feature/fix and include it in the PR description. - [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. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR. - [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? - [x] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry - 🛠️ Fixed native tool calling to support sequential tool calls with shared context, allowing tools to access images and data from previous tool executions in the same conversation. ### Description ## Description **Fixed native tool calling to support sequential tool calls with shared context** In native function calling mode, tools were unable to access conversation history from previous tool calls within the same conversation. This prevented workflows like: 1. User: "Generate an image of a bear" 2. Tool generates image 3. User: "Make the bear's eyes blue" 4. Tool cannot find the previously generated image ❌ This occurred because tool functions were created with frozen `__messages__` parameters using `functools.partial`, which captured only the initial conversation state. Subsequent tool calls in the same conversation continued using the stale frozen parameters instead of the updated message history. **Solution**: Modified the tool calling system to dynamically update context parameters (`__messages__`, `__files__`) on each tool execution in native mode by storing a reference to the original unwrapped function and re-applying parameters with current state. ### Fixed - Fixed native tool calling mode to provide updated `__messages__` and `__files__` parameters to tools on each execution - Tools in native mode can now access data (images, files, etc.) generated by previous tool calls in the same conversation - Enables multi-step workflows where tools build upon each other's outputs (e.g., generate image → edit image) ### Changed - `backend/open_webui/utils/tools.py`: - Modified `get_async_tool_function_and_apply_extra_params()` to store references to original function and initial parameters - Added `get_tool_function_with_updated_params()` helper function to re-call tools with updated context - `backend/open_webui/utils/middleware.py`: - Modified native tool execution path to check for stored original function and re-apply parameters with current `form_data["messages"]` --- ## Additional Information - This fix only affects **native function calling mode**. Default mode was unaffected as it executes tools before the LLM in a single pass without recursion. - The solution maintains backward compatibility - tools without `__original_function__` fall back to normal execution. ### 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-29 23:12:46 -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#47818