Memory System
Give your agents persistent memory using markdown-based storage.
Quick Start
What is Memory?
Memory is a simple, file-based storage system that lets your agents:
Persistent Storage
Save information across sessions
Key-Value Retrieval
Retrieve information by specific keys
Regex Search
Search across all memories with patterns
Markdown Format
Organize knowledge in human-readable format
Storage Strategy
Memories start in a single memory.md file. When the file exceeds 3000 lines, it automatically splits into a directory structure with separate .md files per memory key.
Installation
Memory is included in ConnectOnion:
Basic Usage
Creating a Memory Instance
Adding Memory to an Agent
Now your agent has access to 4 memory methods:
- write_memory(key, content)- Save or update information
- read_memory(key)- Retrieve information
- list_memories()- Show all stored memories
- search_memory(pattern)- Search with regex
Memory Methods
write_memory
Save information to memory:
read_memory
Retrieve saved information:
list_memories
Show all stored memories:
search_memory
Search across all memories using regex:
Examples
Example 1: Customer Notes
Example 2: Project Tracker
Example 3: Research Assistant
Example 4: Multi-Agent Shared Memory
Pass the same Memory instance to multiple agents so they share knowledge:
Advanced Patterns
Memory with Different Tools
Memory works alongside any other tools:
Custom File Organization
Use separate Memory files for different purposes:
Regex Search Patterns
Powerful pattern matching across all stored memories:
File Format
Single File (Default)
Memories start in a single memory.md file using section headers:
Works at TechCorp
Prefers phone calls
Auto-Split to Directory
When memory.md exceeds 3000 lines, it automatically migrates:
Best Practices
1. Use Descriptive Keys
2. Structure Your Content
Use markdown formatting for better organization:
3. Keep Memories Updated
Periodically prune or refresh stale notes:
4. Search Before Creating
Avoid duplicates by checking first:
5. Use Consistent Naming
Pick a key prefix convention and stick to it:
Limitations
Storage
All memories are loaded during search. For very large stores (>1000 files or >100MB), consider a database backend.
Concurrency
File-based storage isn't optimized for high concurrency. Multiple agents writing to the same memory may race.
Search Performance
Regex search scans linearly. For large-scale search, consider Elasticsearch or similar.
Troubleshooting
“Memory not found”
Keys are sanitized — list all stored memories to see actual keys:
“Invalid key name”
Use only alphanumeric characters, hyphens, and underscores:
Memory file not created
The file is created on first write, not on construction:
Customizing
Need to modify Memory's behavior? Copy the source into your project and import from there:
ConnectOnion