Skip to content

Commit 0a74ce3

Browse files
authored
fix(docs): read observation history before curating facts in memories.py (#2120)
memories.py listed memories, then ran edit -> invalidate -> restore on a fact. Any update_memory call re-consolidates the bank and recreates derived observations with new ids, so the observation id from the earlier listing was stale by the time the example called get_observation_history — which the engine correctly 404s on (NotFoundException), failing test-doc-examples (python) on every PR. Move the observation-history read to immediately after list_memories, before the curate operations, so it uses a live id. No re-consolidation timing dependency. The existing `if observation is not None` guard still covers the no-observation case.
1 parent 5b5188a commit 0a74ce3

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

hindsight-docs/examples/api/memories.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ async def main():
3838
print(f"{len(invalidated.items)} invalidated fact(s)")
3939
# [/docs:list-memories]
4040

41+
# An observation (derived) exposes how it evolved as sources arrived. Read
42+
# it here, before the edit/invalidate/restore below: any update_memory call
43+
# re-consolidates and recreates observations with new ids, so an id captured
44+
# before those steps is stale afterward (get_observation_history would 404).
45+
observation = next((u for u in memories.items if u["fact_type"] == "observation"), None)
46+
if observation is not None:
47+
# [docs:observation-history]
48+
# Get the refresh history of a derived observation.
49+
history = await client.memory.get_observation_history(
50+
bank_id=BANK_ID, memory_id=observation["id"]
51+
)
52+
print(f"Observation history entries: {len(history)}")
53+
# [/docs:observation-history]
54+
4155
# Grab a raw fact (world/experience) to curate in the examples below.
4256
fact = next((u for u in memories.items if u["fact_type"] in ("world", "experience")), None)
4357
if fact is None:
@@ -103,17 +117,6 @@ async def main():
103117
)
104118
# [/docs:restore-memory]
105119

106-
# An observation (derived) exposes how it evolved as sources arrived.
107-
observation = next((u for u in memories.items if u["fact_type"] == "observation"), None)
108-
if observation is not None:
109-
# [docs:observation-history]
110-
# Get the refresh history of a derived observation.
111-
history = await client.memory.get_observation_history(
112-
bank_id=BANK_ID, memory_id=observation["id"]
113-
)
114-
print(f"Observation history entries: {len(history)}")
115-
# [/docs:observation-history]
116-
117120
# =========================================================================
118121
# Cleanup (not shown in docs)
119122
# =========================================================================

0 commit comments

Comments
 (0)