Custom Memory
BindAI allows you to build your own memory implementations. While the built-in providers cover many common scenarios, some applications require custom storage, specialized databases, cloud services, or proprietary systems. Custom memory providers make it possible to integrate those systems without modifying agents or workflows.Why Create a Custom Memory?
You may want a custom implementation when:- storing conversations in your own database
- integrating with an existing application
- using a cloud storage service
- encrypting stored conversations
- implementing custom retention rules
- sharing memory across multiple services
Architecture
A custom provider fits into the existing memory architecture.Provider Responsibilities
A memory provider is responsible for managing stored conversation data. Typical responsibilities include:- loading messages
- storing messages
- updating conversations
- clearing memory
- retrieving conversation history
Basic Structure
A simplified provider might look like this:Creating a Memory Instance
Once your provider exists, create a Memory object.Attaching to an Agent
Use the provider exactly like a built-in one.Example: Database Provider
A custom provider could write messages into a relational database.Example: Cloud Storage
Cloud services can also be used.Example: Encrypted Memory
Sensitive applications may encrypt every stored message.Session Management
Most providers organize conversations by session identifier.Performance Considerations
Large deployments should consider:- indexing conversations
- batching writes
- caching recent messages
- asynchronous persistence
- database connection pooling
Error Handling
Providers should gracefully handle failures. Examples include:- unavailable databases
- network interruptions
- authentication failures
- serialization errors
Testing
Before using a provider in production, verify that it correctly:- loads conversations
- stores new messages
- restores previous sessions
- clears memory
- handles concurrent access
- recovers from failures
Best Practices
- Keep the provider focused on storage.
- Separate storage logic from agent logic.
- Support session isolation.
- Handle failures gracefully.
- Avoid blocking operations whenever possible.
- Consider encryption for sensitive information.
- Document retention and deletion policies.
