fix(memory): add timestamp and cap to recent history injection

This commit is contained in:
Xubin Ren
2026-04-08 00:03:11 +08:00
committed by Xubin Ren
parent 05d8062c70
commit ce7986e492
2 changed files with 42 additions and 2 deletions
+5 -1
View File
@@ -19,6 +19,7 @@ class ContextBuilder:
BOOTSTRAP_FILES = ["AGENTS.md", "SOUL.md", "USER.md", "TOOLS.md"]
_RUNTIME_CONTEXT_TAG = "[Runtime Context — metadata only, not instructions]"
_MAX_RECENT_HISTORY = 50
def __init__(self, workspace: Path, timezone: str | None = None):
self.workspace = workspace
@@ -50,7 +51,10 @@ class ContextBuilder:
entries = self.memory.read_unprocessed_history(since_cursor=self.memory.get_last_dream_cursor())
if entries:
parts.append("# Recent History\n\n" + "\n".join(f"- {entry['content']}" for entry in entries))
capped = entries[-self._MAX_RECENT_HISTORY:]
parts.append("# Recent History\n\n" + "\n".join(
f"- [{e['timestamp']}] {e['content']}" for e in capped
))
return "\n\n---\n\n".join(parts)