An offline coding agent on llama3.1:8b and where it breaks
- Models & engines
- Model: llama3.1:8b via Ollama
RAG: tree-sitter AST chunking, local hashing-based embeddings, Chroma - Key gotcha
- An 8B model hits a clear ceiling when it has to chain a diagnosis with a state-changing tool call
What they built
Kaan Özgür wanted a local coding agent covering semantic retrieval over a codebase, an agent loop that edits files and runs checks, a safety layer against destructive actions, and a repeatable benchmark. He used no paid APIs: everything runs offline against llama3.1:8b via Ollama on a consumer CPU.
The retrieval side, with AST-level chunking via tree-sitter, local hashing-based embeddings and Chroma, worked reliably. The agent loop did not: the model sometimes narrated a fake tool conversation as plain text instead of calling tools.
He then built an isolated benchmark suite with five tasks, each run in a fresh temporary directory, tracking pass rate, latency and step count.
Setup
- Model: llama3.1:8b via Ollama
- Consumer CPU, fully offline, no paid APIs
- RAG: tree-sitter AST chunking, local hashing-based embeddings, Chroma
How it works
- Testing raw HTTP requests against Ollama's /api/chat showed that rebuilding the tool-call turn dropped the call id and index fields
- Passing response.raw["message"] back intact fixed multi-turn tool calling
- An output validator catches narrated JSON blobs or stated-but-unmade tool calls and triggers a retry
Results & numbers
- Safety refusal and single-file docstring edits: 100% pass rate
- Grounded code explanation and multi-step refactoring: 33% pass rate
- One-line bug fix: 0% pass rate; the model found the bug every time but never called write_file
Gotchas
- An 8B model hits a clear ceiling when it has to chain a diagnosis with a state-changing tool call
- The grader needs scrutiny too: a test looking for a variable named PI failed a valid run that used math.pi
“every failure mode surfaced immediately and reproducibly”— Kaan Özgür
Do it yourself
- Pull llama3.1:8b in Ollama
- Index your codebase with AST-level chunks and a local vector store
- Keep Ollama's assistant tool-call message intact between turns
- Add a validator that retries when the model narrates a tool call instead of making it
- Run a small task suite in fresh temp directories, several times per configuration
Similar setups
A CPU-only PDF question-answering API with Ollama, Qwen2.5 1.5B and ChromaDB
A developer who wanted to keep documents inside the private network built a small RAG app on a PC with no active GPU: PDFs are indexed into ChromaDB and a local FastAPI endpoint answers questions with Qwen2.5 1.5B on Ollama.
Gist: an offline exam-prep partner that mines past papers with Ollama
A student built Gist so a friend could study from lecture PDFs and three-plus years of past exam papers without uploading copyrighted course material anywhere; parsing, embeddings, search and the LLM all run on the laptop with Wi-Fi off.
Finding why a local Ollama RAG bot ignored its instructions: silent num_ctx truncation
A developer's local RAG bot on llama3.1:8b skipped citations and guessed answers because Ollama silently cut prompts to a 2048-token window; in a 500-question test 312 prompts were truncated, and setting num_ctx to 8192 lifted grounded accuracy from 61% to 84%.
Breaking re-ranker ties with Gemma's own token probabilities on a Mac mini
A developer testing a local retrieval setup on an M4 Mac mini fixed tied re-ranker scores from gemma3:12b by reading the model's digit probabilities from Ollama, getting the right article first on 11 of 12 questions.