An AI agent is an engineered loop: what broke when I gave a 4B abliterated model 56 tools on an RX 7600

I’ve been building a local-first agentic assistant on an RX 7600 (gfx1102, ROCm 10.1) and
kept hitting the same class of failure: the model would say it called a tool without
calling it. After enough of those, I rebuilt the harness around four ideas and the failure
rate dropped sharply. Sharing the design because the individual pieces aren’t novel but the
combination is what made a small model usable.

The loop

observe → route → decide → act → verify → update

The runtime, not the model, owns the loop. The model only ever answers “which tool, with
what arguments” or “here’s the answer.” Every tool result is wrapped in untrusted-content
markers and re-read as data, never as instruction.

What actually broke, and the four fixes

1. Tool routing narrowed to one irrelevant tool.
The router is a regex filter that picks 3–5 tools out of 56 based on message wording.
“release date” matched the date trigger, so the model got offered only get_current_time
and truthfully replied “I don’t have that tool.” Fix: if the message contains a tool name
verbatim (e.g. “call deep_search”), always include it regardless of other matches.

2. Retry spiral.
A broken search backend returned the same error 20 times in one turn, burning the context
window. Fix: fingerprint (tool, args) and abort the turn after two identical failures with
a message that says “this is a configuration problem, not a retry problem.”

3. Hallucinated tool success.
The model wrote “I sent the email” with no tool call at all. Fix: the audit log is the
source of truth, not the model’s prose — and every write is snapshotted first so it’s
reversible. Confirmation-gated tools never auto-approve.

4. Context truncation mid-task.
Fixed 8K window plus a 40-message history meant long sessions silently lost state. Fix:
compaction at 85% of the window — summarise everything before the current user turn into a
structured block, keep the current turn verbatim, never cut a tool result from its parent
assistant message.

The reading pipeline (the part I’m least sure about)

Search returns snippets, which a small model can’t ground on. So deep_search fetches the
top 3 URLs in parallel, extracts markdown, chunks it, ranks chunks by query terms, then
makes one narrow call per chunk: “return only facts that answer this question, as JSON.”
The main model sees ~1–2 KB of cited bullets instead of ~150 KB of HTML. Everything except
that one call is deterministic Python, so failures are debuggable.

Numbers on the RX 7600

[8 GB VRAM, ROCm 10.1, Q4 quant]

  • 4B slot: [X tok/s] generation, [Y tok/s] prompt
  • 8B slot: [X tok/s] generation — fits at Q4 with 8K context
  • deep_search end-to-end: [~25 s] for 3 pages, 2–3 s for plain web_search
  • 90-case tool-selection suite: 82.2% overall; weakest category was web_fetch at 40% before
    the router rewrite

What I’d want feedback on

  • Is the per-chunk distill call the right granularity, or is page-level summarisation
    cheaper for the same grounding quality?
  • Anyone running this on ROCm with a different gfx target seen different context ceilings?

Code, Modelfiles and the benchmark suite: [github.com/Bhavishya799/quill-cowork]
Committed at [your commit hash]. MIT.

Hello, I’d keep chunk-level grounding but batch it. Rank the chunks, send the top few with IDs in one call per page, and ask for verbatim quotes tagged by ID, so a plain substring check can confirm each one. You get the call count of page-level summaries without losing the check.

The context ceiling mostly follows VRAM, not the gfx target, as your README’s 12 GB and 16 GB settings already assume. On the 7600’s 8 GB, set OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0. Ollama’s FAQ says q8_0 uses about half the memory of f16, so a 16K cache takes about what your 8K one does now. Raise CONTEXT_WINDOW with OLLAMA_NUM_CTX, since compaction has its own 8192 default, and rerun your 90-case suite to make sure tool accuracy holds.

This is incredibly helpful, thank you.

The batching approach for chunk grounding is exactly what I needed. I’m going to refactor the distillation step to send the top-ranked chunks with their IDs in a single call per page, ask for verbatim quotes tagged by ID, and verify them with a substring check. That solves the latency problem without sacrificing the anti-hallucination guarantees.

For the RX 7600, you’re spot on about the VRAM ceiling. I’ve added OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0 to the .env.example. I’m raising OLLAMA_NUM_CTX and CONTEXT_WINDOW to 16384 across the board and will rerun the bench_v3.py suite to ensure the larger context doesn’t degrade tool-selection accuracy. Appreciate the detailed pointers