recall
Search the active long-term memory backend and return matching memories.
Source
- Entry:
packages/coding-agent/src/tools/memory-recall.ts - Model-facing prompt:
packages/coding-agent/src/prompts/tools/recall.md - Hindsight collaborators:
packages/coding-agent/src/hindsight/state.ts— session state, recall query defaults, prompt-side auto-recall.packages/coding-agent/src/hindsight/content.ts— result formatting and UTC timestamp formatting.packages/coding-agent/src/hindsight/client.ts— HTTPrecallcall and error mapping.packages/coding-agent/src/hindsight/bank.ts— bank id and tag-filter scoping.
- Mnemopi collaborators:
packages/coding-agent/src/mnemopi/state.ts— scoped local recall and result formatting with ids.packages/coding-agent/src/mnemopi/config.ts— local bank scoping and recall limits.docs/tools/retain.md— shared backend, storage, scoping, and retention behavior.
Inputs
| Field | Type | Required | Description |
|---|---|---|---|
query |
string |
Yes | Natural-language search query. The tool passes it through unchanged except Mnemopi per-project-tagged may run an internal shared-bank fallback query. |
Outputs
Returns a single-shot tool result.
When matches exist:
content[0].type = "text"content[0].text = "Found <n> relevant memory/memories (as of YYYY-MM-DD HH:MM UTC):\n\n<bullet list>"details = {}
Hindsight bullet format comes from formatMemories(...):
- each bullet is
- <text> [<type>] (<mentioned_at>); the type and timestamp suffixes appear only when those fields are present.
Mnemopi bullet format comes from formatScopedRecallWithIds(...):
- each bullet is
- <content> (id: <id>|id unavailable) [<source>] (<YYYY-MM-DD>) c:<score>; optional source, date, and score suffixes appear only when present.
When no matches exist:
content[0].text = "No relevant memories found."details = {}
Flow
MemoryRecallTool.createIf(...)exposes the tool whenmemory.backendis either"hindsight"or"mnemopi".execute(...)wraps the operation inuntilAborted(...).- If the backend is
mnemopi:- it reads
session.getMnemopiSessionState()and throws if the backend was not started; - it calls
state.recallResultsScoped(params.query); - scoped recall queries each configured recall bank with
recallEnhanced(query, recallLimit, { includeFacts: true, channelId: bank }), merges/deduplicates results by id/content, sorts them, and truncates torecallLimit; - in
per-project-tagged, the shared bank may receive one extra fallback query with project-bank literal tokens stripped so broad global memories still match; - results are formatted with ids for later
memory_edituse.
- it reads
- If the backend is
hindsight:- it reads
session.getHindsightSessionState()and throws if the backend was not started; - it calls
state.client.recall(...)withbankId, query, configuredbudget,maxTokens,types, and bank-scope tag filters; HindsightApi.recall(...)POSTs/v1/default/banks/{bank_id}/memories/recall;- results are formatted into a plain-text list with
formatMemories(...).
- it reads
- Backend failures are logged with
logger.warn("recall failed", ...)and rethrown asErrorinstances when needed.
Modes / Variants
- Tool path: explicit query-only recall. It does not compose context from recent turns.
- Backend auto-recall has a richer query-composition path in
HindsightSessionState.beforeAgentStartPrompt(...)/maybeRecallOnAgentStart(...)andMnemopiSessionState.beforeAgentStartPrompt(...)/maybeRecallOnAgentStart(...). - Hindsight bank scoping:
global— no tag filter.per-project— separate bank id per cwd basename.per-project-tagged— shared bank id plusproject:<cwd basename>filter withtagsMatch = "any", so project-tagged and untagged global memories can both surface.
- Mnemopi bank scoping:
global— recall reads the shared bank.per-project— recall reads the project bank.per-project-tagged— recall reads the project bank and shared bank, then merges results.
- Session scope: reads cross-session memory data, using the active session's cached config and scope.
Side Effects
- Network
- Hindsight:
POST /v1/default/banks/{bank_id}/memories/recall. - Mnemopi: none unless configured local runtime providers perform embedding/LLM work during recall.
- Hindsight:
- Session state
- None on success for the explicit tool path. Unlike backend auto-recall, this tool does not update
lastRecallSnippetor refresh the system prompt.
- None on success for the explicit tool path. Unlike backend auto-recall, this tool does not update
- Background work / cancellation
- Aborts through
untilAborted(...)if the tool call signal is cancelled.
- Aborts through
Limits & Caps
- Tool availability requires
memory.backendto be"hindsight"or"mnemopi"; defaultmemory.backendis"off". - Hindsight client default budget for raw
HindsightApi.recall(...)is"mid"; this tool overrides from config. - Hindsight recall settings:
hindsight.recallBudget = "mid"hindsight.recallMaxTokens = 1024hindsight.recallTypes = ["world", "experience"]
- Mnemopi recall settings:
mnemopi.recallLimit = 8mnemopi.scopingselects which local bank(s) are searched
- The explicit tool path does not apply
hindsight.recallContextTurns,hindsight.recallMaxQueryChars,mnemopi.recallContextTurns, ormnemopi.recallMaxQueryChars; those caps only affect backend auto-recall query composition.
Errors
- Throws
Mnemopi backend is not initialised for this session.whenmemory.backend == "mnemopi"but no state exists. - Throws
Hindsight backend is not initialised for this session.whenmemory.backend == "hindsight"but no state exists. - Hindsight HTTP and fetch failures become
HindsightErrorwithstatusCodeand parseddetailswhen available. - Mnemopi recall target failures inside
collectScopedRecallResults(...)are caught per bank and logged only whenmnemopi.debugis enabled; if all targets fail, the tool can returnNo relevant memories found. - Non-
Errorfailures caught by the tool are normalized tonew Error(String(err))before rethrow.
Notes
- Shared backend details are in
docs/tools/retain.md: storage, subagent aliasing, bank scoping, mission setup, and mental-model behavior. - Hindsight mental models are not fetched by this tool. They may already be present in the agent's developer instructions because the backend caches a
<mental_models>block separately from recall results. - Mnemopi developer instructions may include a
<memories>block from auto-recall; this explicit tool does not update that block. - The tool returns memory hits; it does not synthesize across them. Use
reflectfor that path.