I start with a read-only tool and a hard limit on the agent loop. I keep the model local and never hand it a general shell, filesystem, or production credential.
Before I start
- A computer supported by Ollama, Python 3, and enough free disk/RAM for the selected model.
- Permission to install software and download model weights; review the model licence.
- The downloadable example uses qwen3:4b. Smaller models trade capability for lower resource use.
Step by step
Install Ollama from its official site
Install the supported Ollama package for your OS. Start the local service if the installer has not started it. Downloading software and weights requires Internet access; subsequent inference in this example uses localhost.
Download and test a local model
Run the commands below. Keep a local model tag and avoid cloud model variants. My first test is a short question with no confidential data.
ollama pull qwen3:4b
ollama run qwen3:4b "Explain what a backup is in one sentence."Create an isolated Python environment
Use the commands for your OS. Then install the Ollama client inside that environment. I keep this lab separate from system Python.
# Windows PowerShell
py -m venv .venv
.\.venv\Scripts\python -m pip install ollama
# Linux / macOS
python3 -m venv .venv
.venv/bin/python -m pip install ollamaDownload the example agent
Save local-agent.py from the downloads below in the same folder. The only available tool returns a fictional service status. It validates the name, refuses unknown tools, and limits tool rounds. It never runs the model’s text as code.
Run a tool request
Use your environment’s Python executable. The result should include a TOOL line followed by a short explanation of the fictional status.
# Windows
.\.venv\Scripts\python local-agent.py "What is the status of the demo portal?"
# Linux / macOS
.venv/bin/python local-agent.py "What is the status of the demo portal?"Understand the loop
The client sends the model a tool schema. The model proposes a call; the Python allowlist decides whether to execute it. The result returns to the model as a tool message. I keep these separate so a model suggestion is never itself authority to act.
Test a refused request
Ask the agent to delete a file or read a secret. The program has no such tool, so no operation can occur. If the model claims that it performed an action, the absence of a TOOL line confirms it did not; improve instructions and keep the capability boundary.
Replace the demo carefully
For a real next step, I add one read-only API function with narrow inputs, least-privilege credentials, a timeout, and a small output. I retain explicit approval before any future write operation. I keep the Ollama service on localhost rather than opening port 11434 to the Internet.
How I check the result
0 of 4 checks completed
Checklist progress stays in this browser. I use it to track checks, not to certify a deployment or compliance.
If something does not work
Connection refused
Start Ollama and confirm its local service is available.
Model missing or too slow
Run ollama list, pull the exact tag, or choose a smaller tool-capable local model and update the example.
No tool call
Try an explicit demo-service question. Small models may answer without a tool; never accept that as a live status result.
My working templates
I allow one fictional status tool, validate its inputs, and cap the loop at three rounds.
Download PY ↓I record expected answers, permission checks, failures, and evidence before release.
Download CSV ↓Official sources I checked
I checked these sources on 13 October 2026. Product screens and legal requirements change; I verify the relevant source before a production rollout or legal decision.