Repository navigation
feat(cognition): surface recalled engrams into prompt_assembly (#1211 PR-2) - #1234
Merged
Merged
Conversation
…PR-2) Closes the engram loop end-to-end. PR-1 (#1213) wired admission inline on the cognition/respond hot path so personas grow engrams from chat turns. PR-2 plumbs the RECALL side: after admission runs, pull the persona's most-recent engrams via AdmissionState::recall_recent and surface them into prompt_assembly as a [Recent Memory] block in the system prompt. The model now SEES its own memory. Without this, the engram store grew but the persona never used it. ## Changes 1. RespondInput.recalled_engrams: Vec<String> (new field) — content strings only; full Engram type stays in the admission/recall layer so future structural changes (kind enum, embeddings, recall_keys reshape) don't ripple into prompt_assembly. Per-persona (each persona's admission store is independent), so the field lives on RespondInput not the per-turn-shared TurnContext (#1206) — different personas in the same room recall different memory. 2. PromptAssemblyInput.recalled_engrams: Vec<String> (new field) — mirrors RespondInput; respond_inner passes through. 3. prompt_assembly::assemble renders [Recent Memory] block right after the matched-angle injection (so persona sees its own memory adjacent to the analyzer's per-turn perspective). Bullet-prefixed engrams via writeln! to avoid the trailing-newline-in-format-string clippy lint. Empty list = no rendering, no header — backwards-compat with cold-start personas that haven't accumulated memory yet. 4. modules/cognition.rs cognition/respond IPC handler: after run_inline_admission_gate runs, call state.personas.get(persona_id).admission.recall_recent(5) and populate input.recalled_engrams with content strings before handing to respond(). Cap of 5 is a sensible v1 default — enough to ground the persona in continuity without dominating the prompt. Future tunable via per-persona AdmissionConfig. 5. cognition_io::build_respond_input defaults recalled_engrams to Vec::new() so any RespondInput constructed outside the IPC path (tests, direct callers) gets a no-op memory render. ## Tests - recalled_engrams_render_as_memory_block — non-empty list produces the [Recent Memory] header AND each bullet-prefixed engram. - empty_recalled_engrams_emits_no_memory_block — empty list produces NO header (backwards-compat for pre-PR-2 callers + cold-start personas). - All 451 existing persona tests pass. Together with PR-1 (#1213), the engram substrate (#1121 PR-1..5) is now wired end-to-end: inbox → admission gate (PR-1) → engram store grows recall surface (this PR) → prompt context → model sees its own memory A persona that says "my favorite color is teal" in turn N now has that fact available as [Recent Memory] context in turn N+1, and can answer "what color did I say I liked?" correctly. ## Validation - cargo test --lib --features metal,accelerate persona:: — 451 passed, 0 failed (2 new prompt_assembly tests). - cargo clippy --lib --features metal,accelerate — no new warnings. - Pre-push hook ran without --no-verify. Refs #1211. Refs #1121. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.
Closes the engram loop end-to-end. PR-1 (#1213) wired admission inline on the cognition/respond hot path so personas grow engrams from chat turns. PR-2 plumbs the RECALL side — model now SEES its own memory.
What
After admission gate runs in cognition/respond IPC handler, pull the persona's most-recent engrams via AdmissionState::recall_recent(5) and populate input.recalled_engrams. respond_inner passes through to PromptAssemblyInput, which renders a [Recent Memory] block in the system prompt right after the matched-angle injection.
End-to-end loop now wired
A persona that says "my favorite color is teal" in turn N now has that fact available as [Recent Memory] context in turn N+1, and can answer "what color did I say I liked?" correctly.
Design choices
Test plan
Refs #1211. Refs #1121.
🤖 Generated with Claude Code