Problem
Long-running agent sessions accumulate too many messages, leading to:
HTTP 400: invalid_request_error: context is too long errors
- Model API failures
- Manual intervention required to clear sessions
- No automatic cleanup mechanism
Current Behavior
- Sessions grow indefinitely
compaction.mode: "safeguard" is too conservative
- No built-in way to reset sessions without deleting files
- Token usage is not visible to users
Impact
This affects:
- Long-running group chats
- Personal assistants with continuous conversation
- Multi-agent deployments with high message volume
Users experience unexpected failures and must manually delete session files.
Proposed Improvements
1. Enhanced Auto-Compaction
{
"agents": {
"defaults": {
"compaction": {
"mode": "auto",
"strategy": "sliding-window",
"maxTokens": 150000,
"targetTokens": 100000,
"preserveRecent": 10,
"preserveTools": true,
"summarizeOlder": true
}
}
}
}
Features:
- Automatically compact when approaching token limit
- Preserve recent messages for context
- Keep tool call history for continuity
- Optionally summarize older conversations
2. Session Reset Command
Add built-in /reset command to clear session history:
{
"commands": {
"native": "auto",
"custom": {
"/reset": {
"description": "Clear session history",
"action": "reset-session",
"confirmRequired": false
}
}
}
}
User can type /reset in conversation to start fresh without deleting files manually.
3. Automatic Session Archival
- Archive sessions older than N days
- Compress old sessions to reduce disk usage (
.jsonl.gz)
- Option to auto-delete very old sessions
{
"agents": {
"defaults": {
"sessions": {
"archival": {
"enabled": true,
"archiveAfterDays": 7,
"deleteAfterDays": 30,
"compress": true
}
}
}
}
}
4. Context Length Warning and Visibility
- Warn user when session is approaching token limit (e.g., at 80%)
- Show current token usage in session status
- Suggest compaction or reset proactively
Example output:
⚠️ Session is using 160K/200K tokens (80%). Consider /reset to free up context.
Use Cases
- Group chat agent: Conversations can span days/weeks
- Personal assistant: Continuous daily interactions
- Customer support: Long support threads
- Development agent: Extended debugging sessions
Benefits
- Prevents "context too long" errors automatically
- Reduces manual maintenance burden
- Improves system reliability
- Better user experience with proactive warnings
Additional Context
Current workaround requires users to:
rm -rf ~/.openclaw/agents/*/sessions/*.jsonl
echo '{}' > ~/.openclaw/agents/*/sessions/sessions.json
openclaw gateway restart
This is not user-friendly and loses all conversation history.
Problem
Long-running agent sessions accumulate too many messages, leading to:
HTTP 400: invalid_request_error: context is too longerrorsCurrent Behavior
compaction.mode: "safeguard"is too conservativeImpact
This affects:
Users experience unexpected failures and must manually delete session files.
Proposed Improvements
1. Enhanced Auto-Compaction
{ "agents": { "defaults": { "compaction": { "mode": "auto", "strategy": "sliding-window", "maxTokens": 150000, "targetTokens": 100000, "preserveRecent": 10, "preserveTools": true, "summarizeOlder": true } } } }Features:
2. Session Reset Command
Add built-in
/resetcommand to clear session history:{ "commands": { "native": "auto", "custom": { "/reset": { "description": "Clear session history", "action": "reset-session", "confirmRequired": false } } } }User can type
/resetin conversation to start fresh without deleting files manually.3. Automatic Session Archival
.jsonl.gz){ "agents": { "defaults": { "sessions": { "archival": { "enabled": true, "archiveAfterDays": 7, "deleteAfterDays": 30, "compress": true } } } } }4. Context Length Warning and Visibility
Example output:
Use Cases
Benefits
Additional Context
Current workaround requires users to:
This is not user-friendly and loses all conversation history.