Beyond Token Optimization: Exploring Deterministic Context Engineering for AI Coding Agents
What if the performance of a coding agent depends not only on the capabilities of its language model, but also on how much unnecessary work the surrounding system asks it to do?
Over the past few months, I have been developing Qzzar-Knowledge (QK), an independent research and engineering project exploring that question.
Rather than making the model larger or modifying its weights, I have been investigating how repository knowledge, persistent context and deterministic implementation controls can change the conditions under which an existing model operates.
This article discusses three lessons from that work, including results that did not go as expected.
1. Context is an engineering problem, not just a token budget
A coding agent frequently has to discover files, reconstruct dependencies, recover previously established information and determine which changes are permissible. Some of that work requires interpretation. Some of it can be supported by conventional computation.
QK is an external layer implemented in Rust and Python. It combines structural repository knowledge, persistent memory, context selection and implementation verification. The language model remains responsible for interpreting the request and proposing a solution; external mechanisms help assemble relevant evidence and enforce supported constraints.
This is not fine-tuning. The underlying model is unchanged.
A conceptual distinction I find useful is between the intelligence of the model and the operational competence of the complete system. Improving the latter does not necessarily require increasing the former.
2. An experiment with open-ended coding tasks
I distinguish between targeted tasks, where the implementation target is known, and open-ended tasks, where the agent receives a symptom without an explicit file or function hint.
The latter is particularly interesting because successful implementation depends on successful discovery.
In the QK v1.3.2 campaign (revision 53847b98), the evaluation used 12 tasks across three repositories:
- Werkzeug (Python)
- ai-memory (Rust)
- Traccar (Java)
Each task was repeated three times per arm, yielding 72 attempts. Both arms used Codex with the reported model identifier gpt-6-luna and low reasoning effort.
| Metric | Standalone Codex | Codex + QK |
|---|---|---|
| First-pass valid approvals | 23/36 | 18/36 |
| Final valid approvals | 23/36 | 23/36 |
| Total tokens | 9,939,743 | 2,108,914 |
| Cached input | 9,231,488 | 1,336,704 |
| Uncached input | 661,591 | 754,284 |
| Output tokens | 46,664 | 17,926 |
| Final out-of-scope outcomes | 11 | 0 |
| Summed session time | 2,288.25 s | 2,788.07 s |
The QK arm consumed 78.78% fewer total tokens and reached the same final approval count, but used 14.01% more uncached input and took 21.84% longer in summed session time.
One-time project preparation was accounted for separately. The comparison includes discovery and repair activity in the QK token totals. Equal final counts are not evidence of statistical equivalence, and the difference in first-pass approvals matters.
3. Fewer tokens do not translate directly into lower costs
Total token consumption can be misleading when cached input, uncached input and output are priced differently.
A useful way to explore this is to normalize the cost of an uncached input token to 1 and vary the relative weights of the other categories:
def weighted_cost(uncached, cached, output, alpha, beta): return uncached + alpha * cached + beta * output baseline = (661_591, 9_231_488, 46_664) qk = (754_284, 1_336_704, 17_926) for alpha, beta in [(0.25, 4), (0.1, 8)]: before = weighted_cost(*baseline, alpha, beta) after = weighted_cost(*qk, alpha, beta) print(f"Reduction: {100 * (1 - after / before):.2f}%") The first weighting is the one used in the benchmark protocol. It gives a reduction of approximately 63.24%. The second gives approximately 47.33%.
Neither represents an actual provider invoice. Local indexing, orchestration, maintenance and hardware costs also matter. The point is that an efficiency claim should expose its token composition rather than rely entirely on a headline percentage.
4. Deterministic verification is not infallible
An earlier experiment taught me an uncomfortable lesson about acceptance criteria.
In a separate 384-attempt campaign, a QK patch increased valid deliveries from 85 to 107 out of 128 attempts. At the same time, applied proposals that subsequently failed external evaluation increased from 11 to 15.
A more permissive gate can increase valid deliveries while admitting more invalid ones. Conversely, an excessively restrictive gate can reject correct implementations.
A decision procedure can be deterministic and still be wrong. Reproducibility of a decision is not evidence that its criteria are sound.
In the latest Tier 2 campaign, the QK arm recorded 11 intermediate out-of-scope proposals despite having zero final out-of-scope outcomes. That distinction is essential: the model can still propose invalid actions. The external system attempts to govern which proposals are accepted.
5. Aggregate results can hide regressions
The latest campaign reached 23/36 final approvals in both arms, but the distribution across repositories was different:
| Repository | Standalone | QK |
|---|---|---|
| Werkzeug | 12/12 | 8/12 |
| ai-memory | 4/12 | 7/12 |
| Traccar | 7/12 | 8/12 |
The architecture helped in two repositories and hurt in another.
Across the three official Tier 2 campaigns, the standalone arm recorded 65/108 approvals and QK recorded 74/108. These are repeated evaluations of the same 12 tasks, not 108 independent problems per arm. They also span different QK revisions, so the pooled figures do not measure one fixed implementation.
This is why I prefer publishing per-task failures and campaign-specific results alongside aggregate numbers.
6. Evidence and limitations
I have started publishing benchmark artifacts in a separate public repository:
The current Tier 2 evidence package contains 216 official attempts and 16 transition canary attempts, with 231 complete metering receipts out of 232 recorded cells. It includes frozen task specifications, campaign manifests, individual results, reviewed receipts, failure diagnostics, original reports and checksums.
The archived data can be inspected and its arithmetic checked:
git clone https://github.com/lols8000/Qzzar-Knowledge-Benchmarks.git cd Qzzar-Knowledge-Benchmarks/benchmarks/tier2 sha256sum -c SHA256SUMS python3 verificar_relatorios.py . The engine remains proprietary. Raw execution traces, candidate patches and some harness sources are not distributed. These are internal, author-reported experiments, not independent replications. The checks establish consistency of the archived records, not authenticity of every execution. The published task oracles also mean these cases should no longer be used as blind holdouts.
7. The research question I want to investigate next
The most interesting question to me is not whether I can reduce token consumption by another few percentage points.
It is whether an external knowledge and verification infrastructure can reduce the minimum model capability required to solve a particular task.
Can a smaller model with better structural context and stronger external verification approach the performance of a larger standalone model? Under what conditions does such an architecture help, and where does it introduce new failure modes?
A meaningful evaluation would require component ablations, fresh held-out repositories and tasks, matched model and reasoning budgets, explicit repair accounting, independent evaluators and a complete accounting of infrastructure overhead.
I am developing QK independently alongside my regular technology work. I would appreciate technical criticism, suggestions for evaluation protocols and references to related research, particularly from people working on static analysis, knowledge representation, agent architectures and empirical software engineering.
The goal is to understand how to distribute computation between probabilistic models and deterministic systems more effectively, not to claim that either one can replace the other.
AI disclosure: This English article was drafted by ChatGPT from the project author's supplied experimental reports, prior discussion and public benchmark records. The project and experiments are the author's work; this is not an independently replicated study.

