mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 03:18:23 -05:00
[GH-ISSUE #17860] issue: Bug: RAG Web Search fails with "cannot access local variable 'tool'" #18421
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?
Originally created by @alexandrsuk on GitHub (Sep 28, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/17860
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.6.31
Ollama Version (if applicable)
ollama version is 0.12.3
Operating System
Windows 11 PRO, Docker Deskop v4.46.0, Ubuntu 20.04.6 LTS
Browser (if applicable)
Chrome v140.0.7339.186
Confirmation
README.md.Expected Behavior
After the AI prepares the tool call (e.g., browser.search), the Open WebUI backend should successfully execute the HTTP request to the configured web search tool (SearXNG).
The AI should then receive the search results from the tool and use them to formulate a factual, helpful answer to the user's question, without displaying an error message.
Actual Behavior
The AI correctly identifies the need for a web search and successfully prepares the tool call JSON, as seen in the UI (e.g., Spouštím browser.search... with the correct parameters).
However, the process then fails. The UI first displays a generic message "An error occurred while searching the web," immediately followed by the specific Python backend error: cannot access local variable 'tool' where it is not associated with a value.
The actual HTTP request to the configured SearXNG URL is never sent. The failure happens internally within the Open WebUI backend before the tool is dispatched.
Steps to Reproduce
Rozumím, tato část je nejdůležitější. Zde je podrobný návod krok za krokem, který můžete zkopírovat. Je napsaný v angličtině a obsahuje minimální docker-compose.yml, aby to mohli vývojáři snadno a rychle otestovat.
Steps to Reproduce
Prepare the environment: Create a directory with the following three files:
docker-compose.yml:
YAML
services:
ollama:
container_name: ollama
image: ollama/ollama:latest
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama_models:/root/.ollama
open-webui:
image: ghcr.io/open-webui/open-webui:latest
container_name: open-webui
restart: unless-stopped
ports:
- "8080:8080"
depends_on:
- ollama
- caddy
- searxng
environment:
- 'OLLAMA_BASE_URL=http://ollama:11434'
- 'WEBUI_SECRET_KEY=secret_key_for_testing'
- RAG_WEB_SEARCH=true
- RAG_WEB_SEARCH_ENGINE=searxng
- RAG_SEARXNG_API_URL=http://caddy:80/
caddy:
container_name: caddy
image: caddy:2-alpine
restart: unless-stopped
ports:
- "8087:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
searxng:
image: searxng/searxng:latest
container_name: searxng
restart: unless-stopped
volumes:
- ./searxng:/etc/searxng:rw
depends_on:
- caddy
volumes:
ollama_models: {}
open-webui: {}
Caddyfile:
Fragment kódu
:80 {
reverse_proxy searxng:8080
}
searxng/settings.yml: (Nezapomeňte vytvořit podadresář searxng a v něm tento soubor)
YAML
server:
secret_key: "a_very_random_secret_key_for_testing"
use_forwarded_for: true
search:
formats:
- html
- json
Start the services: In the directory containing the files, run the command:
Bash
docker-compose up -d --build
Set up Open WebUI:
Open your browser to http://localhost:8080.
Create an admin account.
Pull a model if necessary (e.g., from Ollama library, or use a model like gpt-oss:20b).
Start a new chat.
Trigger the Bug:
Ask a question that requires a web search, for example:
What is the current weather in Prague?
Observe the Error:
The AI will respond with "An error occurred while searching the web" followed by the Python error cannot access local variable 'tool' where it is not associated with a value.
Logs & Screenshots
I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError.
Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error.
Samozřejmě. Tato část je pro vývojáře klíčová, protože jim poskytne konkrétní důkazy o chybě.
Zde je text, který můžete zkopírovat a vložit. Přesně popisuje, jaké materiály přikládáte.
Logs and Screenshots
I am providing a screenshot of the user interface right after the error occurs. It shows the AI's attempt to use the tool and the resulting UnboundLocalError.
Additionally, I am providing the relevant logs from the open-webui container, which show the full traceback for the cannot access local variable 'tool' where it is not associated with a value error.
Screenshot of the UI:

Relevant logs from the open-webui container:
log-open-webui-001.txt
Additional Information
Jasně, zde je text, který můžete zkopírovat a vložit do sekce "Additional Information". Stručně a jasně shrnuje kontext, který pomůže vývojářům rychleji pochopit problém.
Additional Information
The self-hosted SearXNG instance is fully functional and has been tested independently. It works correctly when accessed directly via its URL (http://localhost:8087). The logs for the searxng container show a successful startup and do not indicate any errors when receiving requests.
The error cannot access local variable 'tool' appears to be happening entirely within the Open WebUI backend. Based on the logs and the UI feedback, the failure occurs after the AI has decided which tool to use and has prepared the parameters, but before the actual HTTP request is dispatched to the searxng service via Caddy.
This suggests the issue is not related to network connectivity or the SearXNG configuration itself, but rather an internal bug in the tool-dispatching logic within Open WebUI, likely related to the RAG web search implementation.
@tjbck commented on GitHub (Sep 28, 2025):
@alexandrsuk could you confirm if this is still the case with our latest dev branch?
@alexandrsuk commented on GitHub (Sep 29, 2025):
Yes this is happening to me on the latest Open Webui 0.6.31.
@tjbck commented on GitHub (Sep 29, 2025):
requests.exceptions.InvalidURL: Failed to parse: http://caddy:80searchWe're unable to reproduce your issue.