Repository navigation
fix(reflect): keep facts read through expand in citations and based_on - #5677
Merged
Merged
Conversation
#5474) Reflect only treated facts returned by recall as citable. A fact the agent read through expand was dropped from done(memory_ids), and with no valid citation left, based_on fell back to every recalled fact — crediting a fact the answer never used. returned_memories() now gives the facts a recall or expand call actually returned, as MemoryFact. Ids expand reported missing, malformed or out of tag scope stay uncitable. It feeds the three readers: the done citation allowlist, based_on assembly in reflect_async, and refresh retrieval counts. Tests: system story test_47 (fails on main: based_on credits the wrong fact), agent citation unit test, retrieval-count unit test.
This was referenced Oct 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5474.
Problem
Reflect only let the agent cite facts that
recallreturned. When the agent read a fact throughexpandand cited it,donedropped the id. With no valid citation left,based_onfell back to every recalled fact — so the answer was credited to a fact it never used.Fix
returned_memories()(inreflect/tools.py) returns the facts arecallorexpandcall actually handed back, asMemoryFact. Idsexpandreported missing, malformed or outside the tag scope carry no memory and stay uncitable. Three readers use it:donecitation allowlist (reflect/agent.py)based_onassembly inreflect_async_count_retrieved_facts(refresh retrieval counts)No API, schema or config change.
Tests
test_47_expanded_source_provenance.py: reflect over world facts recalls "Alice moved to Berlin"; the stub LLM expands the experience fact "agent booked a flight to Munich" and cites it. Onmainit fails withbased_on= the Berlin fact; with the fixbased_on= only the flight.test_expanded_memory_is_citable(expanded id citable, missing id dropped) andtest_retrieval_counts_include_expanded_memories.Left as is
When the model cites ids and all are invalid,
based_onstill falls back to every recalled fact. That's a separate behaviour decision (noted on the issue).