4.7 KiB
4.7 KiB
reflect
Ask the Hindsight server to synthesize an answer over the active memory bank.
Source
- Entry:
packages/coding-agent/src/tools/hindsight-reflect.ts - Model-facing prompt:
packages/coding-agent/src/prompts/tools/reflect.md - Key collaborators:
packages/coding-agent/src/hindsight/bank.ts— best-effort bank mission initialization.packages/coding-agent/src/hindsight/state.ts— session state, shared bank scope, recall/reflect config.packages/coding-agent/src/hindsight/client.ts— HTTPreflectcall and error mapping.docs/tools/retain.md— shared backend, storage, seeding, and mental-model bootstrap.
Inputs
| Field | Type | Required | Description |
|---|---|---|---|
query |
string |
Yes | Question to answer from long-term memory. |
context |
string |
No | Extra guidance sent to the Hindsight reflect endpoint. |
Outputs
Returns a single-shot tool result:
content[0].type = "text"content[0].text = response.text?.trim() || "No relevant information found to reflect on."details = {}
The tool returns the Hindsight server's synthesized text directly; it does not expose raw recall hits.
Flow
HindsightReflectTool.createIf(...)only exposes the tool whenmemory.backend == "hindsight".execute(...)runs underuntilAborted(...).- It reads the active
HindsightSessionState; missing state throwsHindsight backend is not initialised for this session. - Before reflecting, it calls
ensureBankMission(...)with the currentbankId, config, and process-localmissionsSet. ensureBankMission(...)best-effortPUTs/v1/default/banks/{bank_id}withreflect_missionand optionalretain_missionexactly once per bank/process; failures are swallowed.- It calls
state.client.reflect(...)with the modelquery, optionalcontext, configured recall budget, and bank-scope tag filters. HindsightApi.reflect(...)POSTs/v1/default/banks/{bank_id}/reflectand defaults its own budget to"low"when callers omit one; this tool always passes the configured budget.- Blank or whitespace-only responses are replaced with
No relevant information found to reflect on. - Failures are logged with
logger.warn("reflect failed", ...)and rethrown.
Modes / Variants
- Tool path: one reflect request, optionally focused by
context. - Bank scoping is inherited from the active
HindsightSessionState:global— no tag filter.per-project— separate bank id per cwd basename.per-project-tagged— shared bank id plusproject:<cwd basename>filter withtagsMatch = "any".
- Session scope: reads cross-session server-side memories, but does not persist local output.
Side Effects
- Network
- Optional
PUT /v1/default/banks/{bank_id}fromensureBankMission(...). POST /v1/default/banks/{bank_id}/reflectviapackages/coding-agent/src/hindsight/client.ts.
- Optional
- Session state (transcript, memory, jobs, checkpoints, registries)
- Reads session-held bank scope and config only. Does not update
lastRecallSnippet, the mental-model cache, or the retain queue.
- Reads session-held bank scope and config only. Does not update
- Background work / cancellation
- Aborts through
untilAborted(...)if the tool call signal is cancelled.
- Aborts through
Limits & Caps
- Tool-level params: only
queryis required;contextis optional. - Default budget setting comes from
hindsight.recallBudgetinpackages/coding-agent/src/config/settings-schema.ts; default"mid". reflectitself has no client-side token cap parameter here; unlikerecall, the tool does not passmaxTokens.- Mission initialization tracks up to
MISSION_SET_CAP = 10_000bank ids inpackages/coding-agent/src/hindsight/bank.ts, then drops the oldest half of the sorted set.
Errors
- Throws
Hindsight backend is not initialised for this session.when no state exists. - HTTP and fetch failures become
HindsightErrorfrompackages/coding-agent/src/hindsight/client.tswithstatusCodeand parseddetailswhen available. ensureBankMission(...)failures are silent to the tool caller; only the later reflect request can fail visibly.- Non-
Errorfailures are normalized tonew Error(String(err))before rethrow.
Notes
- Shared backend details are in
docs/tools/retain.md: server-side storage, subagent aliasing, bank scoping, seed mental models frompackages/coding-agent/src/hindsight/seeds.json, and mental-model prompt injection. reflectdoes not read the cached<mental_models>block directly. It queries the Hindsight server over the bank contents. The same session may also have separate mental-model context injected into its developer instructions.- Reflect mission and retain mission are bank-level server settings, not per-request payload. The tool just ensures they are present best-effort before reflecting.