Memory System
Moxxy agents have a sophisticated memory system that enables them to remember conversations, learn from interactions, and maintain context over time.
Overview
┌─────────────────────────────────────────────────────┐
│ Memory System │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Short-Term │ │ Long-Term │ │
│ │ Memory (STM) │ │ Memory (LTM) │ │
│ │ │ │ │ │
│ │ • Recent turns │ │ • Facts │ │
│ │ • Session ctx │ │ • Embeddings │ │
│ │ • current.md │ │ • Semantic │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Swarm │ │ Scheduled │ │
│ │ Memory │ │ Jobs │ │
│ │ │ │ │ │
│ │ • Shared facts │ │ • Cron tasks │ │
│ │ • Agent comms │ │ • Heartbeats │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────┘Short-Term Memory (STM)
STM holds the current conversation context - recent messages and the active session.
Characteristics
- Fast access - In-memory + SQLite cache
- Session-scoped - Tied to current conversation
- Limited window - Last N turns (configurable)
- Human-readable - Exported to
current.md
Storage
| Component | Location | Purpose |
|---|---|---|
| SQLite table | memory.db | Persistent store |
| current.md | Agent workspace | Human-readable snapshot |
| In-memory cache | Runtime | Fast access |
Session Management
Each conversation has a unique session ID:
Session: sess_abc123
├── User: Hello
├── Agent: Hi! How can I help?
├── User: What's the weather?
└── Agent: Let me check...Start New Session
In TUI:
/newVia API:
POST /api/agents/default/session/newcurrent.md
A human-readable snapshot of STM:
# Agent Short-Term Memory Context
## Session: sess_abc123
## Last Updated: 2024-01-15 10:30:00
### Recent Messages
**User:** What files are in my Downloads folder?
**Agent:** I found 15 files in your Downloads folder:
- report.pdf
- image.png
- ...
**User:** Can you open the PDF?
**Agent:** I'll open report.pdf for you.
<invoke name="host_shell">["open ~/Downloads/report.pdf"]</invoke>Long-Term Memory (LTM)
LTM stores persistent knowledge that survives across sessions.
Characteristics
- Durable - Persists indefinitely
- Semantic search - Vector embeddings for similarity
- Fact extraction - Important information saved
- Cross-session - Available in future conversations
Vector Embeddings
LTM uses sqlite-vec for semantic search:
-- Memory entries with embeddings
CREATE TABLE long_term_memory (
id INTEGER PRIMARY KEY,
content TEXT,
embedding BLOB, -- Vector embedding
created_at DATETIME
);
-- Semantic search
SELECT content
FROM long_term_memory
ORDER BY vector_distance(embedding, ?)
LIMIT 5;How It Works
- Agent responds - Generates response to user
- Important facts extracted - Key information identified
- Embeddings created - Facts converted to vectors
- Stored in LTM - Persisted with embeddings
Semantic Retrieval
When the agent needs context:
User: "What did we discuss about the API last week?"
System:
1. Embed query: "API discussion last week"
2. Search LTM for similar vectors
3. Return top-k relevant memories
4. Inject into context
Agent: Based on our previous discussion, we talked about...Swarm Memory
Shared knowledge base across all agents.
Characteristics
- Global - All agents can read/write
- Announcements - Agents share discoveries
- Collaborative - Learn from each other
How Agents Share
Agents announce facts using special tags:
[ANNOUNCE] The production API is experiencing 503 errorsOther agents can then access this knowledge:
User (to Agent B): Is there anything I should know about?
Agent B (retrieves from swarm): The production API is currently
experiencing issues. You may want to check on that.Storage
Swarm memory is stored in a shared database:
~/.moxxy/swarm.dbUse Cases
- Shared alerts - System issues, important events
- Knowledge sharing - Learned facts, discoveries
- Coordination - Task status, progress updates
Scheduled Jobs
Memory system also stores scheduled tasks:
CREATE TABLE scheduled_jobs (
name TEXT PRIMARY KEY,
cron TEXT NOT NULL, -- Cron expression
prompt TEXT NOT NULL, -- What to execute
source TEXT NOT NULL, -- Who created it
created_at DATETIME
);Managing Schedules
Create:
Schedule a daily summary at 9amList:
Show me all scheduled jobsRemove:
Cancel the daily summary jobMemory API
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/agents/:name/memory/stm | Get STM |
| GET | /api/agents/:name/memory/ltm | Search LTM |
| POST | /api/agents/:name/memory/ltm | Add to LTM |
| DELETE | /api/agents/:name/memory | Clear memory |
| POST | /api/agents/:name/session/new | New session |
Example: Search LTM
curl -X POST http://localhost:17890/api/agents/default/memory/ltm/search \
-H "Content-Type: application/json" \
-d '{"query": "API discussion", "limit": 5}'Example: Clear Memory
curl -X DELETE http://localhost:17890/api/agents/default/memoryMemory Configuration
STM Window Size
Control how many turns to keep:
moxxy run --agent default --prompt "Store '20' in vault as stm_window_size"LTM Embedding Model
Configure the embedding model:
moxxy run --agent default --prompt "Store 'text-embedding-3-small' in vault as embedding_model"Memory Cleanup
Automatically prune old memories:
moxxy run --agent default --prompt "Store '30' in vault as ltm_retention_days"Best Practices
What to Store
Good for LTM:
- Important facts
- User preferences
- Project context
- Recurring patterns
Not for LTM:
- Temporary calculations
- Verbatim conversations
- Ephemeral data
Session Management
- New session for unrelated topics
- Continue for related follow-ups
- Clear when starting fresh
Memory Hygiene
Periodically review and clean:
# View current memory
cat ~/.moxxy/agents/default/current.md
# Reset if needed
rm ~/.moxxy/agents/default/memory.db
moxxy agent restart defaultTroubleshooting
Memory Not Persisting
Check database permissions:
bashls -la ~/.moxxy/agents/default/memory.dbVerify SQLite integrity:
bashsqlite3 ~/.moxxy/agents/default/memory.db "PRAGMA integrity_check;"
Semantic Search Not Working
Verify sqlite-vec extension:
bashmoxxy doctorCheck embedding configuration:
bashmoxxy run --agent default --prompt "What embedding model am I using?"
Memory Growing Too Large
Check database size:
bashdu -h ~/.moxxy/agents/default/memory.dbVacuum to reclaim space:
bashsqlite3 ~/.moxxy/agents/default/memory.db "VACUUM;"Set retention policy in vault