Free guide Checked November 17, 2026. About 15 minutes to read. Code follows the official Ollama Python examples.
What is an agent, really?
An agent is an AI model plus tools plus a loop. You give it a goal; it decides which tool to use, looks at the result, and keeps going until it is done. The tools are ordinary programs: “get the time”, “search my notes”, “send a draft to me for approval”.
Think of a helpful assistant at a desk. The model is the assistant’s brain. The tools are the phone, the calculator and the filing cabinet. The loop is the habit of checking: “Did that answer the question? If not, what should I do next?”
The three parts, simply
- The model chooses what to do. It must support “tool calling”, which means it can reply with a request like “please run get_time” instead of plain text.
- The tools do the work. Each is a small function with a short description the model can read.
- The loop connects them: ask the model, run any tools it asks for, give it the results, and ask again until it gives a final answer.
Path A: no code
- Download our free OPC Desktop for Windows from Downloads. Pick a model, press Start, chat. It can use your browser and desktop when you allow it.
- Or use Open WebUI’s tools on your home AI brain to add web search and other helpers, switching each one on only when you need it.
Path B: your first agent in about 25 lines of Python
- Decide the one job. Pick a single small task, like “tell me what is on my calendar file today” or “summarise new notes in this folder”. Small jobs succeed; vague jobs wander.
- Get a model that can use tools. Install Ollama and pull a tool-capable model, for example
ollama pull llama3.1. The Ollama library marks which models support tools. - Install Python and the Ollama library. Python 3.10 or newer from python.org, then
pip install ollama.
pip install ollama
ollama pull llama3.1
Save this as agent.py and run python agent.py:
import datetime, ollama
def get_time() -> str:
"""Get the current local date and time."""
return datetime.datetime.now().strftime("%A %B %d, %Y %I:%M %p")
TOOLS = {"get_time": get_time}
messages = [{"role": "user", "content": "What day is it, and what time?"}]
for _ in range(8): # never loop forever
reply = ollama.chat(model="llama3.1", messages=messages, tools=[get_time])
messages.append(reply.message)
if not reply.message.tool_calls: # no tool needed: final answer
print(reply.message.content)
break
for call in reply.message.tool_calls: # run each tool the model asked for
fn = TOOLS.get(call.function.name)
result = fn(**(call.function.arguments or {})) if fn else "Tool not found"
print("tool:", call.function.name, "->", result) # simple log
messages.append({"role": "tool", "content": str(result), "tool_name": call.function.name})
What each part does, line by line
def get_time()is the tool. The text in triple quotes is its description; the model reads it to decide when to use it.TOOLSis a list the program uses to find the right function when the model asks for one by name.messagesis the conversation so far. It starts with your question.for _ in range(8)is the loop, with a safety limit of 8 rounds so it can never run forever.ollama.chat(..., tools=[get_time])sends the conversation and the tools to the model. The Ollama Python library turns your function and its description into a tool the model understands.- If there are no tool calls, the model has its answer, so we print it and stop.
- Otherwise we run each requested tool, print a log line, and add the result to the conversation as a
toolmessage, the same way Ollama’s own example does. Then the loop asks the model again.
Add a second tool
Give your agent a way to read a notes file. Add this function and put it in both TOOLS and the tools=[...] list:
def read_notes() -> str:
"""Read the text of my notes file, notes.txt, in this folder."""
with open("notes.txt", encoding="utf-8") as f:
return f.read()[:4000] # keep it short for small models
Now ask: “What is on my list today, and what time is it?” The model should call both tools, then answer. That is a real agent: it chose two tools, used their results and finished the job. Notice the tool only reads. That is on purpose.
Useful first agents to build
Once the loop works, the only thing that changes from one agent to the next is the tools. Here are a few safe, genuinely useful ideas that only need read-only tools:
- Morning briefing: tools that read today’s date, your to-do file and a calendar file you export. Ask “What should I focus on today?”
- Folder summariser: a tool that lists new files in a folder and one that reads a file. Ask for a one-paragraph summary of each new document.
- Homework helper: a calculator tool and a tool that reads a worksheet. The model explains steps; the calculator does the arithmetic so the numbers are right.
- Recipe planner: a tool that reads your pantry list. Ask what you can cook tonight and what to buy.
Notice the pattern: the model does the thinking and the talking, and the tools do anything that must be exact, like dates, sums or file contents. That split is what makes agents reliable.
Five safety rules we follow
- Start read-only. Tools that look things up come before tools that change things.
- Ask before acting. Anything that sends, buys, deletes or posts waits for your “yes”.
- Keep secrets out of prompts. Store passwords and keys in your system’s keychain, never in the chat.
- Log every action so you can see what it did and undo it.
- Prove it worked. “Done” means you can see the result, not that the AI said so.
Where to go from here
- Test with easy questions first. Ask things you already know the answer to. Watch which tools it calls and with what inputs.
- Add safety before adding power. Read-only tools first. Anything that sends, buys, deletes or posts must wait for a human “yes”.
- Log everything. Print or save every tool call and result so you can see what happened and undo it.
- Grow slowly. Add one tool at a time, test it alone, then together with the others.
Troubleshooting
| What you see | Most likely cause | What to do |
|---|---|---|
| The model never calls the tool | The model does not support tools, or the description is vague | Use a tool-capable model (for example llama3.1). Write a one-sentence docstring that says exactly when to use the tool. |
KeyError for a tool name | The model asked for a tool that does not exist | Keep the TOOLS dictionary names identical to the function names. Reply “tool not found” instead of crashing. |
| Wrong types, like “3012” instead of 42 | Tool arguments arrive as text | Convert inputs inside the tool, as Ollama’s own example does with int(a) + int(b). |
| The loop runs forever | The model keeps asking for tools | Add a step limit, for example stop after 8 rounds, and print what happened. |
Connection refused | Ollama is not running | Start Ollama (open the app, or run ollama serve) and try again. |
| Answers are slow | Model too big for your graphics card | Run ollama ps; aim for 100% GPU, or use a smaller model. |
Questions people ask
What is the difference between a chatbot and an agent?
A chatbot only writes text. An agent can also use tools you give it, such as reading a file or checking the time, and it keeps going step by step until the job is done.
Do I need to code?
No for Path A: our free OPC Desktop and Open WebUI’s tools work without code. Yes, a little Python, for Path B, where you build one yourself and understand exactly what it does.
Which model should I use?
One that supports tool calling and fits your graphics card. The Ollama library labels tool-capable models. Bigger models choose tools more reliably; small ones are fine for simple tools.
Is it safe to let an agent use my computer?
Only with rules. Start with tools that only read. Make anything that changes, sends, buys or deletes ask you first. Never put passwords in prompts.
Why did my agent call the wrong tool or make up an answer?
Usually the tool description is unclear, or the model is too small. Make each description one plain sentence about exactly what the tool does, and check results instead of trusting the words “done”.
Can my agent use the internet?
Only if you give it a tool that does. Every internet tool is a door out of your home, so add it on purpose and log what it sends.
Can I run this on my home AI brain?
Yes. Point the script at your server by setting the Ollama host, or run the script on the server itself.
How is this different from big AI agent products?
The idea is the same: a model, tools and a loop. Products add many tools, memory and polish. Building a small one yourself is the best way to understand, and judge, the big ones.
Sources
- Ollama Python library: tool calling example (tools=[function], role tool, tool_name)
- Ollama model library (look for the tools label)
- Ollama FAQ (ollama ps)
- Python downloads
Want one home for all your AI helpers? ABUZ8 HQ keeps your agents, files and conversations in one place. Sign-up is optional; every guide here stays free.
Get startedAll guides