mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-31 08:13:11 +03:00
style(memory): minimize summary diff churn
This commit is contained in:
@@ -102,11 +102,7 @@ class AutoCompact:
|
|||||||
finally:
|
finally:
|
||||||
self._archiving.discard(key)
|
self._archiving.discard(key)
|
||||||
|
|
||||||
def prepare_session(
|
def prepare_session(self, session: Session, key: str) -> tuple[Session, SessionSummary | None]:
|
||||||
self,
|
|
||||||
session: Session,
|
|
||||||
key: str,
|
|
||||||
) -> tuple[Session, SessionSummary | None]:
|
|
||||||
if self._is_internal_session(key):
|
if self._is_internal_session(key):
|
||||||
self._archiving.discard(key)
|
self._archiving.discard(key)
|
||||||
self._summaries.pop(key, None)
|
self._summaries.pop(key, None)
|
||||||
|
|||||||
@@ -686,10 +686,7 @@ class TestPrepareSession:
|
|||||||
ac.sessions = mock_sm
|
ac.sessions = mock_sm
|
||||||
key = "dream:20260602-155256"
|
key = "dream:20260602-155256"
|
||||||
ac._archiving.add(key)
|
ac._archiving.add(key)
|
||||||
ac._summaries[key] = SessionSummary(
|
ac._summaries[key] = SessionSummary("Hot summary.", datetime(2026, 6, 2, 15, 52, 56))
|
||||||
"Hot summary.",
|
|
||||||
datetime(2026, 6, 2, 15, 52, 56),
|
|
||||||
)
|
|
||||||
session = _make_session(
|
session = _make_session(
|
||||||
key=key,
|
key=key,
|
||||||
updated_at=datetime.now() - timedelta(minutes=20),
|
updated_at=datetime.now() - timedelta(minutes=20),
|
||||||
|
|||||||
@@ -332,24 +332,16 @@ class TestBuildSystemPrompt:
|
|||||||
|
|
||||||
def test_includes_session_summary(self, tmp_path):
|
def test_includes_session_summary(self, tmp_path):
|
||||||
builder = _builder(tmp_path)
|
builder = _builder(tmp_path)
|
||||||
result = builder.build_system_prompt(
|
summary = SessionSummary("Previous chat about Python.", datetime(2026, 8, 19, 10, 0))
|
||||||
session_summary=SessionSummary(
|
result = builder.build_system_prompt(session_summary=summary)
|
||||||
text="Previous chat about Python.",
|
|
||||||
last_active=datetime(2026, 8, 19, 10, 0),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert "Previous chat about Python." in result
|
assert "Previous chat about Python." in result
|
||||||
assert "[Archived Context Summary]" in result
|
assert "[Archived Context Summary]" in result
|
||||||
|
|
||||||
def test_sections_separated_by_separator(self, tmp_path):
|
def test_sections_separated_by_separator(self, tmp_path):
|
||||||
(tmp_path / "AGENTS.md").write_text("Rules.", encoding="utf-8")
|
(tmp_path / "AGENTS.md").write_text("Rules.", encoding="utf-8")
|
||||||
builder = _builder(tmp_path)
|
builder = _builder(tmp_path)
|
||||||
result = builder.build_system_prompt(
|
summary = SessionSummary("Summary.", datetime(2026, 8, 19, 10, 0))
|
||||||
session_summary=SessionSummary(
|
result = builder.build_system_prompt(session_summary=summary)
|
||||||
text="Summary.",
|
|
||||||
last_active=datetime(2026, 8, 19, 10, 0),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert "\n\n---\n\n" in result
|
assert "\n\n---\n\n" in result
|
||||||
|
|
||||||
def test_no_bootstrap_no_summary(self, tmp_path):
|
def test_no_bootstrap_no_summary(self, tmp_path):
|
||||||
|
|||||||
@@ -121,10 +121,7 @@ def test_session_summary_replaces_matching_recent_history_entry(tmp_path) -> Non
|
|||||||
|
|
||||||
builder.memory.append_history("another session event", session_key=session_key)
|
builder.memory.append_history("another session event", session_key=session_key)
|
||||||
summary_cursor = builder.memory.append_history(overview, session_key=session_key)
|
summary_cursor = builder.memory.append_history(overview, session_key=session_key)
|
||||||
summary = SessionSummary(
|
summary = SessionSummary(overview, real_datetime(2026, 8, 19, 10, 0))
|
||||||
text=overview,
|
|
||||||
last_active=real_datetime(2026, 8, 19, 10, 0),
|
|
||||||
)
|
|
||||||
|
|
||||||
prompt = builder.build_system_prompt(
|
prompt = builder.build_system_prompt(
|
||||||
session_key=session_key,
|
session_key=session_key,
|
||||||
|
|||||||
@@ -213,13 +213,7 @@ async def test_preflight_consolidation_receives_pending_summary(tmp_path) -> Non
|
|||||||
loop = _make_loop(tmp_path, estimated_tokens=100, context_window_tokens=200)
|
loop = _make_loop(tmp_path, estimated_tokens=100, context_window_tokens=200)
|
||||||
session = loop.sessions.get_or_create("cli:test")
|
session = loop.sessions.get_or_create("cli:test")
|
||||||
loop.auto_compact.prepare_session = MagicMock(
|
loop.auto_compact.prepare_session = MagicMock(
|
||||||
return_value=(
|
return_value=(session, SessionSummary("earlier context", session.updated_at))
|
||||||
session,
|
|
||||||
SessionSummary(
|
|
||||||
text="earlier context",
|
|
||||||
last_active=session.updated_at,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
) # type: ignore[method-assign]
|
) # type: ignore[method-assign]
|
||||||
loop.consolidator.maybe_consolidate_by_tokens = AsyncMock(return_value=None) # type: ignore[method-assign]
|
loop.consolidator.maybe_consolidate_by_tokens = AsyncMock(return_value=None) # type: ignore[method-assign]
|
||||||
loop.schedule_background = lambda coro: coro.close() # type: ignore[method-assign]
|
loop.schedule_background = lambda coro: coro.close() # type: ignore[method-assign]
|
||||||
|
|||||||
Reference in New Issue
Block a user