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
amend_skill
async
¶
amend_skill(scope: TenantScope, node_id: NodeId, *, steps: Any = None, properties: dict[str, Any] | None = None, active: bool | None = None, toggle_active: bool = False) -> MemoryNode
Apply a UI edit through the lifecycle lock without bypassing review.
HTTP callers can edit content metadata and disable an approved skill, but cannot mint review authority or promote a draft by writing graph fields directly. The latter remains the explicit review transition.
Source code in src/symfonic/memory/layers/procedural/layer.py
approve_skill
async
¶
approve_skill(scope: TenantScope, node_id: NodeId, *, action_tool: str | None = None, precondition: Any = None) -> MemoryNode
Apply a human approval and any binding in one locked transition.
Source code in src/symfonic/memory/layers/procedural/layer.py
decide_draft_skill
async
¶
decide_draft_skill(scope: TenantScope, node_id: NodeId, *, status: str, action_tool: str | None = None, precondition: Any = None, expected_source: object | None = None, expected_source_present: bool = True, expected_action_tool: str | None = None, expected_action_tool_present: bool = False, actor: str | None = None) -> MemoryNode | None
Apply an opt-in automated decision only if the row remains a draft.
This is intentionally limited to one process: its value is that a policy and the human admin door composed over this same layer cannot race a stale decision past a review. Multi-process automation needs a backend compare-and-set port before it can make that claim.
Source code in src/symfonic/memory/layers/procedural/layer.py
deduplicate_skills
async
¶
deduplicate_skills(scope: TenantScope, *, audit: Any = None, context: Any = None) -> tuple[int, list[MemoryNode]]
Refuse an unattributed pass before the lock; the janitor gates and audits.
The atomic gate and the one awaited intent live at the janitor's shared boundary, so this layer neither re-gates nor records its own intent.
Source code in src/symfonic/memory/layers/procedural/layer.py
delete
async
¶
delete_skill
async
¶
Delete through the same writer gate as review and deduplication.
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.
retrieve_report
async
¶
Opt-in per-row origin and queried scope; no routing policy change.
Source code in src/symfonic/memory/layers/procedural/layer.py
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 (adopter 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 -- adopter 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_legacy_consolidated_skill
async
¶
store_legacy_consolidated_skill(scope: TenantScope, skill: MemoryEntry, *, status: str) -> MemoryNode
Persist one retired-engine terminal with explicit compatibility intent.
The compatibility writer is the sole minting path for the automatic provenance marker. Generic writes (including HTTP creation) retain their supplied lifecycle but remain unsealed historical terminals.
Source code in src/symfonic/memory/layers/procedural/layer.py
store_phase_12_skill
async
¶
Store a replayable Phase-12 draft without trusting entry metadata.
Source code in src/symfonic/memory/layers/procedural/layer.py
store_skill
async
¶
store_skill(scope: TenantScope, skill: MemoryEntry, *, status: str = 'draft', _lifecycle_origin: str | None = None, _return_created: bool = False) -> MemoryNode | tuple[MemoryNode, bool]
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'
|
_return_created
|
bool
|
Internal native-create option; report the insert-versus-merge decision made under the writer lock. |
False
|
Source code in src/symfonic/memory/layers/procedural/layer.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |