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 (Jarvio 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
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
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, Jarvio 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 (Jarvio ask public-render-skill-helper): promoted from
the v7.5.1 private _render_skill_for_prompt to a public
helper.
v7.7.5 (Jarvio 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.