History & Organization
Relevant source files
The following files were used as context for generating this wiki page:
The OpenChat system implements a structured approach to managing conversation history, background task execution, and user personalization. The architecture ensures that both real-time user interactions and autonomous background agent runs are organized, tracked, and accessible through a unified interface. This is achieved through a combination of a real-time database (Convex), specialized UI components for chat management, and an execution logging system for automated tasks.
At its core, the system organizes data into chronological groups (e.g., Today, Yesterday, Last 7 Days) and supports advanced organizational features such as chat pinning, branching, and full-text search. Background agents further extend this by maintaining their own execution logs and history, which are integrated into the primary chat interface for visibility and continuity.
Sources: README.md:52-60, CLAUDE.md:88-93
Chat History Management
Chat management in OpenChat is designed for high portability and smart organization. Conversations are automatically grouped by time periods and can be pinned to remain at the top of the user's list. A key architectural feature is "Chat Branching," which allows users to create alternative conversation paths from any specific assistant message, effectively creating a tree-like structure of historical context.
Data Storage and Retrieval
All chat history is stored in the Convex real-time database, ensuring that updates are synchronized across all connected clients instantly. The system stores account information, chat messages, conversation history, and user preferences.
The diagram shows the relationship between the UI and the Convex database, highlighting the organizational components applied to the data.
Sources: README.md:52-60, CLAUDE.md:79-82, src/routes/security.tsx:112-117
Background Agent Execution History
Background agents are a significant part of the "History & Organization" module. These agents run scheduled tasks (one-time, daily, or weekly) and maintain detailed logs of their operations. Every time a scheduled agent executes, a unique execution history record is created to track its performance and outcomes.
Execution Flow and Logging
When a task is triggered, the system generates a unique executionId and records the start time. A new, dedicated chat is often created for the task execution to keep its history isolated and organized.
The sequence diagram illustrates the lifecycle of a scheduled task execution and how it interacts with the history and chat systems.
History Retention
To maintain performance and organization, the system includes a cleanup mechanism for old executions. By default, it retains the last 30 execution records for any given task.
Sources: convex/scheduled_ai.ts:25-83, convex/scheduled_ai.ts:405-410, README.md:38-41
Personalization and System Context
The organization of AI responses is heavily influenced by the "System Prompt" and "Personas" configurations. These provide the historical and behavioral context for the AI, ensuring consistency across different chat sessions.
Personas Configuration
The system defines several distinct personas, each with a specific "personality" organized into a standard structure.
| Persona ID | Label | Characteristic | Icon |
|---|---|---|---|
companion | Companion | Thoughtful friend, casual phrasing | ChatTeardropText |
researcher | Researcher | NUance, intellectual curiosity | MagnifyingGlass |
teacher | Teacher | Clear explanations, relatable examples | ChalkboardTeacher |
software-engineer | Software Engineer | Pragmatic, values clean code | Code |
creative-writer | Creative Writer | Distinct voice, narrative rhythm | PenNib |
Sources: src/lib/prompt_config.ts:31-77
User-Specific Traits
Users can organize their own AI experience by defining personal traits and context in the settings. This data is appended to the system prompt to maintain historical continuity of the user's identity across all chats.
| Field | Description | Constraint |
|---|---|---|
preferredName | What the AI calls the user | Max 50 chars |
occupation | User's profession for context | Max 100 chars |
traits | AI behavioral traits (e.g., witty, concise) | Max 50 items |
about | Additional context or preferences | Max 3000 chars |
Sources: src/routes/settings/customization.tsx:186-267, src/lib/prompt_config.ts:373-394
Security and Data Portability
Organization includes how data is protected and moved. OpenChat provides features for data portability, allowing users to export and import their chat history.
- Data Deletion: Users have the autonomy to delete their chat history at any time. Account deletion removes all associated data, including history and preferences.
- Isolation: User data is isolated, ensuring that users can only access their own conversation history.
- Encryption: Sensitive organizational data, such as API keys provided for model access, is encrypted using AES-GCM 256-bit encryption.
Sources: src/routes/security.tsx:32-40, src/routes/security.tsx:119-124, README.md:60
Conclusion
The History & Organization system in OpenChat provides a robust framework for both manual and autonomous interactions. By leveraging Convex for real-time synchronization, implementing chronological grouping, and maintaining detailed execution logs for background agents, the project ensures that users can manage complex, long-term AI workflows with clarity and security. This structure supports the project's goal of being a truly personal AI assistant that grows with the user's digital life.