Menu

Ollama Tool Calling: Put a Budget on the Agent Loop
📰

Ollama Tool Calling: Put a Budget on the Agent Loop

DEV Community: node·Pavel Espitia·about 12 hours ago
#zE5VF0Nb
#devtonodejs#devto#dev#tool#const
Reading 0:00
15s threshold

The application executes the tool requests a model returns. If the model keeps asking for another lookup, your loop decides whether to keep spending time and memory or stop with the evidence already collected.

Ollama’s chat API can return several tool calls in one response. Count both rounds and individual calls, limit each tool result, and reject missing or unknown tool names. The loop below also gives Ollama fetches a shared deadline; tools need cancellation or execution limits appropriate to their own work.

A bounded local example

Prerequisites: Node.js 20 or newer, Ollama running on localhost, and a model that supports tool calling already available in Ollama. This example exposes only a bounded multiplication function. It makes no external requests besides the local Ollama API.

Save as bounded-agent.mjs and run OLLAMA_MODEL=your-model node bounded-agent.mjs (PowerShell: $env:OLLAMA_MODEL='your-model'; node .\bounded-agent.mjs ).

const model = process . env . OLLAMA_MODEL ; if ( !…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.