fix(openclaw): switch multi-agent compaction to true LLM summarization and document split-turn drift

This commit is contained in:
Moritz Graf
2026-09-29 08:48:15 +02:00
parent 5bf1a29f4a
commit 61ac5baa6f
2 changed files with 61 additions and 5 deletions
+11 -5
View File
@@ -28,12 +28,12 @@ Compacts all active forum topics and main sessions exceeding the token threshold
import subprocess
import json
import sys
import time
THRESHOLD_TOKENS = 25000
MAX_LINES = 250
def main():
print(f"=== Running OpenClaw Nightly Multi-Agent Compaction (threshold: {THRESHOLD_TOKENS} tokens, maxLines: {MAX_LINES}) ===")
print(f"=== Running OpenClaw Nightly Multi-Agent Compaction (threshold: {THRESHOLD_TOKENS} tokens, LLM summarization) ===")
res = subprocess.run(["openclaw", "sessions", "--all-agents", "--json"], capture_output=True, text=True)
if res.returncode != 0:
print(f"Failed to list sessions: {res.stderr}")
@@ -48,12 +48,17 @@ def main():
agent = s.get("agentId") or "main"
tokens = s.get("totalTokens") or 0
# Target main session and all telegram group topic sessions
if (":telegram:group" in key or key == "agent:main:main") and not key.endswith(":heartbeat"):
# Target main sessions and all telegram sessions (topics and direct)
is_target = (
key == "agent:main:main" or
":telegram:" in key or
(key.startswith("agent:") and key.endswith(":main"))
)
if is_target and not key.endswith(":heartbeat"):
if tokens >= THRESHOLD_TOKENS:
print(f"Compacting {agent} ({tokens} tokens) -> {key}...")
c_res = subprocess.run(
["openclaw", "sessions", "compact", key, "--agent", agent, "--max-lines", str(MAX_LINES)],
["openclaw", "sessions", "compact", key, "--agent", agent],
capture_output=True, text=True
)
if c_res.returncode == 0:
@@ -61,6 +66,7 @@ def main():
compacted += 1
else:
print(f" ✗ {c_res.stderr.strip()}")
time.sleep(2)
else:
skipped += 1