Smart Router (Tool/Web Routing)¶
Last Verified: February 2026
Scope: Routing tool/web queries to the cheapest viable data source.
This document is about SmartRouter (web/tools). It is not the same as SmartMessageRouter (message routing between MiniApps/workflows/conversation).
Goals¶
- Decide when a user request needs current info (web search) vs internal context.
- Route to the lowest-cost provider that can satisfy the request.
- Provide structured metadata (source, cost) and a clean fallback to GPT‑5 generation.
Key files¶
- Router:
app/orchestrator/smart_router.py - Analyzer (LLM-assisted intent/complexity):
app/orchestrator/query_analyzer.py - Providers + adapters:
app/orchestrator/providers/ - Perplexity client (httpx + tracing):
app/utils/perplexity_client.py
Cost / source hierarchy (current)¶
SmartRouter attempts (cheapest → most expensive):
- Free APIs (e.g., weather)
- OAuth APIs (calendar/email, if connected)
- Parallel Search (if configured) — deep/multi-hop, structured research
- Perplexity (if configured) — fast web search
- GPT‑5 fallback — no web call (router returns
response=None)
Provider availability is driven by env vars:
- PARALLEL_API_KEY enables Parallel provider
- PERPLEXITY_API_KEY enables Perplexity provider
Execution flow (simplified)¶
QueryAnalyzer.analyze()classifies:- complexity: simple / multi-intent / multi-step / ambiguous / conversational
-
per-intent
data_sourcerecommendations -
SmartRouter.route(): - handles ambiguous/multi-intent logic
- executes the recommended provider (with fallback to Perplexity when appropriate)
- returns:
- or returns GPT‑5 fallback signal:
Where it’s used¶
The tool/router layer is invoked by the orchestrator when a message requires external info/tooling:
- app/orchestrator/tool_executor.py