IndependentOpen source
Context Tree
Routes every message in a long AI conversation before it’s sent: stay on topic, switch back to an earlier one, or fork a new branch. Jev, an evaluation model, makes the call in milliseconds.
- Role
- Sole builder: SDK, router, demo and benchmarks.
- Problem
- Long chats resend the whole history every turn, and topics bleed into each other.
- Outcome
- Open source, with a deterministic local demo, tests and benchmarks that run without API keys.
Context
A long conversation with a model is really several conversations: pricing, then architecture, then back to pricing. Sending the full transcript every turn costs tokens and lets one topic leak into another.
It grew out of Outline AI, where sections made the structure visible but every reply still sent the full history. Context Tree keeps the sections and sends only the active path.
Context Tree keeps the conversation as a tree of topics and decides, before each message is sent, which part of the tree it belongs to.
What I built
- A TypeScript SDK that builds the working context from the root checkpoint, the active path, its checkpoint and recent turns.
- A router that makes one bounded decision per message — STAY, SWITCH or FORK — with probabilities, using the Jev evaluation model or a local reference scorer.
- A React demo that routes a draft while you type, without committing anything until you send.
- Tests and benchmarks that run deterministically without API keys.
How it works
Route first, then generate
Decisions
01
Routing decides where, the model decides what
The router only chooses a place in the tree. Keeping it separate from response generation makes it small, testable and cheap to run on every message.
02
Candidates first, then one decision
Locality, recency and semantic similarity narrow the tree to a handful of nodes before the router decides, so the decision stays bounded as the tree grows.
03
Works offline by default
Without keys, the demo, tests and benchmarks run on a deterministic local backend. Anyone can clone it and see the same result.
What this page shows
My own project. Everything here is in the public repository.