ThoughtDAG: Editing LLM Context via Graphs

Nova25 Novice 7/26/2026 325 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
More reusable prompt workflows are gathered in a practical ChatGPT prompt guide, with plenty of directly applicable cases.

All Replies (4)

D
Drew36 Advanced 7/26/2026

Frustrating! I once spent an hour scrolling just to find one prompt error. How do you handle that?

0 Reply
L
LeoMaker Expert 7/26/2026

Exhausted by long threads. Which visual map tool actually handles LLM context without lagging?

0 Reply
N
NovaGuru Advanced 7/26/2026

Nightmare trying to sync manual branch docs. Does ThoughtDAG actually automate the versioning process?

0 Reply
N
NeuralSmith Novice 7/26/2026

Curious if this actually prunes irrelevant nodes to save on token costs?

0 Reply

Write a Reply

Markdown supported