-
Notifications
You must be signed in to change notification settings - Fork 0
Description
🧩 Feature: Track Current Path in Conversation Tree Using Thread
Description:
We need a mechanism to track the current conversation path (from root to latest node) within a tree-structured LLM chat system stored in Realm. This enables:
- Reconstructing the conversation history
- Providing accurate context to the LLM
- Supporting branching and resuming from any prior message
Each message (MessageNode) is stored in Realm with parent and children links. To enable per-user or per-agent navigation and editing, we introduce a Thread object that holds the current node in the path.
✅ Proposal
-
New Realm Object:
Threadclass Thread extends Realm.Object<Thread> { _id!: BSON.ObjectId; name!: string; // optional label like "Poetic Rewrite" currentNode?: MessageNode; static schema = { name: "Thread", primaryKey: "_id", properties: { _id: "objectId", name: "string", currentNode: "MessageNode?", }, }; }
-
Compute Path on Demand
Use
parentlinks to dynamically reconstruct the active path for the thread:function getPathToRoot(node: MessageNode): MessageNode[] { const path: MessageNode[] = []; let current: MessageNode | undefined = node; while (current) { path.unshift(current); current = current.parent; } return path; }
-
UI Integration
- The app will track the
currentThread(by ID or object). - When the user selects or creates a message, the thread's
currentNodeis updated. - The UI can render the current path linearly using
getPathToRoot(currentThread.currentNode).
- The app will track the
🧠 Benefits
- Enables context-aware LLM calls using the correct message history
- Allows users to branch and explore alternate replies
- Supports features like breadcrumbs, step navigation, and history comparison
🛠 Tasks
-
Define
Threadmodel in Realm schema -
Add thread selection and creation logic
-
Track and update
currentNodeas the user interacts -
Implement
getPathToRoot()logic -
Use the current path for:
- LLM context construction
- UI display (chat thread, breadcrumbs)
- Exporting paths
Let me know if you'd like this saved as a .md file or added to a real GitHub repo.