symfonic.memory.layers.procedural.router¶
router ¶
CapabilityRouter -- LLM-driven tool selection from procedural memory.
Queries the PROCEDURAL layer for relevant skills, searches the ToolCatalog, and uses the LLM to select the minimal set of tools needed for a request.
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 | |
RoutingResult ¶
Bases: BaseModel
Result of capability routing.
Contains the detected intent, selected tool IDs and their minimal schemas, and the reasoning behind the selection.
render_skill_for_prompt ¶
Format a single skill for the router prompt's RELEVANT SKILLS section.
Three metadata['precondition'] shapes are honoured:
- Non-empty
str(v7.5.1 shape) -- appended as a single indentedPRE-FLIGHT:line. Renders byte-identical to pre-7.6.2 output; prompt-cache parity is preserved. - Non-empty
list[str](v7.6.2 shape, adopter multi-precondition ask) -- one indentedPRE-FLIGHT:line per entry, in supplied order. Empty / non-string entries are skipped silently. The router prompt's ordering clause atprompts/router.txttreats every PRE-FLIGHT line as a hard ordering constraint overrequired_tool_ids. - Anything else (
None, empty string, whitespace-only, non-string non-list metadata) -- the bullet renders single-line and no PRE-FLIGHT marker is emitted.
Skills without preconditions render byte-identical to pre-7.5.1 so prompt-cache parity holds for adopters who never use the authored tier.
v7.7.4 (adopter ask public-render-skill-helper): promoted from
the v7.5.1 private _render_skill_for_prompt to a public
helper.
v7.7.5 (adopter L2-prose architectural ask, Option D): bare-
identifier preconditions render with a strictly stronger imperative
phrasing -- PRE-FLIGHT REQUIRED: BEFORE calling \`X\`, YOU MUST
first call \`Y\`. -- to lift compliance on the L2 path for
adopters who don't opt into the v7.7.5 L1 render knob. Free-text
preconditions fall through to the v7.5.1 PRE-FLIGHT: phrasing
byte-identical (free text cannot be safely rewritten without
inventing tool names). The bare-id discriminator is shared with
the v7.7.4 gate via _extract_bare_identifier; the action tool
is resolved via _skill_action_tool. Skills with no resolvable
bare-id action tool fall back to free-text phrasing even when the
precondition itself is a bare id -- refusing to invent.