Module memory_inject
Expand description
Unified memory-context injection: ONE policy and ONE renderer for the memory preamble, applied at the turn engine.
Replaces the per-path inline renderers (the three loop_ sites, the
channel orchestrator’s budgeted renderer, the agent-direct loader, and
the cron/daemon pre-prompt blocks). The injection decision is keyed on
TurnOrigin (who initiated the turn), resolved by
resolve_inject_policy; the pipeline in render_memory_context is
the uniform superset of the legacy renderers’ behavior. Divergences from
any individual legacy path are deliberate and documented on the PR that
wires this module (uniform rigour: a per-path difference is an error
unless documented).
Pipeline: recall (per session, key-deduped) -> time decay OR the gated
rerank stage (rerank_enabled: over-fetched candidate pool, then
recency/importance blend + duplicate collapse + optional MMR + trim,
replacing decay on that arm) -> relevance filter -> skip set (autosave
keys/content, *_history keys, [IMAGE: markers, <tool_result
blocks, optional Conversation-category exclusion) -> budget caps (entry
count, per-entry chars, total chars) -> [Memory context] wrapper.
Exactly one MemoryRecall observer event is emitted per render,
covering all recalls.
Structs§
- Memory
Inject Config - The stable, per-agent-config half of the injection policy. Callers build
it from the agent’s resolved memory config; the per-turn half (origin,
session scope, spawn-site suppression) arrives via
resolve_inject_policy’s arguments. - Turn
Memory - The per-turn memory half carried on
ToolLoop: the handle plus the recall inputs only the entry point knows. Entry points that own a memory passSome; nested sub-turn sites passNone.
Enums§
- Inject
Policy - The resolved injection decision for one turn.
Constants§
- DEFAULT_
ENTRY_ MAX_ CHARS - Default per-entry character cap before ellipsis truncation.
- DEFAULT_
MAX_ ENTRIES - Default cap on rendered entries (from the channel renderer’s budget).
- DEFAULT_
MAX_ TOTAL_ CHARS - Default total character budget for the rendered block.
- DEFAULT_
RECALL_ LIMIT - Default recall limit per session (all legacy paths used 5).