This guide provides a hands-on approach to creating and deploying tools in Open WebUI. It complements the Open WebUI Tool System Analysis.
1. Creating Local Python Tools¶
Local tools are Python scripts that Open WebUI loads dynamically. The system uses your type hints and docstrings to tell the LLM how to use the tool.
The “Hello World” Template¶
Create a Python file (e.g., my_tool.py). The simplest tool is just a function.
from pydantic import BaseModel, Field
from typing import Optional
class Tools:
def say_hello(self, name: str) -> str:
"""
Greets the user by name.
:param name: The name of the person to greet.
:return: A friendly greeting string.
"""
return f"Hello, {name}! I am an Open WebUI tool."Critical Requirements for Local Tools¶
A. The Docstring Format (reST)¶
Open WebUI requires reStructuredText (reST) format for parameter descriptions. If you omit the :param tag, the LLM will not receive a description for that argument.
Correct:
"""
Search for a user by ID.
:param user_id: The unique UUID of the user.
:return: User profile data.
"""Incorrect:
"""
Search for a user by ID.
Args:
user_id: The unique UUID of the user.
"""B. Type Hinting¶
Always use explicit type hints (e.g., str, int, float, bool, list[str]). These are converted directly into the JSON schema provided to the LLM.
2. Advanced Tool Configuration (Valves)¶
Valves allow you to add configuration settings to your tools that can be modified via the Web UI without changing the code.
Global Valves (Admin Settings)¶
Use a Valves class for settings that apply to everyone.
from pydantic import BaseModel, Field
class Tools:
class Valves(BaseModel):
api_key: str = Field(default="", description="API Key for the external service")
timeout: int = Field(default=30, description="Request timeout in seconds")
def get_data(self, query: str) -> str:
"""
Fetch data from an API.
:param query: The search query.
"""
# Access global valves via self.valves
key = self.valves.api_key
return f"Fetching {query} using key {key[:4]}..."User Valves (Per-User Settings)¶
Use a UserValves class for settings that each user can configure individually.
class Tools:
class UserValves(BaseModel):
preferred_language: str = Field(default="English", description="Language for tool responses")
def translate(self, text: str) -> str:
"""
Translates text to the user's preferred language.
:param text: Text to translate.
"""
# Access user-specific valves via self.user_valves (injected by the system)
lang = getattr(self, 'user_valves', None).preferred_language if hasattr(self, 'user_valves') else "English"
return f"Translating '{text}' to {lang}..."3. Creating External Tool Servers (OpenAPI)¶
If you have an existing API, you don’t need to write Python code for Open WebUI. You just need an OpenAPI Specification (JSON/YAML).
Requirements for the API¶
OpenAPI 3.0+: Your server must expose a
/openapi.jsonor/swagger.jsonendpoint.operationId: Every endpoint must have a uniqueoperationId. Open WebUI uses this ID as the tool’s name.Descriptions: Provide clear
summaryanddescriptionfields in your OpenAPI spec so the LLM knows when to call the endpoint.
Connection Setup¶
Go to Workspace Tools Add Tool Server.
Enter the URL of your server.
Select the Auth Type (e.g., Bearer Token).
Open WebUI will fetch the spec and automatically register all
operationIds as available tools.
4. Managing Tool Scope (Visibility)¶
Tools in Open WebUI are not “globally” active. You must explicitly define which contexts have access to which tools.
A. Model-Level Scope¶
You can bind tools to a specific model. This is the most common way to ensure a specialized model has the right capabilities.
Go to Workspace Models.
Edit your target model.
In the Tools section, select the tools you want to attach.
Effect: Only chats started with this model will have these tools available.
B. Folder/Context-Level Scope¶
You can bind tools to a specific folder or collection.
Navigate to your Workspace Collections/Folders.
Assign tools to the folder context.
Effect: Any model used within that folder’s context will automatically gain access to these tools, regardless of the model’s own default tool set.
5. Using Tools in the Interface¶
Once a tool is created or connected:
Configure Settings:
Go to Workspace Tools.
Click the gear icon next to your tool to edit the Valves.
Invoke:
Start a chat with the assigned model (or within the assigned folder).
Ask a question that triggers the tool (e.g., “Search for user 123”).
The model will generate a tool call, the backend will execute it, and the result will be fed back into the conversation.