For years, the debate between local and cloud-based Large Language Models (LLMs) often centered on raw performance. However, the landscape has shifted dramatically with the rise of sophisticated local inference engines. One of the most powerful features of modern LLMs is function calling, or tool use. This capability allows a model to interact with external APIs, execute code, or query databases, effectively transforming it from a passive text generator into an active AI agent.
Traditionally, this feature was exclusive to proprietary, closed-source models accessible via API keys. But with the integration of Ollama and Open WebUI, you can now enable robust function calling capabilities in a fully local, private, and cost-effective environment. In this guide, we will explore how to configure and utilize function calling in Open WebUI to build powerful local agent workflows.
Why Function Calling Matters for Local AI
Function calling breaks down the monolithic nature of LLM responses. Instead of guessing facts or hallucinating outcomes, the model can pause its generation process, output a structured JSON request to use a specific tool, and wait for the result before continuing its conversation. This is crucial for applications requiring real-time data, such as weather updates, stock prices, or accessing your personal knowledge base.
By combining Ollama’s efficient local hosting with Open WebUI’s intuitive interface, you retain full control over your data while gaining the dynamic capabilities of agentic AI. This setup is particularly valuable for developers who want to experiment with agent logic without incurring cloud API costs or compromising data privacy.
Prerequisites: Setting Up the Stack
Before enabling function calling, ensure your environment is correctly configured:
- Ollama: Installed and running. Ensure you have pulled a model that supports tools, such as
llama3.1,qwen2.5, orgpt-oss-20b. - Open WebUI: Installed and connected to your Ollama instance via the configuration settings (typically pointing to
http://localhost:11434).
Configuring Tools in Open WebUI
Open WebUI allows you to define custom functions that can be exposed to the LLM. These functions are essentially Python endpoints or pre-defined scripts that the UI can trigger based on the model’s intent.
Navigate to Admin Panel > Functions in Open WebUI. Here, you can create a new function. Let’s create a simple weather lookup function as a practical example.
# Example Python Function in Open WebUI
def get_weather(city: str) -> str:
"""
Get the current weather for a given city.
Args:
city (str): The name of the city.
Returns:
str: A string describing the current weather.
"""
# Simulated API call or local data lookup
if city == "New York":
return "Sunny, 72°F"
elif city == "London":
return "Rainy, 55°F"
else:
return "Data not available."
Once the function is defined, you must associate it with a specific model or make it available globally. In the function configuration, ensure that the type is set to tool and that the description is clear and concise, as the LLM relies on these descriptions to decide when to invoke the tool.
Testing the Agent Workflow
To test the integration, start a new chat session in Open WebUI. Select a model that supports function calling, such as qwen2.5-coder or a larger version of llama3.1.
Issue a prompt that clearly requires external data:
"What is the current weather in New York? Please use the available tools to find out."
Here is what happens under the hood:
- Intent Recognition: The LLM analyzes the prompt and identifies that it needs to call a function to retrieve weather data.
- Tool Invocation: The model outputs a structured JSON object requesting the
get_weatherfunction with the parameter{"city": "New York"}. - Execution: Open WebUI intercepts this request, executes the Python function locally, and receives the return value:
"Sunny, 72°F". - Response Generation: The LLM receives the result and generates a natural language response:
"The current weather in New York is Sunny and 72°F."
In the Open WebUI interface, you will often see a visual indicator or a log entry showing that a tool was executed. This transparency is vital for debugging and trust.
Advanced Agent Workflows: Chaining and Reasoning
Simple function calls are the building block, but true agent workflows involve chaining and reasoning. You can create complex functions that interact with multiple data sources. For example, you could create a function that:
- Searches a local SQLite database for user preferences.
- Queries a news API for relevant headlines.
- Synthesizes the information into a personalized briefing.
To enhance this, you can enable RAG (Retrieval-Augmented Generation) alongside function calling. By uploading documents to Open WebUI’s vector store, your local agent can both search its knowledge base and execute external tools. This hybrid approach allows for highly contextual and accurate responses.
Best Practices and Performance Tips
- Model Selection: Not all local models are created equal. Smaller models (7B-8B parameters) may struggle with complex tool syntax. For reliable function calling, models with 14B+ parameters (like
qwen2.5-14borllama3.1-70b) generally perform better. If hardware is limited, use quantized versions (Q4_K_M) for a balance of speed and accuracy. - Clear Descriptions: The LLM decides to call a tool based on the function’s documentation string. Be explicit about input types, expected outputs, and when the function should be used.
- Error Handling: Your Python functions should be robust. If an external API fails, return a clear error message rather than crashing, allowing the LLM to acknowledge the failure and suggest alternatives.
Conclusion
Enabling function calling in Open WebUI with Ollama is a significant step toward democratizing AI agent development. It empowers developers to build sophisticated, interactive, and private AI assistants that can interact with the real world—all from your local hardware.
As local models continue to improve in their reasoning and instruction-following capabilities, the gap between local and cloud-based agentic AI will only narrow. By mastering these local tool-use patterns, you position yourself at the forefront of privacy-first AI development, capable of building complex workflows without the latency, cost, or privacy concerns associated with cloud APIs.
Start small with simple lookup functions, then scale up to complex, multi-step agent workflows. The local AI stack is ready for you to build with.