symfonic.memory.layers.procedural.layer¶
layer ¶
ProceduralLayer -- skills, workflows, and learned procedures.
Stores skills as graph nodes with steps and context properties.
Implements BaseMemoryStore with summarize and link as no-ops.
ProceduralLayer ¶
ProceduralLayer(
graph_store: GraphMemoryStore,
dedup_threshold: float = 0.65,
embedding_provider: EmbeddingProvider | None = None,
embedding_cache: EmbeddingCache | None = None,
)
Procedural memory layer for skills and workflows.
BaseMemoryStore contract
- retrieve: queries skills by content matching
- write: stores a skill as a graph node
- summarize: returns empty string (skills are standalone)
- link: no-op (skills are standalone graph nodes)
- delete: removes a skill node from the graph
v7.3 Item 13.1: optional embedding_provider for auto-embed.
Default None preserves byte-identical pre-Item-13.1 behaviour.
When supplied, every store_skill write runs through
:func:maybe_embed before the de-dup janitor sees it -- so
procedural skills auto-embed when the caller leaves
node.embedding=None. Caller-provided embeddings always win.
The embedding_cache is shared across all three graph-backed
layers by the orchestrator.
Per-kind embedding-text rule: procedural skills always fall into
the default branch of
:func:symfonic.memory.embeddings.auto_embed.resolve_embedding_text
and embed properties['content'] (the skill's rich description)
rather than the label (which is the skill_id).
Source code in src/symfonic/memory/layers/procedural/layer.py
approve_skill
async
¶
Promote a draft skill to approved+active.
Source code in src/symfonic/memory/layers/procedural/layer.py
delete
async
¶
link
async
¶
query_skills
async
¶
query_skills(
scope: TenantScope,
query: str,
top_k: int = 5,
*,
include_drafts: bool = False,
) -> list[MemoryEntry]
Query procedural skills by word-level matching.
Uses word intersection (like SemanticLayer.query_facts) instead of exact substring matching so that "deploy the app" can find a skill whose label/content contains "deploy" or "app".
By default only active (approved) skills are returned. Pass
include_drafts=True to return skills of all statuses.
Ordering contract (v7.19.2): the returned list is sorted by
node_id so the "first matching skill" downstream
consumers rely on (precondition_gate's first-call wins,
engine _maybe_resolve_forced_tool_choice's candidate
procedure selection) is deterministic across the in-memory /
mongodb / postgres backends. The in-memory backend's
dict.values() order happens to be insertion-stable on
CPython 3.7+, but mongodb / postgres do not guarantee
registration order without an explicit sort. Sorting at
query time pins the contract at the layer boundary so any
future backend additions inherit it automatically.
v7.22 (T-7.22.12-15) multi-scope: when scope.inherits_from
is non-empty, the query fans out to [scope, *scope.inherits_from]
and merges results by shadow override on
metadata['identifier'] first, then metadata['label'].
Empty inherits_from (the common case) delegates to the
single-scope fast path unchanged. See
docs/concepts/procedural-shadow-inheritance.md for merge semantics
and cache-invariant trade-offs.
Source code in src/symfonic/memory/layers/procedural/layer.py
reject_skill
async
¶
Mark a draft skill as rejected+inactive.
Source code in src/symfonic/memory/layers/procedural/layer.py
render_for_prompt ¶
render_for_prompt(
entry: Any,
scrubber: Callable[[dict[str, Any]], dict[str, Any]]
| None = None,
) -> str
Render a procedural entry for MEMORY_CONTEXT.
v7.7: closes the v7.6.4 procedural-render-bypass structurally.
When the entry carries v7.5+ skill-aware metadata (source
starts with "authored:" OR non-empty precondition of
either str or list[str] shape), delegate to the
v7.5.1 _render_skill_for_prompt helper so PRE-FLIGHT
markers reach the prompt. Pre-v7.5 procedural entries fall
through to :func:render_legacy for byte-identical pre-v7.7
output and prompt-cache parity.
Supersedes the inline _is_skill_aware_entry predicate +
dispatch block that lived in engine.py after the v7.6.4
hotfix; the engine's render loop is now polymorphic dispatch
with zero procedural-specific knowledge.
Source code in src/symfonic/memory/layers/procedural/layer.py
retrieve
async
¶
Retrieve skills matching the query.
seed_authored_skill
async
¶
seed_authored_skill(
scope: TenantScope,
skill: MemoryEntry,
*,
source_tag: str,
precondition: str
| list[str | dict[str, Any]]
| None = None,
) -> MemoryNode
Seed a hand-authored procedural skill (Jarvio Ask 7 Option B).
Convenience wrapper around :meth:store_skill for the
domain-plugin tier of procedural memory. The result lands at
status="approved" (immediately active in
:meth:query_skills), carries the required source tag so
:class:~symfonic.memory.janitor.SemanticMerge leaves it
alone, and optionally records one or more pre-flight
preconditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
TenantScope
|
Tenant scope for isolation. |
required |
skill
|
MemoryEntry
|
The skill |
required |
source_tag
|
str
|
A discriminator the janitor uses to recognise
the authored tier. MUST start with |
required |
precondition
|
str | list[str | dict[str, Any]] | None
|
Optional pre-flight rule. Three shapes accepted (v7.6.2 -- Jarvio multi-precondition ask):
|
None
|
Returns:
| Type | Description |
|---|---|
MemoryNode
|
The persisted :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/symfonic/memory/layers/procedural/layer.py
store_skill
async
¶
Store a skill as a MemoryNode with steps and context properties.
Before inserting, the incoming skill is checked against existing procedural nodes via SemanticMerge. If a sufficiently similar node already exists the two are merged in-place and no new node is created.
The skill's metadata should include 'steps' (list[str]) and 'context' (str) keys for proper procedural storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
"draft" (inactive, pending review), "approved" (active), "rejected" (archived, will not be queried). |
'draft'
|