Mhonn YbañezSRE, DevOps, AI Engineer
 Projects
Read the full page

LangGraph Detective: Does a Smaller Context Help?

When
November 2026
Kind
Side project

An AI detective solves mystery cases by reading clue files, and the project tests four ways of managing what goes into its prompt. After about 340 runs on five models, the simplest method, one prompt, was the most accurate and the cheapest.

Problem

Long agent runs fill the context window, so the usual fix is a memory harness that swaps what was read for notes. It is not clear that this helps, and it adds code, calls and cost, so the question was worth measuring instead of assuming.

Highlights

  1. Four methods compared on the same cases: a memory harness, a context-budget harness, a plain chat that keeps everything, and one prompt with the whole case.
  2. Six cases from 3.4K to 13.9K tokens, each blind-solved by a separate agent before use, with distractor documents checked so they cannot reveal the culprit alone.
  3. Ran on local Qwen 3.5 9B with Ollama, then 332 cloud runs across four OpenRouter models, each pinned to one provider. Total cloud spend was $4.22.
  4. One prompt matched or beat the memory harness on accuracy for every model, at 7x to 20x lower cost. The harness cut the peak prompt by 40 to 50% but read 7x to 18x more tokens in total.
  5. Rules the model cannot break live in code: file reads are limited to the case folder, so the agent can never open the solution, and a cost cap and reply caps stop runaway runs.
  6. Findings are written up honestly, including what was not done: the tight-budget sweep failed because the last compression step was never built, so that conclusion is an inference, not a measurement.
  7. 94 tests with fake models, and a LangGraph concept map that points each idea to the line where it lives.
7x to 20x cheaperOne prompt matched or beat the memory harness on accuracy for every model tested.

Stack

Architecture

The harness graph: load memory, investigate, read a clue, compress it into notes, then accuse and score.
FIG. A The harness graph: load memory, investigate, read a clue, compress it into notes, then accuse and score.

Screens

What I learned