Feedback

Chat Icon

Local AI Engineering with Ollama

Run, understand, customize, fine-tune, and build agentic apps on your own hardware

Building Advanced Agents: Function-Calling
90%

Pass 8: Let the Model Call Python Functions ("Tools") to Fetch Live Data

So far the assistant has been working with a fixed body of knowledge: whatever was in the model's weights at training time, plus whatever the user has told it across sessions and mem0 has stored. That works fine for conversational questions, but it falls apart the moment the user asks about something the model can't possibly know: today's weather, the current air quality, a stock price, a row in a database, the contents of a file on disk. The model has no way to find out. It can guess (and small models often will, confidently and wrongly), or it can refuse, but it can't go look.

Function calling closes that gap. Instead of constraining the assistant to what's in its head, we give it a set of Python functions it can decide to call, with arguments it picks based on the conversation. When the user asks what's the temperature in Tokyo?, the model recognizes that one of our functions can answer that, emits a structured tool call with location="Tokyo", our code runs the function and hands the result back, and the model turns that result into a natural reply. The model never sees real-time weather data in its training data directly; it just knows the shape of the tool and how to invoke it.

This pattern is what people mean when they talk about "agents". An agent is a model with tools, a loop that lets it call those tools, and the ability to call several in sequence before producing a final answer. We've actually been using create_agent since "pass 5" to enable summarization middleware, but with an empty tools=[] list. Now we'll add real tools and let the model use them:

agent = create_agent(
    model=llm,    
    middleware=[
        SummarizationMiddleware(
            model

Local AI Engineering with Ollama

Run, understand, customize, fine-tune, and build agentic apps on your own hardware

Enroll now to unlock all content and receive all future updates for free.