Summary
Add built-in context management and memory optimization features to reduce token costs and prevent context bloat.
Problem
Long-running agents accumulate context through:
- Growing memory files (daily logs, learnings, decisions)
- Skill descriptions loaded every turn
- Cron job payloads and histories
- Session transcripts
This leads to:
- Increased token costs ($5-10/day for active agents)
- Context window pressure requiring frequent compaction
- Manual maintenance burden on users
Proposed Features
1. Automatic Memory Archiving
- Auto-archive memory files older than N days (configurable)
- Compress archived files (gzip)
- Keep archived content searchable via
memory_search
- Config:
agents.defaults.memory.archiveAfterDays: 7
2. Context Budget Monitoring
- Track context file sizes
- Alert when approaching threshold
- Dashboard widget showing context usage breakdown
- Config:
agents.defaults.context.maxKb: 50
3. Smart Memory Summarization
- Auto-summarize old daily logs before archiving
- Extract key learnings/decisions to dedicated files
- Preserve important context while reducing size
4. Lazy Skill Loading
- Load skill descriptions on-demand instead of every turn
- Cache recently used skills
- Reduce base context by 3-5KB
5. Memory Maintenance Hooks
onMemoryMaintenance hook for custom logic
- Built-in weekly maintenance cron
- Dry-run mode for testing
Example Config
{
"agents": {
"defaults": {
"memory": {
"archiveAfterDays": 7,
"compressArchive": true,
"autoSummarize": true,
"maxActiveKb": 50
},
"context": {
"lazySkillLoad": true,
"budgetAlertKb": 40
}
}
}
}
Benefits
- Reduces daily token costs 20-40%
- Prevents runaway context growth
- Zero manual maintenance
- Preserves all learnings (archived, not deleted)
Workaround
Currently using a bash script for weekly maintenance - happy to share if helpful for implementation reference.
Submitted by @sachah via Alex agent
Summary
Add built-in context management and memory optimization features to reduce token costs and prevent context bloat.
Problem
Long-running agents accumulate context through:
This leads to:
Proposed Features
1. Automatic Memory Archiving
memory_searchagents.defaults.memory.archiveAfterDays: 72. Context Budget Monitoring
agents.defaults.context.maxKb: 503. Smart Memory Summarization
4. Lazy Skill Loading
5. Memory Maintenance Hooks
onMemoryMaintenancehook for custom logicExample Config
{ "agents": { "defaults": { "memory": { "archiveAfterDays": 7, "compressArchive": true, "autoSummarize": true, "maxActiveKb": 50 }, "context": { "lazySkillLoad": true, "budgetAlertKb": 40 } } } }Benefits
Workaround
Currently using a bash script for weekly maintenance - happy to share if helpful for implementation reference.
Submitted by @sachah via Alex agent