symfonic.memory.render¶
render ¶
Shared MEMORY_CONTEXT render helpers.
v7.7 (Jarvio procedural-render-bypass follow-up). The engine's
hydrate render loop used to enumerate a fixed metadata key set inline
at engine.py:5237-5345 (description, name, role,
properties). v7.6.4 patched the procedural case via an inline
dispatch; v7.7 finishes the architecture by moving the legacy render
shape into this module and adding a render_for_prompt protocol on
BaseMemoryStore so each layer owns its render contract.
Layers that don't need a layer-specific shape delegate to
:func:render_legacy -- this preserves the pre-v7.7
[layer] content (k=v) output byte-identically so prompt-cache
parity holds for adopters who haven't opted into any new metadata
surface.
The credential-scrubber callable threads in as the second positional
argument so v6.1.9 F2 defense-in-depth (scrub credential-shaped keys
from properties dicts BEFORE formatting) still runs through every
render path. None is permitted -- it disables scrubbing for the
common case where no credential pattern is configured.
render_legacy ¶
render_legacy(
entry: Any,
scrubber: Callable[[dict[str, Any]], dict[str, Any]]
| None = None,
) -> str
Render an entry in the pre-v7.7 [layer] content (k=v) shape.
Body ported byte-identically from engine.py:5275-5345 so any
layer delegating here emits the same string the engine used to
emit before the polymorphic-dispatch refactor. This is the
prompt-cache-parity guarantee for adopters who haven't migrated
to a layer-specific render shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Any
|
A retrieved memory entry. The helper reads
|
required |
scrubber
|
Callable[[dict[str, Any]], dict[str, Any]] | None
|
Optional credential-scrubber callable. When the
entry's metadata carries a |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The fully-rendered line including the leading |
str
|
tag. Multi-line content stays one line in the rendered |
str
|
output (the legacy shape never inserted line breaks). |
Source code in src/symfonic/memory/render.py
strip_memory_label_prefix ¶
Strip a leading AGENT_IDENTITY: / SOUL: token from content.
Public successor to the v6.x _strip_memory_label_prefix helper
that lived in engine.py:389-402. Moved here in v7.7 so per-
layer renderers can apply the same Defect A defense-in-depth
without depending on the engine module.
Returns the content unchanged when no prefix is found OR when the input is empty.