symfonic.memory.layers.procedural¶
procedural ¶
Procedural memory layer -- skills, workflows, and capability routing.
CapabilityRouter ¶
CapabilityRouter(procedural_layer: ProceduralLayer, catalog: ToolCatalog, llm: Any, max_tools: int = 5, *, observability_hook: ObservabilityHook | None = None)
Routes user queries to the appropriate tools via LLM selection.
Combines procedural memory (learned skills) with a static tool catalog to select the minimal set of tools needed for a given query.
Source code in src/symfonic/memory/layers/procedural/router.py
route
async
¶
route(scope: TenantScope, query: str, conversation_history: list[Any] | None = None, *, callback_manager: CallbackManager | None = None, run_id: str = '', model_name: str = 'procedural_router') -> RoutingResult
Route a query to appropriate tools.
Steps: 1. Query procedural layer for relevant skills. 2. Search catalog for matching tools. 3. Use LLM with structured output to select top tools. 4. Return only minimal schemas for selected tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
TenantScope
|
Tenant scope for isolation. |
required |
query
|
str
|
The user's query or request. |
required |
conversation_history
|
list[Any] | None
|
Optional recent conversation for context. |
None
|
callback_manager
|
CallbackManager | None
|
v7.4.3 (adopter Ask 5) -- when provided, fires
|
None
|
run_id
|
str
|
Engine run identifier for callback correlation. |
''
|
model_name
|
str
|
Optional model identifier stamped on the
LLMEndEvent. Defaults to |
'procedural_router'
|
Returns:
| Type | Description |
|---|---|
RoutingResult
|
RoutingResult with intent, selected tools, and reasoning. |
Source code in src/symfonic/memory/layers/procedural/router.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
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 | |
summarize
async
¶
write
async
¶
ToolCatalog ¶
Registry of available tools and capabilities.
Tools are registered dynamically and can be searched by keyword. The catalog provides tool metadata to the CapabilityRouter for LLM-driven tool selection.
Source code in src/symfonic/memory/layers/procedural/catalog.py
get ¶
list_all ¶
register ¶
Register a tool with its description and schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id
|
str
|
Unique identifier for the tool. |
required |
description
|
str
|
Human-readable description of what the tool does. |
required |
schema
|
dict[str, Any]
|
JSON schema or dict describing the tool's parameters. |
required |
Source code in src/symfonic/memory/layers/procedural/catalog.py
search ¶
Search tools by keyword matching against ID and description.
Simple case-insensitive substring matching for v1.