The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(hindsight): send configured event timestamps
Fabiao De Gongniu97850afa333d
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..4bec55656f9--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+ragingbullddiff --git a/plugins/memory/hindsight/__init__.py b/plugins/memory/hindsight/__init__.pyindex 03632b98da7..5516f1a1e25 100644--- a/plugins/memory/hindsight/__init__.py+++ b/plugins/memory/hindsight/__init__.py@@ -49,6 +49,7 @@ from agent.secret_scope import get_secretfrom agent.memory_provider import MemoryProvider, RecallStatusfrom hermes_constants import get_hermes_home+from hermes_time import now as _hermes_nowfrom tools.registry import tool_errorfrom hermes_cli.config import cfg_get@@ -544,6 +545,11 @@ def _utc_timestamp() -> str:return datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")+def _event_timestamp() -> str:+ """Return the configured Hermes-local timestamp for a retained event."""+ return _hermes_now().isoformat(timespec="seconds")++def _embedded_profile_name(config: dict[str, Any]) -> str:"""Return the Hindsight embedded profile name for this Hermes config."""profile = config.get("profile", "hermes")@@ -1975,7 +1981,7 @@ class HindsightMemoryProvider(MemoryProvider):self._prefetch_thread.start()def _build_turn_messages(self, user_content: str, assistant_content: str) -> List[Dict[str, str]]:- now = datetime.now(timezone.utc).isoformat()+ now = _event_timestamp()return [{"role": "user",@@ -2031,6 +2037,7 @@ class HindsightMemoryProvider(MemoryProvider):"bank_id": self._bank_id,"content": content,"metadata": metadata or self._build_metadata(message_count=1, turn_index=self._turn_index),+ "timestamp": _event_timestamp(),}if context is not None:kwargs["context"] = contextdiff --git a/tests/plugins/memory/test_hindsight_provider.py b/tests/plugins/memory/test_hindsight_provider.pyindex d7114e00394..1da9e72f607 100644--- a/tests/plugins/memory/test_hindsight_provider.py+++ b/tests/plugins/memory/test_hindsight_provider.py@@ -11,9 +11,11 @@ import reimport statimport sysimport time+from datetime import datetimefrom pathlib import Pathfrom types import SimpleNamespacefrom unittest.mock import AsyncMock, MagicMock+from zoneinfo import ZoneInfoimport pytest@@ -844,7 +846,9 @@ class TestRecallStatus:class TestSyncTurn:- def test_sync_turn_retains_metadata_rich_turn(self, provider_with_config):+ def test_sync_turn_retains_metadata_rich_turn(self, provider_with_config, monkeypatch):+ event_time = datetime(2026, 8, 10, 11, 9, tzinfo=ZoneInfo("Asia/Shanghai"))+ monkeypatch.setattr("plugins.memory.hindsight._hermes_now", lambda: event_time)p = provider_with_config(retain_tags=["conv", "session1"],retain_source="hermes",@@ -894,8 +898,29 @@ class TestSyncTurn:assert item["metadata"]["agent_identity"] == "fakeassistantname"assert item["metadata"]["turn_index"] == "1"assert item["metadata"]["message_count"] == "2"- assert re.fullmatch(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?\+00:00", content[0][0]["timestamp"])+ assert content[0][0]["timestamp"] == event_time.isoformat(timespec="seconds")+ assert content[0][1]["timestamp"] == event_time.isoformat(timespec="seconds")assert re.fullmatch(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", item["metadata"]["retained_at"])+ assert item["timestamp"] == event_time.isoformat(timespec="seconds")++ @pytest.mark.asyncio+ async def test_retain_timestamp_is_serialized_by_pinned_client(self, provider):+ from hindsight_client import Hindsight++ item = provider._build_retain_kwargs("hello")+ item.pop("bank_id", None)+ item.pop("retain_async", None)++ client = Hindsight(base_url="http://localhost:9999", api_key="test-key")+ client._memory_api.retain_memories = AsyncMock(return_value=SimpleNamespace(ok=True))+ try:+ await client.aretain_batch(bank_id="test-bank", items=[item])+ call = client._memory_api.retain_memories.await_args+ assert call is not None+ request = call.args[1]+ assert request.to_dict()["items"][0]["timestamp"] == item["timestamp"]+ finally:+ await client.aclose()def test_resume_creates_new_document(self, tmp_path, monkeypatch):