AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend/copilot): preserve tentative status and episode reference time in recall (#15798)
Nicholas Tindleaa3790323d17
diff --git a/autogpt_platform/backend/backend/copilot/graphiti/recall_render.py b/autogpt_platform/backend/backend/copilot/graphiti/recall_render.pyindex 3ec585cace..5384461d9e 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/recall_render.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/recall_render.py@@ -40,7 +40,12 @@ def render(fact: EntityEdge) -> str:text = fact_text(fact)if is_live(fact):valid_from, valid_to = fact_validity(fact)- return f"{text} (valid: {valid_from} — {valid_to})"+ qualification = (+ "Unconfirmed inference (tentative): "+ if fact_status(fact) == MemoryStatus.tentative.value+ else ""+ )+ return f"{qualification}{text} (valid: {valid_from} — {valid_to})"retired_at = str(fact.expired_at) if fact.expired_at else "at an unknown time"return f"{text} ({_retired_label(fact)} {retired_at})"@@ -62,8 +67,9 @@ def fact_validity(fact: EntityEdge) -> tuple[str, str]:def render_episode(episode: EpisodicNode) -> str:- """``[created_at] body``, the body cut to ``EPISODE_DISPLAY_CHARS``."""- return f"[{episode.created_at}] {episode.content[:EPISODE_DISPLAY_CHARS]}"+ """Date the statement by its reference time, falling back to ingestion time."""+ timestamp = episode.valid_at or episode.created_at+ return f"[{timestamp}] {episode.content[:EPISODE_DISPLAY_CHARS]}"def episode_scope(episode: EpisodicNode) -> str:diff --git a/autogpt_platform/backend/backend/copilot/graphiti/recall_render_test.py b/autogpt_platform/backend/backend/copilot/graphiti/recall_render_test.pyindex 93a169b653..b6d51821f0 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/recall_render_test.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/recall_render_test.py@@ -49,6 +49,26 @@ def _episode(content: str) -> EpisodicNode:class TestRender:+ @pytest.mark.parametrize("invalid_at", [None, _NOW])+ def test_only_live_tentative_facts_are_unconfirmed(+ self, invalid_at: datetime | None+ ) -> None:+ tentative = _fact(status="tentative", valid_at=_NOW, invalid_at=invalid_at)+ active = _fact(valid_at=_NOW, invalid_at=invalid_at)+ legacy = active.model_copy(update={"attributes": {}})+ retired = _fact(status="tentative", expired_at=_NOW)+ valid_to = str(invalid_at) if invalid_at else "present"+ interval = f"valid: {_NOW} — {valid_to}"++ assert [+ recall_render.render(f) for f in (tentative, active, legacy, retired)+ ] == [+ f"Unconfirmed inference (tentative): Alice works on Atlas ({interval})",+ f"Alice works on Atlas ({interval})",+ f"Alice works on Atlas ({interval})",+ f"Alice works on Atlas (expired {_NOW})",+ ]+def test_live_fact_shows_its_validity(self) -> None:fact = _fact(valid_at=datetime(2025, 1, 1, tzinfo=timezone.utc))assert recall_render.render(fact) == (@@ -94,6 +114,17 @@ class TestRender:class TestRenderEpisode:+ def test_reference_time_dates_delayed_episodes_with_legacy_fallback(self) -> None:+ episode = _episode("The delivery is tomorrow.")+ episode.valid_at = datetime(2026, 9, 30, 12, tzinfo=timezone.utc)+ episode.created_at = datetime(2026, 10, 20, 12, tzinfo=timezone.utc)+ legacy = episode.model_copy(update={"valid_at": None})++ assert [recall_render.render_episode(item) for item in (episode, legacy)] == [+ "[2026-09-30 12:00:00+00:00] The delivery is tomorrow.",+ "[2026-10-20 12:00:00+00:00] The delivery is tomorrow.",+ ]+def test_timestamp_and_body(self) -> None:assert recall_render.render_episode(_episode("talked about coffee")) == ("[2026-09-26 12:00:00+00:00] talked about coffee"diff --git a/autogpt_platform/backend/backend/copilot/prompting.py b/autogpt_platform/backend/backend/copilot/prompting.pyindex 7be0923ffa..3b50b452b0 100644--- a/autogpt_platform/backend/backend/copilot/prompting.py+++ b/autogpt_platform/backend/backend/copilot/prompting.py@@ -961,6 +961,7 @@ You have access to persistent temporal memory tools scoped to the assistant runn- At the START of every new conversation to check for relevant context### MEMORY RULES:+- Treat any memory marked tentative as an unconfirmed inference: state that uncertainty before mentioning it, and do not strengthen it or add details.- Facts have temporal validity — if something CHANGED (e.g., user switched from Shopify to WooCommerce), store the new fact. The system automatically invalidates the old one.- Never fabricate memories. Only persist what the user actually said.- Memory is private and isolated to the current assistant. Otto and hired experts cannot read each other's memories.diff --git a/autogpt_platform/backend/backend/copilot/prompting_test.py b/autogpt_platform/backend/backend/copilot/prompting_test.pyindex 4c4ffdfa58..1e5507bdb9 100644--- a/autogpt_platform/backend/backend/copilot/prompting_test.py+++ b/autogpt_platform/backend/backend/copilot/prompting_test.py@@ -169,6 +169,13 @@ class TestToolDiscoveryPriorityAntiPattern:class TestGraphitiMemoryScope:+ def test_supplement_keeps_tentative_memories_unconfirmed(self):+ assert (+ "Treat any memory marked tentative as an unconfirmed inference: "+ "state that uncertainty before mentioning it, "+ "and do not strengthen it or add details."+ ) in prompting.get_graphiti_supplement()+def test_supplement_describes_assistant_scoped_memory(self):result = prompting.get_graphiti_supplement()diff --git a/autogpt_platform/backend/backend/copilot/tools/graphiti_forget.py b/autogpt_platform/backend/backend/copilot/tools/graphiti_forget.pyindex 634a545b88..dc36c904c0 100644--- a/autogpt_platform/backend/backend/copilot/tools/graphiti_forget.py+++ b/autogpt_platform/backend/backend/copilot/tools/graphiti_forget.py@@ -29,6 +29,7 @@ from backend.copilot.graphiti.memory_model import ()from backend.copilot.graphiti.recall import (FORGOTTEN_FACT,+ fact_status,live_fact_predicate,search_facts,search_forgotten_facts,@@ -327,12 +328,16 @@ def _build_confirm_message(def _candidate(edge: EntityEdge) -> dict[str, str]:"""One forget candidate, in the shape ``memory_forget_search`` returns."""valid_from, valid_to = fact_validity(edge)- return {+ candidate = {"uuid": edge.uuid,"fact": fact_text(edge),"valid_from": valid_from,"valid_to": valid_to,}+ status = fact_status(edge)+ if status is not None:+ candidate["status"] = status+ return candidatedef _forgotten_candidate(edge: EntityEdge) -> dict[str, str]:diff --git a/autogpt_platform/backend/backend/copilot/tools/graphiti_forget_test.py b/autogpt_platform/backend/backend/copilot/tools/graphiti_forget_test.pyindex d9b5d4ca88..51839af52b 100644--- a/autogpt_platform/backend/backend/copilot/tools/graphiti_forget_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/graphiti_forget_test.py@@ -98,8 +98,11 @@ class TestExpertMemoryScope:class TestForgetSearchCandidates:+ @pytest.mark.parametrize("status", [None, "active", "tentative"])@pytest.mark.asyncio- async def test_candidates_carry_uuid_fact_and_validity(self) -> None:+ async def test_candidates_carry_uuid_fact_and_validity(+ self, status: str | None+ ) -> None:edge = EntityEdge(uuid="e1",group_id="user_user-abc",@@ -109,6 +112,7 @@ class TestForgetSearchCandidates:name="works_on",fact="Alice works on Atlas",valid_at=datetime(2025, 1, 1, tzinfo=timezone.utc),+ attributes={"status": status} if status else {},)session = ChatSession.new("user-abc", dry_run=False)with (@@ -126,6 +130,7 @@ class TestForgetSearchCandidates:"fact": "Alice works on Atlas","valid_from": "2025-01-01 00:00:00+00:00","valid_to": "present",+ **({"status": status} if status else {}),}]