Conversational Pipeline
Relevant source files
The following files were used as context for generating this wiki page:
The monGARS Conversational Pipeline is the core system responsible for managing user interactions. It provides a memory-backed conversational engine that processes user input, enriches it with context and research, generates a response using an LLM, and adapts the output to the user's personality. The entire process is designed to be resilient and modular, integrating various components from the cognition core.
This pipeline serves as the primary interface for users, handling everything from initial authentication and request validation to real-time streaming of responses via WebSockets. It leverages a sophisticated memory architecture, curiosity-driven research heuristics, and dynamic response adaptation to create a rich and personalized user experience.
Sources: README.md
High-Level Architecture
The conversational pipeline follows a multi-stage process to handle user requests. A request begins at the API layer, is processed by the core cognition engine, and results in a response that is persisted and sent back to the user.
The following diagram illustrates the high-level data flow through the conversational pipeline.
Sources: README.md
API Entrypoints
The conversational pipeline is exposed through the FastAPI service, which provides both REST and WebSocket endpoints for chat interactions.
Sources: monGARS/api/web_api.py, monGARS/api/AGENTS.md
REST Endpoint
A primary REST endpoint handles synchronous chat requests. It is responsible for initial authentication and passing the request to the core conversational module.
| Property | Description |
|---|---|
| Path | /api/v1/chat/ |
| Method | POST |
| Security | Requires OAuth2 bearer token. |
| Request | ChatRequest Pydantic model. |
| Response | A JSON object containing the AI's reply. |
Sources: monGARS/api/web_api.py
The ChatRequest schema defines the structure for incoming messages:
| Field | Type | Description |
|---|---|---|
conversation_id | str | The unique identifier for the conversation. |
message | str | The user's message text. |
user_id | str | The ID of the user sending the message. |
Sources: monGARS/api/web_api.py
WebSocket Endpoint
For real-time, streaming interactions, the pipeline uses a WebSocket endpoint. Clients must first obtain a temporary ticket to establish a connection. The WebSocketManager handles the connection lifecycle, message broadcasting, and rate limiting.
| Property | Description |
|---|---|
| Path | /ws/chat/{ticket} |
| Security | Requires a valid, signed ticket obtained via a separate auth flow. |
| Behavior | Streams responses back to the client as they are generated. |
Sources: README.md, monGARS/api/web_api.py
API Interaction Sequence
The following diagram shows the sequence of a typical chat interaction.
Sources: README.md, monGARS/api/web_api.py
Core Orchestration
At the heart of the pipeline is the ConversationalModule, which orchestrates the various cognitive services to process a user's message and generate a thoughtful response. This orchestration is a key part of the core-turn scenario defined within the project's architecture.
Sources: monGARS/core/conversation.py, scripts/generate_monGARS_llm_dataset.py:441-465
The orchestration flow within ConversationalModule is as follows:
- Image Handling: If the request includes an image,
_handle_imageis called to generate a caption, which is injected into the prompt. - Curiosity Augmentation:
_augment_with_curiosityqueries theCuriosityEngineto detect knowledge gaps and append missing context. - Query Refinement:
_refine_queryuses theAdvancedReasonerto add structured, neuro-symbolic refinements to the prompt. - LLM Interaction: The enriched prompt is sent to
LLMIntegration.generate_responseto get a raw response from the language model. - Response Adaptation: The
AdaptiveResponseGeneratorandMimicryModuletailor the response to match the user's persona and style. - Persistence:
PersistenceRepository.save_interactionsaves the complete interaction to the database for long-term memory. - Memory Sampling:
EvolutionEngine.record_memory_samplestores curated snippets from the conversation for future model training and self-improvement cycles.
This flow is visualized in the diagram below.
Dynamic Response Generation
A key feature of the conversational pipeline is its ability to adapt responses dynamically. The AdaptiveResponseGenerator is the central component for this functionality. It analyzes the conversation and adjusts the AI's persona and response style to better align with the user. This helps create a more natural and engaging conversational experience. This component is explicitly designed to be injected into orchestrators to tailor the final output.
Sources: monGARS/core/dynamic_response.py, monGARS/core/AGENTS.md
Conclusion
The monGARS Conversational Pipeline is a comprehensive system that seamlessly integrates API handling, core cognitive processing, and persistence. By orchestrating services for memory, curiosity, reasoning, and dynamic adaptation, it transforms simple user input into context-rich, personalized interactions. Its modular design and clear separation of concerns make it a robust and extensible foundation for the entire monGARS application.
Sources: README.md, monGARS/core/conversation.py