Memory Architecture
Memory Types
1. Short-Term Memory
Purpose: Store recent step observations within the current action. Implementation:MemoryManager.ts (lines 186-210)
Characteristics:
- Lives in-memory and on-disk (
memory.json) - Default limit: 20 entries (configurable via
memoryContextLimit) - Cleaned up after action completion
- Includes tool observations, user messages, system injections
2. Episodic Memory
Purpose: LLM-generated summaries of conversation batches for durable thread context. Implementation:MemoryManager.ts (lines 273-332)
Characteristics:
- Created via automatic consolidation when short-term memory exceeds threshold (default: 30 entries)
- Grouped by platform + contact (e.g.,
telegram:123456789) - Batch size: 12 exchanges (configurable via
interactionBatchSize) - Summarized with structured JSON:
{summary, facts, pending, tone, preferences, confidence}
3. Long-Term Memory
Purpose: Persistent markdown files for durable facts, learning, and reflections. Implementation: File-backed storage in~/.orcbot/
Files:
| File | Purpose | Updated By |
|---|---|---|
JOURNAL.md | Agent’s self-reflections and activity logs | update_journal skill |
LEARNING.md | Structured knowledge on various topics | update_learning skill |
USER.md | User preferences and profile | update_user_profile skill |
WORLD.md | Environment state and governance | update_world skill |
MEMORY.md | General long-term facts | memory_write skill |
4. Vector Memory (Semantic Search)
Purpose: Semantic embeddings for full-history similarity search. Implementation:VectorMemory.ts (lines 8-940)
Characteristics:
- Uses
text-embedding-3-small(OpenAI) ortext-embedding-004(Google) - Stores embeddings in file-backed JSON (
vector_memory.json) - Background indexing every 5 minutes
- Cosine similarity search
- Max entries: 10,000 (configurable via
vectorMemoryMaxEntries)
5. Daily Memory Logs
Purpose: Append-only markdown logs organized by date. Implementation:DailyMemory.ts (lines 38-742)
Characteristics:
- Files stored in
~/.orcbot/daily_memory/YYYY-MM-DD.md - Categorized entries (System, Research, Communication, Consolidation)
- Automatically appended for important events
- Read into extended context for awareness
Memory Lifecycle
1. Creation
2. Consolidation
3. Retrieval
4. Cleanup
Memory Limits & Configuration
Memory Deduplication
OrcBot prevents storing duplicate events within a 5-minute window:Session Scoping
OrcBot supports three session scoping modes (configurable viasessionScope):
1. main (Single Global Session)
All conversations share the same memory pool.
2. per-peer (Cross-Platform Identity)
Memories are scoped to a user across all channels.
3. per-channel-peer (Default)
Memories are scoped to a user on a specific channel.
Thread Context Retrieval
For follow-up messages, OrcBot retrieves thread context (recent + relevant messages from the same contact):Contact Profiles
OrcBot maintains per-contact profiles in~/.orcbot/profiles/:
Memory Flush System
Inspired by OpenClaw, OrcBot proactively reminds the LLM to write important memories before consolidation:Performance Considerations
Token costs:- Recent context: ~1,000-3,000 tokens
- Episodic: ~500-1,500 tokens
- Long-term files: ~500-2,000 tokens
- Vector search: ~500-2,000 tokens
- Total memory context per step: ~2,500-8,500 tokens
- Use
memoryContextLimitto reduce recent entries - Enable step compaction to trim history
- Set
memoryContentMaxLengthto 1500 (prevents bloat from large tool outputs) - Use
isLeanMode: truefor simple tasks (skips semantic/episodic retrieval)
- Semantic search: ~200-500ms (depends on embedding API)
- Consolidation: ~2-5 seconds (LLM call)
- Daily log read: ~50-100ms
- Parallel retrieval: ~300-600ms (all async ops run concurrently)
Debugging Memory Issues
1. Inspect raw memory:Further Reading
- Agent Loop — How memories are used during reasoning
- Decision Pipeline — Context assembly and prompt engineering
- Architecture — Overall system design