Tier 3: LLM Classification
Purpose and Scope
This document covers Tier 3: LLM Classification in the Universal Router's tiered routing system. Tier 3 is the final fallback mechanism that uses a workspace-configured Large Language Model to dynamically select the most appropriate agent for a request when all prior routing tiers fail to produce a match.
For information about the overall routing architecture, see Routing Architecture. For details on prior tiers, see Tier 0: User Overrides, Tier 1: Cache Lookup, and Tier 2: Rule-Based Routing.
Overview
Tier 3 LLM Classification is invoked when Tiers 0-2 (user overrides, cache, rules, and intent matching) fail to route a request. Unlike static rule-based routing, Tier 3 uses semantic understanding to select the most appropriate agent by analyzing the request content against agent descriptions and capabilities.
The classification process produces two outputs:
Agent ID: The selected agent to handle the request
Confidence Score: A float between 0.0 and 1.0 indicating classification certainty
Based on the confidence score, the router makes a routing decision:
High confidence (
>= 0.5): Route directly to the selected agent (route_type='agent')Low confidence (
< 0.5): Return for orchestrated workflow decomposition (route_type='orchestrate')
Sources: orchestrator/core/routing/engine.py:332-433
Tier 3 Invocation Flow
Tier 3: LLM Classification Sequence Diagram
Sources: orchestrator/core/routing/engine.py:332-433, orchestrator/core/routing/engine.py:78-144
Confidence Threshold and Routing Logic
The confidence threshold determines whether the router trusts the LLM's classification enough to route directly to an agent, or whether the request requires full orchestrated workflow decomposition.
>= 0.5
agent
Direct routing to selected agent
Yes
< 0.5
orchestrate
Return for workflow decomposition
Yes
None (parse failed)
None
Store as UnroutedEvent
No
Configuration:
Sources: orchestrator/core/routing/engine.py:44-46, orchestrator/config.py:144
Agent Description Building
Before invoking the LLM, the router builds structured descriptions of all active agents in the workspace, including their assigned Composio app integrations.
Agent Query
Description Structure
App Assignment Resolution
For each agent, the router queries AgentAppAssignment to retrieve assigned app names:
Agent Description Building Process
Sources: orchestrator/core/routing/engine.py:435-458
Classification Prompt Construction
The router builds a lightweight prompt that presents the request content and available agents to the LLM for classification.
Prompt Template (Hardcoded Fallback)
PromptRegistry Integration
The router first attempts to load the prompt from the admin-editable PromptRegistry using slug "routing-classifier". This allows platform administrators to customize the routing prompt without code changes.
Sources: orchestrator/core/routing/engine.py:460-493
LLM Invocation
The router invokes the LLM via the LLMManager singleton, which handles provider selection, credentials, and API communication.
LLMManager Integration
The LLMManager uses the workspace's configured LLM provider and model. The service_name="orchestrator" parameter ensures the correct service-level configuration is loaded.
Workspace LLM Configuration
Each workspace can configure its own LLM provider and model via system settings. The Tier 3 classification uses this workspace-specific configuration, not a global default.
Sources: orchestrator/core/routing/engine.py:370-376
Response Parsing and Validation
After receiving the LLM response, the router parses the JSON output and validates the agent ID against the workspace's active agent list.
Expected Response Format
Parsing Logic
Response Parsing Flow
Validation Rules
JSON format
Must be valid JSON
Return (None, 0.0)
agent_id field
Must be present
Return (None, 0.0)
agent_id type
Must be convertible to int
Return (None, 0.0)
agent_id existence
Must be in workspace's active agent list
Return (None, 0.0)
confidence field
Optional, defaults to 0.0
No failure
confidence type
Must be convertible to float
No failure
confidence range
Clamped to [0.0, 1.0]
No failure
Sources: orchestrator/core/routing/engine.py:495-533
Routing Decision Construction
Based on the parsed confidence score, the router constructs a RoutingDecision object with the appropriate route_type.
High Confidence Decision (>= 0.5)
This decision routes the request directly to the selected agent for immediate execution.
Low Confidence Decision (< 0.5)
This decision signals that the request should be sent for orchestrated workflow decomposition, where multiple agents may collaborate to handle the request.
RoutingDecision Data Model
Sources: orchestrator/core/routing/engine.py:386-428, orchestrator/core/models/routing.py
Caching Strategy
Both high-confidence and low-confidence decisions are cached in Redis via the RoutingCache to avoid redundant LLM calls for similar requests.
Cache Key Format
Where normalized_content is a lowercase, whitespace-normalized version of the request content.
Cache Population
Cache TTL
The default cache TTL is 24 hours, configurable via ROUTING_CACHE_TTL_HOURS:
Even low-confidence results are cached to prevent repeated LLM classification attempts for inherently ambiguous requests.
Sources: orchestrator/core/routing/engine.py:403-409, orchestrator/core/routing/engine.py:420-427, orchestrator/config.py:143
Error Handling and Unrouted Events
When all tiers fail to produce a routing decision (including Tier 3 LLM classification), the router stores an UnroutedEvent record for later analysis.
Failure Scenarios
No active agents in workspace
logger.warning
Return None
Empty LLM response
logger.warning
Return None
JSON parse error
logger.warning
Return None
Invalid agent_id
logger.warning
Return None
LLM exception
logger.exception
Return None
UnroutedEvent Storage
UnroutedEvent Table Schema
Platform administrators can query the unrouted_events table to identify patterns in routing failures and improve routing rules or agent descriptions.
Sources: orchestrator/core/routing/engine.py:539-555, orchestrator/core/models/routing.py
Decision Logging
Every successful routing decision (including Tier 3 classifications) is logged to the routing_decisions table for analytics and debugging.
RoutingDecisionRecord Schema
Logging Implementation
Sources: orchestrator/core/routing/engine.py:560-585, orchestrator/core/models/routing.py
Configuration Reference
Environment Variables
ROUTING_LLM_CONFIDENCE_THRESHOLD
float
0.5
Minimum confidence for direct agent routing
ROUTING_CACHE_TTL_HOURS
int
24
Cache lifetime for routing decisions
LLM_PROVIDER
str
(system setting)
Workspace LLM provider
LLM_MODEL
str
(system setting)
Workspace LLM model
Config Class Properties
Sources: orchestrator/config.py:143-144, orchestrator/config.py:88-106
Data Structure Relationships
Tier 3 Data Structure Relationships
Sources: orchestrator/core/routing/engine.py:332-585, orchestrator/core/models/routing.py, orchestrator/core/models/core.py, orchestrator/core/models/composio_cache.py
Integration with Other Systems
PromptRegistry Integration
Tier 3 integrates with the admin-editable PromptRegistry for customizable classification prompts. See System Prompt Management for details on editing prompts via the admin interface.
Sources: orchestrator/core/routing/engine.py:475-483
LLM Analytics Tracking
Every LLM call made by Tier 3 is tracked via the UsageTracker for cost analytics. See LLM Usage Tracking for details on tracking and cost calculation.
Sources: orchestrator/core/llm/manager.py
Composio App Integration
Agent descriptions include assigned Composio app names to help the LLM understand each agent's tool capabilities. See Tool Assignment for details on agent-app associations.
Sources: orchestrator/core/routing/engine.py:440-448, orchestrator/core/models/composio_cache.py
Last updated

