Context Tree
Why I Built This
Two things pissed me off enough to actually build something.
First one: I'm deep in a conversation with Claude. Good flow going. Then I wonder what would GPT say about this? What about Gemini? So I open a new tab, copy the entire conversation, paste it, ask the same thing. Do it again for the third model. By the time I'm done I have 4 tabs open, I've lost my original thread, and I'm manually comparing outputs like an animal.
There had to be a better way. Just at this point in the conversation, let me see what another model says. Without leaving. Without copying anything. Branch right here, try a different model, come back.
Second one: I was learning neural networks. Going through backpropagation, understanding the chain rule, building intuition slowly. Then I got stuck on one specific derivative and asked about it. One math question.
The entire conversation shifted. Suddenly we're doing calculus. The model forgot we were talking about NNs. My next question about gradient descent got answered in pure math terms with zero ML context. I had to keep reminding it "we're talking about neural networks, not pure math."
That's not a hallucination problem. The conversation just got polluted. One question dragged the whole context in a different direction and now everything coming after is slightly off.
I wanted to ask that math question in a bubble. Get the answer. Close the bubble. Come back to my NN thread like nothing happened.
What Context Tree Is
It's a canvas where your conversation is a tree, not a line.
Every message is a node. If you want to go on a tangent branch off. That branch only knows about the conversation up to the point you branched from. It doesn't know what happened in other branches. It doesn't contaminate your main thread.
When you're done with the tangent, you just go back to your main node and continue. The detour never happened as far as the main conversation is concerned.
And at any node any point in any branch you can say "what would Gemini say here instead of GPT?" Fork it. Compare. Pick the better answer. Move on.
That's it. That's the whole idea.
How I Built It
- Frontend: Next.js + React Flow for the canvas. Nodes, edges, pan, zoom everything lives here visually.
- Backend: FastAPI + LangGraph. LangGraph was the right call because it actually thinks in graphs natively. Conversation state gets checkpointed in PostgreSQL so nothing is lost.
- LLMs: Groq and Gemini hooked up, with the architecture open to add more. Each node can call a different model independently.
The trickiest part of the backend was keeping two separate database connection pools one for LangGraph's internal checkpointer, one for the app's own conversation storage. They have different concurrency needs and sharing a pool breaks things in ways that take forever to debug.
The trickiest part of the frontend was making the context inheritance visually obvious. If you can't see at a glance which parent a node is inheriting from, the whole tool becomes confusing fast.
What I Learned
Mostly I learned that the linear chat interface we've all accepted as normal is actually a pretty bad fit for how people actually think and learn.
We don't think in straight lines. We go on tangents. We compare options. We want to explore without losing where we started.
The chat window never solved that. It just made us work around it manually
new tabs, copy-paste, starting over. Every single time.
Context Tree is my attempt to stop doing that.
What Was Hard
Honestly the hardest part was not the code. It was explaining to people what this even is. "It's like a chat but branching" doesn't land.
You have to show it. The moment someone sees their learning conversation
stay clean while a math tangent lives in its own little bubble
that's when it clicks.
Getting to that moment fast enough in a demo is still the challenge.
Built With
- fastapi
- langgraph
- nextjs
- python
Log in or sign up for Devpost to join the conversation.