Skip to content

MongoDB Persistence for Agent Memory #17

@omeraplak

Description

@omeraplak

1. Overview:

Provide an integration with MongoDB databases (self-hosted or managed like MongoDB Atlas) to enable persistent storage for agent memory, primarily conversational history. Leveraging MongoDB's flexible document model allows developers to store complex, evolving agent interactions efficiently and scale horizontally.

2. Goals:

  • Implement a MemoryStorage adapter specifically for MongoDB.
  • Utilize the official MongoDB Node.js driver (mongodb).
  • Allow configuration of MongoDB connection details (connection string).
  • Map the conversational memory structure (AgentHistoryEntry, messages, steps) to MongoDB collections and documents.
  • Support efficient CRUD operations using MongoDB's query language.
  • Provide guidance on indexing strategies for common query patterns (e.g., retrieving history by conversationId).
  • (Optional) Explore using MongoDB Atlas Vector Search for storing and querying vector embeddings if integrated with Chunking & Embedding support.

3. Proposed Architecture & Components:

  • MongoMemoryStorage: A class implementing the MemoryStorage interface. This class will:
    • Use the official mongodb Node.js driver.
    • Manage database connections.
    • Translate memory operations into MongoDB operations (e.g., insertOne, findOne, find, updateOne, deleteOne).
    • Handle the mapping between voltagent memory objects and MongoDB documents.
  • MemoryManager Integration: Modify MemoryManager to accept and use the MongoMemoryStorage adapter.
  • Configuration: Extend agent or global configuration to include the MongoDB connection string and potentially database/collection names.
  • Schema Guidance: While MongoDB is schema-flexible, document the recommended document structure and indexing strategies for optimal performance.

4. Affected Core Modules:

  • MemoryManager: Needs to support the new MongoMemoryStorage adapter.
  • Agent Options / Configuration: Needs to accommodate MongoDB connection settings.
  • Requires adding the mongodb driver as a dependency (likely optional).

5. Acceptance Criteria (Initial MVP):

  • Users can configure voltagent to use a MongoDB database for storing conversational history via a connection string.
  • Agent conversations (input, output, basic metadata) are successfully saved as documents in a specified MongoDB collection.
  • Conversation history can be retrieved from MongoDB based on conversationId.
  • Documentation provides basic setup instructions, connection string format, and recommended indexes.
  • The integration uses the official mongodb driver.

6. Potential Challenges & Considerations:

  • Managing connections efficiently.
  • Designing appropriate indexes for performant queries as data grows.
  • Handling potential schema evolution over time, even with flexibility.
  • Security: Users are responsible for securing their MongoDB instance/Atlas cluster and managing credentials.
  • Cost considerations for managed MongoDB services like Atlas.
  • Error handling for connection issues and database operations.
  • Potentially more complex aggregation queries if advanced data analysis on memory is needed.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions