Skip to content

feat(cognition): surface recalled engrams into prompt_assembly (#1211 PR-2) - #1234

Merged
joelteply merged 1 commit into
canaryfrom
feat/engram-recall-into-prompt-1211
May 14, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/engram-recall-into-prompt-1211

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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

  • 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.

Design choices

  • Vec not Vec: prompt_assembly only needs the content text; full Engram type stays in the admission/recall layer so future structural changes (kind enum, embeddings, recall_keys reshape) don't ripple into the prompt path
  • Per-persona on RespondInput, not TurnContext (perf(cognition): hoist per-turn context out of RespondInput — N personas x identical clones per turn #1206): each persona's admission store is independent — different personas in the same room recall different memory
  • Cap of 5 engrams: enough to ground in continuity without dominating the prompt. Future tunable via per-persona AdmissionConfig
  • Empty list = no rendering, no header: backwards-compat with cold-start personas + pre-PR-2 callers
  • prompt_assembly stays a pure formatter: no policy decisions about budget; caller (IPC handler) trims

Test plan

  • cargo test --lib --features metal,accelerate persona:: — 451 passed, 2 new (recalled_engrams_render_as_memory_block + empty_recalled_engrams_emits_no_memory_block)
  • cargo clippy clean (no new warnings; writeln! avoids the trailing-newline format string lint)
  • Pre-push hook ran without --no-verify
  • Live smoke: send memorable chat in general room → next turn from same persona surfaces the memory in their reply (deferred to a separate validation card; substrate is in place)

Refs #1211. Refs #1121.

🤖 Generated with Claude Code

…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]>
@joelteply
joelteply merged commit b69eced into canary May 14, 2026
3 checks passed
@joelteply
joelteply deleted the feat/engram-recall-into-prompt-1211 branch May 14, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant