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 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 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 symfonic/memory/layers/procedural/layer.py
approve_skill
async
¶
Promote a draft skill to approved+active.
Source code in 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 symfonic/memory/layers/procedural/layer.py
reject_skill
async
¶
Mark a draft skill as rejected+inactive.
Source code in 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 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 (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 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'
|
Source code in symfonic/memory/layers/procedural/layer.py
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 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 symfonic/memory/layers/procedural/catalog.py
search ¶
Search tools by keyword matching against ID and description.
Simple case-insensitive substring matching for v1.