Memory system of the MFO Server¶
The MFO Server provides a memory system designed as a key-value store, which tasks and AI agents can use to store and retrieve contextual data dynamically. Here’s how it works and how it can be leveraged:
🔑 Memory: Core Concept¶
-
The memory system allows user-scoped data storage. Each memory entry is identified by:
-
user_id
: isolates memory between different users or agents. key
: the unique identifier for a piece of memory.-
value
: any JSON-serializable data. -
Use case: AI agents can save intermediate results, user preferences, session states, or context variables across multiple tasks, making conversations or workflows stateful and adaptive.
🛠️ API & Handlers¶
- POST /api/memory: Set a key-value pair.
- GET /api/memory/\:key: Retrieve the value of a key.
- PUT /api/memory/\:key: Update a value.
- DELETE /api/memory/\:key: Remove a key.
Example: When an AI agent receives a question like “What’s my last order status?”, it can fetch a stored key like "last_order_status"
from memory.
👷 How Tasks & Agents Use It¶
1️⃣ Temporary State: A long-running workflow (e.g., processing a customer complaint) can save its current progress (e.g., "complaint_status": "investigating"
).
2️⃣ Cross-Task Sharing: One task stores data (Set
), and another retrieves it later (Get
). This enables modular task orchestration.
3️⃣ Memory Batching: Agents can process multiple memory operations at once using the BatchProcessor, which allows bulk get/set/delete to optimize performance.
🗂️ Under the Hood¶
-
PostgreSQL-backed memory store:
-
Table:
slop_memory
- Columns:
user_id
,key_name
,value (JSONB)
,expires_at
-
Indexed for fast retrieval and with expiration logic to automatically clean up stale data.
-
In-Memory Option: For testing or fast tasks, there’s an
InMemoryStore
implementation based on Go’ssync.RWMutex
and in-memory maps.
🧠 Practical Scenarios¶
-
Conversation Memory: A chatbot keeps track of recent user inputs to make follow-up replies smarter.
-
Pipeline Tracking: A multi-step job tracks its execution state in memory to resume after a restart.
-
AI Agent Coordination: Two agents working on related tasks (e.g., parsing and summarizing emails) can use memory to share interim results seamlessly.
✅ Benefits¶
Benefit | Why it matters |
---|---|
Scoped per user/agent | Prevents data leakage between users. |
JSONB data type | Supports flexible and rich data structures. |
Batch processing | Optimizes multiple operations in one go. |
Expiration & cleanup | Automatically removes outdated memory entries. |
In summary: The memory system in the MFO framework is like the short-term working memory of the brain: it gives agents and tasks a place to temporarily store knowledge that can be reused to create seamless, context-aware workflows.