Chat Module

Conversation management, session handling, and message history

Overview

The Chat module manages conversations between users and agents. It handles session lifecycle, message history, thread management, and conversation state. Every interaction passes through the Chat module, making it one of the most fundamental components of the platform.

Session Management

Each conversation exists within a session that tracks participants, message history, and metadata. Sessions can be long-running, persisting across multiple user visits, or ephemeral for one-off interactions. The Chat module manages session creation, resumption, and archival, storing session data in MySQL.

Message History

The Chat module maintains the full message history for each session and is responsible for constructing the message array sent to the LLM during the Reasoning step. It handles context window management by selecting the most relevant messages when the full history exceeds the LLM's context limit. Recent messages are always included, with older messages selected based on relevance scoring.

Thread Management

Conversations can be organized into threads for multi-topic discussions. The Chat module tracks thread boundaries and ensures that context building pulls from the appropriate thread. This prevents context pollution when an agent is handling multiple concurrent topics with the same user.

WebSocket Integration

Real-time messaging is delivered through WebSocket connections managed by the FastAPI backend. The Chat module handles message serialization, delivery confirmation, typing indicators, and connection state. Messages are persisted before delivery to prevent data loss on connection interruptions.

NarraNexus - Multi-Agent Framework