Skip to content

Feature: Track Current Path in Conversation Tree Using Thread #1

@farhoud

Description

@farhoud

🧩 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

  1. New Realm Object: Thread

    class 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?",
        },
      };
    }
  2. Compute Path on Demand

    Use parent links 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;
    }
  3. UI Integration

    • The app will track the currentThread (by ID or object).
    • When the user selects or creates a message, the thread's currentNode is updated.
    • The UI can render the current path linearly using getPathToRoot(currentThread.currentNode).

🧠 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 Thread model in Realm schema

  • Add thread selection and creation logic

  • Track and update currentNode as 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions