Problem
When context compaction occurs, important information like API keys and credentials can be lost if not explicitly saved to files.
Example scenario:
- Agent registers on an external service and receives API key
- Agent continues conversation without saving key to file
- Context gets compacted
- API key is lost forever
Current Behavior
- OpenClaw sends "Pre-compaction memory flush" message before compaction
- By this point, the summary may already be generated and details lost
- Agent has to manually remember to save important data during session
Suggested Improvements
1. Structured pre-compaction hook
Allow agents to define what should always be captured before compaction:
compaction:
always_save:
- api_keys
- credentials
- project_state
2. Earlier warning
Give agents more notice before compaction, not just at the moment it happens.
3. Automatic credential detection
Detect patterns like api_key, token, secret in conversation and prompt agent to save them.
4. Session state file
Automatically maintain a session state file that persists key context across compactions.
Workarounds Currently Used
- Save credentials immediately to
/data/.config/
- Symlink
~/.config/ to /data/.config/ for persistence
- Flush memory during session at trigger points (decisions, completions)
- Maintain project state files in
memory/projects/
Environment
- OpenClaw: latest
- Channel: Telegram
Happy to discuss further or help implement!
Problem
When context compaction occurs, important information like API keys and credentials can be lost if not explicitly saved to files.
Example scenario:
Current Behavior
Suggested Improvements
1. Structured pre-compaction hook
Allow agents to define what should always be captured before compaction:
2. Earlier warning
Give agents more notice before compaction, not just at the moment it happens.
3. Automatic credential detection
Detect patterns like
api_key,token,secretin conversation and prompt agent to save them.4. Session state file
Automatically maintain a session state file that persists key context across compactions.
Workarounds Currently Used
/data/.config/~/.config/to/data/.config/for persistencememory/projects/Environment
Happy to discuss further or help implement!