Six weeks of building an offline coding agent from scratch, debugging tool-calling failures on an 8B model, and measuring where reliability actually drops off.

The setup

I wanted to build a local coding agent that covers the full stack of modern AI developer tools: semantic retrieval over a codebase, an agent loop capable of editing files and running checks, a safety layer to prevent destructive actions, and — the part most prototypes skip — a repeatable benchmark to measure whether any of it actually works.
To keep the constraints clear, I used no paid APIs. Everything runs offline against llama3.1:8b via Ollama on a consumer CPU. Working with a small local model turned out to be the most useful part of the project: instead of a frontier model silently compensating for weak prompts or fragile tool schemas, every failure mode surfaced immediately and reproducibly.

What "agentic" actually costs you

The RAG pipeline (AST-level chunking with tree-sitter, local hashing-based embeddings, and Chroma) came together quickly and worked reliably. The agent loop was a different story.

When I first wired up tool-calling, the model would periodically stop emitting actual function calls and instead narrate an entire fake tool conversation as plain text:

{"name": "search_codebase", "parameters": {"query": "embedding calculation"}} Assuming the output is: [{"name": "calc.py", "location": "/path/to/calc.py"}] I will now read the contents of calc.py... 

At first, this looked like a bug in my harness. Isolating the issue with raw HTTP requests directly against Ollama's /api/chat endpoint revealed two root causes:

  1. Broken multi-turn state: Rebuilding the assistant's tool-call turn in a simplified dictionary dropped the original call id and index fields from Ollama's response, causing the model to fall back into plain-text narration on turn two. Passing response.raw["message"] back intact fixed multi-turn continuity.
  2. Unfulfilled intent: Even with intact message history, the model sometimes stated "I will call read_file now" and stopped without invoking the tool. I added a lightweight output validator (_looks_like_fake_tool_call) to catch narrated JSON blobs or unfulfilled tool-call intents and trigger a retry.

Build the eval before you trust the demo

Running an agent a few times and cherry-picking the successful runs proves nothing. Instead, I built an isolated benchmark suite (codesage eval) with five tasks—each executed in fresh temporary directories—tracking pass rate, latency, and step count.
Across 3 repeats per configuration (6 total attempts on the bug-fix task before and after prompt adjustments), the results showed a sharp split by task shape:
• Safety refusal (resist_indirect_deletion) & single-file docstring edits (add_docstring): 100% pass rate.
• Grounded code explanation (explain_login_grounded) & multi-step refactoring (extract_constant): 33% pass rate.
• One-line logic bug fix (fix_subtract_bug): 0% pass rate. In every single attempt, the model correctly identified the bug in its reasoning (+ instead of -) and then terminated without ever calling write_file.
That gap is the core takeaway: agent reliability is heavily dependent on task structure, and an 8B model hits a clear ceiling when required to chain diagnosis with a state-mutating tool call.
Building the benchmark also exposed flaws in my own grading logic. My initial extract_constant test checked for a variable literally named PI and failed a valid run that used math.pi instead. Rewriting the grader to inspect the AST for remaining hardcoded float literals fixed the false negative—a good reminder that evaluation code needs just as much scrutiny as agent code.

What's next

The next step is running this exact five-task suite against a larger hosted model (such as Claude or GPT-4) to quantify how much of that 0% bug-fix gap comes from model capacity versus harness design.
Source code, architecture notes, and full benchmark logs are available on GitHub: https://github.com/KaanOzgurr