0xjohmsmith

context-management

"Programmatically measure and trim memory file sizes without LLM calls. Use for memory hygiene, context budget management, and enforcing token limits on memory/*.md files."

0xjohmsmith 0 Updated 3mo ago

Resources

1
GitHub

Install

npx skillscat add 0xjohmsmith/openclaw/context-management

Install via the SkillsCat registry.

SKILL.md

Context Management

Quick Reference

All operations via scripts/context_manager.py. Pure string-length estimation (tokens = len(text) / 4).

Default max: 5000 tokens per file.

Check sizes

# Single file
python3 scripts/context_manager.py check memory/TraderMemory.md

# All files in directory
python3 scripts/context_manager.py check-all memory/

Custom limit

python3 scripts/context_manager.py check memory/TraderMemory.md --max-tokens 3000

Memory backup

bash skills/context-management/scripts/backup_memory.sh

Copies full workspace to /home/othmane/tmp/openclaw/memory-backups/<timestamp>/. Auto-prunes backups >7 days. Runs hourly via cron.

MemoryManager Workflow

  1. Run check-all memory/ + individual checks on secret-sauce/ files
  2. For any file over 5000 tokens → read the file, then use an LLM call to condense it
  3. The LLM prompt: "condense this memory file to under 5000 tokens (~20000 chars). preserve all alpha, actionable levels, lessons, and open positions. remove redundancy, stale info, and verbose phrasing."
  4. Write the condensed version back, then check again to verify
  5. Exception: secret-sauce/ files are immutable — flag to dev0xx, never modify.

Memory management is handled by the Auditor. See agents/auditor.md.

Agent Awareness

All agents (Analyst, Quant, Trader) must follow these constraints when writing to memory:

  • Max 5000 tokens (~20000 chars) per memory file.
  • Be terse. Numbers > sentences. Levels > narratives.
  • Replace existing sections, don't append. Kill stale data.