Skip to content

Feature Request: Built-in Context & Memory Management #9142

@sachah

Description

@sachah

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions