ThoughtDAG: Editing LLM Context via Graphs

Nova25 Novice 2h ago Updated Jul 27, 2026 289 views 3 likes 1 min read

Standard chat interfaces treat conversations as linear transcripts, which is a nightmare once you start branching. You end up with one path containing the actual gold and another that's just a dead-end hypothesis, but the model often keeps dragging that irrelevant noise into the current context window.

I built a prototype called ThoughtDAG to make this state actually editable.

Context as a Graph

Instead of a scrollable list, every Q&A exchange is a node on an infinite canvas. The edges aren't just for show—they define the prompt. When you trigger a request from a specific node, ThoughtDAG crawls the incoming graph, collects the ancestors, and sequences them into the message history sent to the LLM.

If you delete an edge and hit regenerate, that entire branch is pruned from the model's memory instantly.

The Logic Behind the DAG

I avoided making this an "autonomous agent" because I want manual control over the reasoning chain. Using a Directed Acyclic Graph (DAG) allows for three specific manual operations:

  • Branching: Testing an alternative angle without polluting the main path.
  • Merging: Pulling insights from two different research branches into one new prompt.
  • Pruning: Cutting out the "hallucination" or the detour before asking a follow-up.

It's essentially a visual, human-controlled representation of the model's short-term memory.

Technical Stack & Local Setup

The tool is local-first, using IndexedDB for storage so there's no need for accounts. It supports Ollama for local inference or any OpenAI-compatible API.

The build is pretty straightforward for anyone wanting to dive into the code:

  • React / TypeScript
  • React Flow (for the canvas)
  • Zustand (state management)
  • Vercel AI SDK
# Project is MIT licensed
# Repo: https://github.com/chenxiachan/thoughtdag

I'm currently weighing whether manual context control is actually a productivity win or if most people would prefer delegating this to RAG or agents. But for complex prompt engineering, having a "kill switch" for specific context branches feels way more reliable.

AIshowdevopensourceAI ProgrammingAI Coding

All Replies (4)

D
Drew36 Advanced 10h ago
been there. spent an hour scrolling back just to find where i messed up a prompt.
0 Reply
L
LeoMaker Expert 10h ago
the struggle is real. a visual map of the conversation would save so much time tbh
0 Reply
N
NovaGuru Advanced 10h ago
I've tried using docs to track branches manually, but it's a total pain to sync.
0 Reply
N
NeuralSmith Novice 10h ago
Would be interesting to see how this handles pruning irrelevant nodes to save tokens.
0 Reply

Write a Reply

Markdown supported