Skip to content

Build a Local AI Agent With Ollama and Human Approval

Guides
A compact computer and local drive on an oak workbench beside two blank cards and an amber review tray.
AI-generated illustration of a local computer and an approval tray.
Build a local AI agent that can look up stock in a small file and propose a draft. A model in Ollama picks the lookup tool. A Python script checks its choice and asks you before it saves the result.
This local AI agent knows two items in a made-up shop. Ask about item HB-14 and the source file says there are 12 mugs on shelf B2. An agent can find that row and show it to you. If you reject the draft, the app leaves the target file absent and keeps the stock list intact.

Set up the local AI agent

Use Python 3.10 or later and a running Ollama app. The example pins the local tag qwen3:4b. Ollama lists this as a tool-capable model of about 2.5 GB to download. Disk size is only one part of the setup. Check the Ollama GPU guide and our local AI hardware requirements for memory and driver details.
Extract the sample into a writable folder. Set up Ollama with our Ollama guide, then run ollama pull qwen3:4b. Run ollama --version to check the install. Each live run records the server version, installed model tag and digest in its own result file.
The local AI agent needs internet access for the first model download. Inference calls go to 127.0.0.1:11434. The adapter uses that fixed address and checks the local model list before it calls the model. The sample stock list, draft and result logs stay in the project.

Give the model one read tool

Open inventory.json. It holds a stock count and shelf for each item. The adapter sends the prompt and a short tool schema to Ollama's chat API. The only tool it lists is lookup_item. The app checks that the model sent one call with the exact item ID from the prompt. Then it reads the matching row.
Keep the model adapter separate from the part that opens files. The stock file and draft path come from the app. A tool call can ask for an item by ID. It cannot supply a file path, change stock, run a shell command or pick a web address.
The Ollama tool-calling guide shows how a model can ask an app to call a function. A model can choose the wrong tool or miss the user's intent, so the app still checks each call. For a wider list of controls, see how to define agent permissions.

Approve a draft and test the stops

  1. Run python agent.py --prepare-save "Look up stock for HB-14.". Read the item row, target path and digest. Type APPROVE only if they match your intent. Open the saved draft in that run folder.
  2. Run python agent.py "Change stock for HB-14 to 99.". The tool list has no stock change. A model that follows the prompt policy sends no tool call. If it asks to read the row anyway, record the mismatch and check that stock stayed at 12.
  3. Repeat the first command and type REJECT. Check that the result says rejected and that there is no draft file in the new run folder.
The sample's six fixture checks ran on Windows with Python 3.12.14. They saved the approved bytes, blocked the unsupported call, refused the rejected write and left the source intact. Those runs used fixed tool messages. The live Ollama calls above are a separate test you can run with the model installed.
This approval protects one draft file in a single-user demo. A shared agent also needs a way to check who approved the action, a deadline and an account with only the access it needs. Use our agent security guide when you move past sample data. Our Local AI guide covers the wider setup.
loading

Loading