Directories containing .md / .mdx files to ingest as the knowledge
corpus.
init() will throw if these paths resolve to zero readable markdown
sections, because a successful router init should imply a non-empty corpus.
Optional confidenceMinimum confidence threshold for accepting a classification result. If confidence falls below this, the router may escalate to a higher tier.
0.7
Optional classifierLLM model for the classifier.
'gpt-4o-mini'
Optional classifierLLM provider for the classifier.
'openai'
Optional maxMaximum tier the classifier may assign.
3
Optional embeddingEmbedding provider name. Without one, the router takes the provider of
the first provider key set, as for the classifier, except MiniMax: it
publishes no embedding model, so a MiniMax key alone leaves embeddings on
openai. A provider other than OpenAI that has a key variable of its own
embeds with that key alone (see embeddingApiKey).
'openai'
Optional embeddingEmbedding model identifier.
'text-embedding-3-small'
Optional generationLLM model for T0/T1 generation.
'gpt-4o-mini'
Optional generationLLM model for T2/T3 generation (deep).
'gpt-4o'
Optional generationLLM provider for generation.
'openai'
Optional graphWhether to enable GraphRAG-based retrieval for tier >= 2 queries. Requires a configured GraphRAG engine.
true
Optional deepWhether to enable deep research mode for tier 3 queries. Research mode performs iterative multi-pass retrieval and synthesis.
true
Optional conversationNumber of recent conversation messages to include as context for classification and generation.
5
Optional maxMaximum estimated tokens to allocate for documentation context.
4000
Optional cacheWhether to cache query results.
When enabled, route() caches completed QueryResult objects in memory
and reuses them for identical query/history/request-option inputs until
router state changes (for example corpus refresh or retriever swap).
true
Optional availableOptional tool/capability names exposed to the classifier prompt so it can reason about what the runtime can actually do.
[]
Optional graphOptional host-provided graph expansion callback.
Provide this to replace the built-in placeholder graphExpand() branch
with a real GraphRAG or relationship-expansion implementation.
Optional rerankOptional host-provided reranker callback.
Provide this to replace the built-in lexical heuristic reranker with a provider-backed or cross-encoder reranker.
Optional verifyEnable post-generation citation verification when the router has an active embedding path and retrieved source chunks.
When enabled, route() runs CitationVerifier over the generated answer
and retrieved sources, then attaches the result to QueryResult.grounding.
If embeddings are unavailable or no sources were retrieved, verification is
skipped gracefully.
Optional deepOptional host-provided deep research callback.
Provide this to replace the built-in placeholder research branch with a
real multi-source research runtime. The sources argument receives
normalized research-source hints such as web, docs, or media,
not raw classifier retrieval labels.
Optional onHook called after classification completes. Receives the ClassificationResult for consumer integration.
Optional onHook called after retrieval completes. Receives the RetrievalResult for consumer integration.
Optional apiOptional API key override for classifier and generator LLM calls.
When omitted, a classifier or generator whose provider is not OpenAI
takes that provider's own key variable (MINIMAX_API_KEY for
minimax), and none when it is unset, so generateText resolves the
provider's credentials and no other vendor's key reaches it. An OpenAI
one prefers OPENAI_API_KEY and falls back to OPENROUTER_API_KEY with
the OpenRouter compatibility base URL.
Optional baseOptional base URL override for classifier and generator LLM providers.
When omitted, QueryRouter auto-selects the OpenRouter compatibility URL
only when OPENROUTER_API_KEY is being used implicitly for an OpenAI
classifier or generator. Any other provider takes the endpoint
generateText resolves for it (MINIMAX_BASE_URL, or MiniMax's default).
An empty or whitespace-only value counts as omitted.
Optional embeddingOptional API key override for embeddings only.
When omitted, embeddings fall back to apiKey when they use the
classifier's or the generator's provider, and never take it for another
vendor's. Without that, an embedding provider other than OpenAI that has
a key variable of its own takes that key (GEMINI_API_KEY for gemini,
MINIMAX_API_KEY for minimax), or none when it is unset, so another
vendor's key never reaches it; an OpenAI one, or one without a key
variable such as Ollama, takes the first provider key set,
OPENAI_API_KEY first and OPENROUTER_API_KEY last.
This is useful when generation uses an OpenAI-compatible endpoint like
OpenRouter but embeddings should stay on a direct OpenAI key.
Optional embeddingOptional base URL override for embeddings only.
When omitted, embeddings inherit baseUrl when they use the classifier's
or the generator's provider, unless embeddingApiKey is explicitly set,
in which case the embedding path assumes the provider's default endpoint.
An embedding provider other than OpenAI otherwise gets no URL from the
router and uses its own endpoint. If neither override is set and QueryRouter falls back to
OPENROUTER_API_KEY, it automatically uses the OpenRouter compatibility
URL for embeddings as well. An empty or whitespace-only value counts as
omitted, here and in an inherited baseUrl.
Optional githubConfiguration for background GitHub repository indexing.
When provided, the router will asynchronously index GitHub repos after
init() completes and merge the resulting chunks into the corpus.
Optional strategyRetrieval strategy configuration for the HyDE-aware query router.
Controls how the classifier selects between none, simple, moderate
(HyDE), and complex (HyDE + decompose) retrieval strategies.
QueryRouterStrategyConfig
Optional includeLoad bundled platform knowledge (tools, skills, FAQ, API reference,
troubleshooting) into the corpus during init().
When enabled, the router ships with instant knowledge about every AgentOS capability — no external docs required for platform questions.
true
Public constructor configuration for the QueryRouter pipeline.
knowledgeCorpusis required. All other fields are optional and default to the values in DEFAULT_QUERY_ROUTER_CONFIG.Example