Skip to main content

Module memory_inject

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§

MemoryInjectConfig
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.
TurnMemory
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 pass Some; nested sub-turn sites pass None.

Enums§

InjectPolicy
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).

Functions§

render_memory_context
resolve_inject_policy