cd /news/artificial-intelligence/making-local-ai-tool-calls-more-reli… · home topics artificial-intelligence article
[ARTICLE · art-106102] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Making Local AI Tool Calls More Reliable

A developer improved the reliability of local AI tool calls in an assistant by adding a recovery step that retries with tool_choice="required" when the model fails to call a required tool. The fix includes buffering the first response to avoid showing ungrounded answers and was tested with regression tests and a local Gemma model.

read1 min views1 publishedAug 21, 2026

Making Local AI Tool Calls More Reliable

While testing our local-first AI assistant, I found an intermittent problem: the model sometimes answered with plain text instead of calling the tool needed to read or update local data.

The original system used tool_choice="auto"

. This normally worked, but it allowed the model to skip a required tool call. A prompt can guide a model, but it cannot guarantee that the model will always follow the tool protocol.

I fixed this by adding a safe recovery step. The first request still uses automatic tool selection, so normal conversation works as before. If an explicit local-data request returns no tool call, the assistant retries once with tool_choice="required"

. The retry happens only before any tool has run, which prevents duplicate database writes.

The assistant also checks whether the recovered tool belongs to the correct read or write group. During streaming, it buffers the first response so an incorrect, ungrounded answer is not shown before recovery completes.

I tested the change with automated regression tests and the running local Gemma model. The live recovery flow was:

auto -> required -> auto

The main lesson was simple: prompts describe expected behavior, but reliable agent systems also need program-level checks around model decisions.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @gemma 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/making-local-ai-tool…] indexed:0 read:1min 2026-08-21 ·