feat(memory): add progressive wiki and drain Dream history (#4477)
This commit is contained in:
1 parent
9ccf3b6214
commit
74d070f699
40 files changed
+1513
-738
No files matched your search
@@ -215,19 +215,6 @@ def _advance_dream_cursor_if_behind(memory: Any) -> None:
|
||||
memory.set_last_dream_cursor(latest)
|
||||
|
||||
|
||||
def _commit_dream_changes(memory: Any) -> str | None:
|
||||
if not memory.git.is_initialized():
|
||||
return None
|
||||
diff_body = memory.dream_content_diff()
|
||||
if not diff_body:
|
||||
return None
|
||||
message = memory.build_dream_commit_message(
|
||||
"dream: periodic memory consolidation",
|
||||
diff_body,
|
||||
)
|
||||
return memory.git.auto_commit(message)
|
||||
|
||||
|
||||
_HEARTBEAT_PREAMBLE = (
|
||||
"[Your response will be delivered directly to the user's messaging app. "
|
||||
"Output ONLY the final user-facing message. Never reference internal "
|
||||
@@ -623,61 +610,17 @@ def _run_claimed_gateway(
|
||||
|
||||
# Dream is an internal job — run directly, not through the agent loop.
|
||||
if job.name == "dream":
|
||||
from nanobot.agent.memory import MemoryStore
|
||||
from nanobot.agent.dream import run_dream
|
||||
|
||||
dream_session_key = MemoryStore.dream_session_key
|
||||
|
||||
store = agent.context.memory
|
||||
resp = None
|
||||
diff_body = ""
|
||||
try:
|
||||
result = store.build_dream_prompt()
|
||||
if result is None:
|
||||
logger.info("Dream: nothing to process")
|
||||
return None
|
||||
prompt, last_cursor = result
|
||||
key = dream_session_key()
|
||||
dream_runtime = agent.dream_runtime()
|
||||
await mcp_provider.connect()
|
||||
resp = await agent.process_direct(
|
||||
prompt,
|
||||
session_key=key,
|
||||
ephemeral=True,
|
||||
tools=store.build_dream_tools(),
|
||||
on_progress=_silent,
|
||||
runtime=dream_runtime,
|
||||
)
|
||||
# The real file delta grounds the audit record; normal completion
|
||||
# decides whether this history batch has finished processing.
|
||||
diff_body = store.dream_content_diff()
|
||||
completed = MemoryStore.dream_run_completed(resp)
|
||||
if completed:
|
||||
store.set_last_dream_cursor(last_cursor)
|
||||
if diff_body:
|
||||
logger.info(
|
||||
"Dream cron job completed, cursor advanced to {}",
|
||||
last_cursor,
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"Dream cron job completed with no memory changes; "
|
||||
"cursor advanced to {}",
|
||||
last_cursor,
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Dream cron job did not complete ({}); cursor remains at {}",
|
||||
MemoryStore.dream_incompletion_reason(resp),
|
||||
store.get_last_dream_cursor(),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Dream cron job failed")
|
||||
finally:
|
||||
sha = _commit_dream_changes(store)
|
||||
if sha:
|
||||
logger.info("Dream commit: {}", sha)
|
||||
store.compact_history()
|
||||
await agent.sessions.state.prune_dream_sessions()
|
||||
result = await run_dream(agent, commit_prefix="dream: periodic memory consolidation")
|
||||
if result.error:
|
||||
logger.warning("Dream did not complete ({})", result.error)
|
||||
elif not result.had_input:
|
||||
logger.info("Dream: nothing to process")
|
||||
else:
|
||||
logger.info("Dream completed the pending history range")
|
||||
if result.commit_sha:
|
||||
logger.info("Dream commit: {}", result.commit_sha)
|
||||
return None
|
||||
|
||||
if job.name == "heartbeat":
|
||||
|
||||
Reference in new issue
Block a user