Give a local LLM live web search and news with Ollama and Python
A model running on your own machine is private, cheap and fast. It also stops learning the day its training data was frozen. Ask it about this week's news, a library released last month or today's price of anything, and it will guess. The fix is tool calling. You give the model a few functions it is allowed to call, it decides when it needs fresh information, your code runs the function, and the…
Ollama is a locally-run model that offers privacy, cost-effectiveness, and speed. However, the model's knowledge is limited to its training data. To enhance its capabilities, tool calling can be implemented. This involves providing the model with a set of functions it can call when it needs fresh information. Ollama supports this feature for models like Qwen 3, Llama 3.1, and Mistral.
This guide will walk you through creating a research assistant that can perform various tasks using Ollama and Python. The assistant will be able to search the web for facts, documentation, and products, search recent news articles using keywords, number of days, and country, and read full pages when a snippet is insufficient.
To get started, you need Ollama running locally with a model that supports tools. In this guide, we'll use qwen3:8b. Ensure you have Python 3.9 or newer and install two packages: pip install ollama requests. Additionally, you'll need a search API key. The examples in this guide use the NestDaddy API, which provides plain JSON from its own web index and news from 45+ countries.
Before writing the tools as Python functions, set up the necessary environment variables. For instance, set the API key for NestDaddy and specify the Ollama model to use. The guide uses qwen3:8b by default but allows flexibility to use other models.
Next, implement the tools as normal Python functions. The Ollama Python library can automatically convert these functions into tool definitions. The function name, type hints, and docstring are used by the model to understand when to call the tool and how to interpret the results. Include instructions in the docstring for the model, not just a description of the function's purpose.
The guide provides three main tools: web_search, news_search, and read_page. The web_search tool allows the model to search the web for facts, documentation, and products. News_search enables searching recent news articles based on keywords, number of days, and optional country. Lastly, read_page reads the main text of a web page, excluding menus and ads, when a snippet is not sufficient.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.