Repository navigation
Description
What
Follow-up to #151 (merged, commit-only half) and the original #150. PR #151 landed turn-end commit to fusion-memory but explicitly deferred retrieve-inject — recalling relevant long-term memory into the main agent's system prompt at turn start. This issue tracks the deferred half so fusion-code gets the full cross-session memory loop (retrieve → act → commit), matching what fusion-cowork #68 and fusion-agent-studio #247 already have.
Why it's deferred
#151's body notes the subagent spawn path (src/tools/AgentTool/AgentTool.tsx) is the wrong seam — it builds subagent prompts, not the main conversational agent's system prompt. The correct main-agent system-prompt assembly seam needs maintainer confirmation before a broader edit, so retrieve-inject was scoped out rather than guessed.
Proposal
Add retrieve-inject that, at main-agent turn start:
- Calls fm-server
retrieve(POST /v1/memory/retrieve, Bearer auth) with the latest user message,top_kand a token budget. - Injects the returned
FormattedContext.blocksinto the main agent's system prompt (alongside git context and chub hints), not subagent prompts. - Degrades gracefully — fm-server down or
FUSION_MEMORY_API_KEYunset → skip with a debug log, never throw (same pattern as the commit half).
Wire contract (already implemented in fusion-memory fm-server)
JSON-RPC 2.0 envelope {jsonrpc, method, params, id} -> {result|error, id}:
retrieve->{blocks: ContextBlock[], total_tokens: number}
HTTP: POST /v1/memory/retrieve (Bearer auth). Full contract: fusion-memory/clients/README.md.
Needed from maintainer
- Correct seam: where is the main conversational agent's system prompt assembled (the one that runs when no
agentIdis set, i.e.!toolUseContext.agentId)? Candidate files to confirm: the main prompt builder / system-prompt assembly path thatAgentTool.tsxfeeds into but does not own. - Token budget: how much of the system-prompt budget can retrieve-inject consume (avoid blowing the context window fusion-memory exists to protect).
Config (operator env, same as #151)
| Env | Default | Purpose |
|---|---|---|
FUSION_MEMORY_BASE_URL |
http://127.0.0.1:11440 |
fm-server base URL |
FUSION_MEMORY_API_KEY |
(none) | Bearer token; if unset, retrieve is skipped |
Scope (expected)
- New: a
retrieveContexthelper alongsidesrc/services/memory/commitTurn.ts(reusefusionMemoryClient.ts'srpc()). - Edit: the main-agent system-prompt assembly seam (to be identified by maintainer).
- Tests: wire-contract asserts mirroring
fusionMemoryClient.test.ts+ an inject-format test.
100% offline — HTTP only to 127.0.0.1. No cloud calls.
Activity
feat(memory): retrieve-inject long-term memory at turn start
feat(memory): retrieve cross-session long-term memory at turn start (#…
dahai80 commentedon Aug 30, 2026
Landed in 2c6733f (direct-push main). Wired the retrieve half symmetric to the commit half (#151).
Seam (found via code, not subagent prompts): src/utils/processUserInput/processUserInput.ts — after query_hooks_end, inject recalled memory as a hook_additional_context attachment (same path as UserPromptSubmit hook additionalContext). Main-agent only.
Race fix: AWAIT retrieveMemorySection (not fire-and-forget) — both callers read result.messages synchronously after await processUserInput, so fire-and-forget would lose the injected message.
Token budget: FUSION_MEMORY_RETRIEVE_BUDGET (default 4096) → retrieve RPC + applyTruncation (10000 char cap). Fail-empty (no fetch when API key unset/subagent/empty).
Gates: typecheck 0 / 961 tests pass / biome 0 new errors / build:dev + build:dev:full green.