Open-source context engine rebuilds agent prompts from scratch to eliminate context rot
line9779 · reddit · 2026-12-01
A Reddit user open-sourced a "context engine" targeting context rot in long-horizon agent tasks: instead of stuffing everything into the prompt, summarizing history, or fuzzy RAG chunks, all task materials (docs, tool schemas, prompts, memory) live in an immutable SHA-256-hashed store, and a clean working prompt (capped at 24,576 tokens) is rebuilt from scratch every step with no truncation.
How it works:
- OTel hook triggers on step boundaries via spans your agent already emits (LangGraph, LlamaIndex, CrewAI, AutoGen, OpenAI Agents SDK, custom loops) — no agent rewrite.
- Wipe & swap-in: if the previous call pre-predicted this step's needed IDs, they swap in with zero extra LLM calls.
- Select: a selector model (or deterministic policy-only path) reads a lightweight menu of IDs + one-line descriptions (top 25 pre-ranked if >30 items) and outputs strict JSON of needed IDs plus a next-step guess.
- Enforce & fetch: hard policy rules (alwayskeep, neverinclude, phase rules) override the model; items are SHA-256 verified; items over one page (2,048 tokens) load as a ledger line + page 1.
- Assembly & mid-step recall: fixed ordering avoids lost-in-the-middle; dropped items are explicitly named so the agent can fetch exact bytes via fetchhiddencontext(id).
It works with no model at all, any OpenAI-compatible endpoint, or your own selector. The author fine-tuned Qwen3 8B with QLoRA as the selector and shipped the full training pipeline and dataset in the repo.
More from coding & agent
- Open-source App Store Connect CLI hits 7.10.0 with placements home, refunds and idempotent reruns — rudrank · 2026-12-01
- Developer puzzled: computer-use agents apparently blocked from T3 code — aniketmaurya · 2026-12-01
- Anatomy (30k stars): AI-built interactive diagrams, and a smarter way to test them — andrewaltair · 2026-12-01
- Supabase Builder Day hits Seoul Dec 10: 155+ builders, $30K global prizes in 14-city build-off — dshukertjr · 2026-12-01
- Codex Cloud teams 'more productive,' but dev warns of platform lock-in — tekbog · 2026-12-01
- Gemini workflow goes viral: carbon for deep reasoning, neon for coding tasks via Antigravity /swarm — rm_rafailov · 2026-12-01