Skip to main content
Back

Model Routing

PilotDeck Agent Series

Router is PilotDeck’s model routing engine. It automatically selects the most appropriate model based on task complexity and tries an alternate model when a request fails, reducing unnecessary model overhead.

1. Core Competencies​

Abilityfunction
TokenSaver smart downshiftAnalyze the complexity of user input, automatically select matching model levels, and use cheap models for simple tasks
Fallback fault tolerance chainWhen a rollback error occurs in a request, alternate models are tried in sequence
Scenario scene routingApply different routing policies based on Agent type (main Agent / sub-Agent)
Custom Router extensionSupport custom routing plug-ins to implement your own routing logic

2. Routing Decision Process​

PilotDeck router decision flow

  1. Custom routing: Optional plugin provides model overrides.
  2. scene recognition: Recognize explicit model, default calls, and subagent calls.
  3. TokenSaver Determination: When it is not explicitly selected or covered by a custom model, reuse the existing gear according to the enable condition, or call the judgment model.
  4. Execute decisions: Determine the model, gear and scene, and then execute the request; automatic arrangement can be enabled when the conditions are met.

When the Router is closed, the model selected by the request is inherited.

3. TokenSaver Intelligent Downshifting​

TokenSaver uses the judgment model (Judge) to analyze the task, and then selects the model corresponding to the Tier (Tier). The savings come primarily from model price differences.

3.1 Working Principle​

  1. Judge: Use a lightweight model to analyze the complexity of user requests based on recent user messages.
  2. gear matching: Select the corresponding model gear according to the judgment result.
  3. Continuous call reuse: Saved models and gears can be reused when the same task is executed continuously to reduce repeated judgments.

When there is a previous cache hit record, the Router will also compare the estimated input cost of retaining the current model (cache read vs. uncached input) and the cost of switching models to reprocess the context to avoid downshifting but increasing the input cost.

3.2 Gear Position Example​

gearApplicable tasks
simpleSimple Q&A, confirmation, lightweight file operations
mediumShort article generation, regular code generation, and reading and writing a small amount of files
reasoningSingle-agent multi-file analysis, data analysis, multi-step workflow and research
complexRequires sub-agent division of labor, professional collaboration or parallel advancement

Gears can be customized, and multiple gears can share models.complex The key is the need for division of labor, and in-depth analysis of single agents is usually classified into reasoning。

3.3 Configure TokenSaver​

The following fragments need to be merged into the existing configuration; the sample model must first be defined in the model pool.

YAML
router:
tokenSaver:
enabled: true
judge: openai/gpt-4.1-mini
defaultTier: medium
subagent:
policy: judge
tiers:
simple:
model: openai/gpt-4.1-mini
medium:
model: openai/gpt-4.1-mini
reasoning:
model: openai/gpt-4.1
complex:
model: openai/gpt-4.1

4. Fallback Fault-Tolerant Chain​

When the execution model encounters a fallback error, the Router tries other models according to the backup chain. Alternate models may also fail, eventually with an error returned to the caller.

4.1 Error Types That Can Trigger Fallback​

  • Retryable timeouts, throttling, server or network errors.
  • Errors such as quota exhaustion, model non-existence, authentication errors, etc. allow recovery by changing the model.
  • Some tool parameters are in the wrong format.

Problems that can be recovered through compression, such as context being too long, will be handled by the corresponding recovery mechanism first, and the model will not be switched directly according to ordinary errors.

4.2 Configure Fallback​

YAML
router:
fallback:
default:
- openai/gpt-4.1-mini
- deepseek/deepseek-chat

The alternative uses the configured provider/model String. By default, up to 5 alternate models are tried, available maxFallbacks Tweak; alternative chains are not enabled when explicitly specifying a model.

4.3 Retry Strategy​

Router supports transient error retry and empty response retry:

  • Instantaneous retry: For errors that meet the conditions, delay retry on the current model. The current YAML parser is not reading router.transientRetry, so it is not available as a YAML configuration item.
  • Retry with empty response: Retry results that meet the null response criteria. You can adjust the number of attempts through the following fields. The default value is 2.
YAML
router:
zeroUsageRetry:
enabled: true
maxAttempts: 2

5. Scenario Scene Routing​

sceneDescription
defaultUse the default scene model; agent.model
explicitExplicitly specify the model
subagentSub-Agent call, independent routing strategy can be applied

Subagent strategy support judge and skip:judge Entering judgment, the gear can be reused during continuous execution;skip Skip judgment. The default subagent model is given by agent.subagents.default Configure, omit or set to inherit When inheriting the default model of the main agent.

6. Auto-Orchestrate​

When the main agent hits the trigger gear, automatic orchestration can inject orchestration prompt words and adjust the tool list, allowing the main agent to plan and delegate, and the sub-agents to execute. The default trigger gear is complex。

YAML
router:
autoOrchestrate:
enabled: true
triggerTiers: [complex]

7. Statistics Panel​

After statistics are turned on, the Router records the model, gear, scenario, input and output token, cache read and time of the execution request. Costs are prioritized using available service providers to return costs, otherwise they are estimated based on model prices.

Savings are the “cost of the same recorded usage estimated at the baseline model price − execution fee”. The baseline prefers using the default scene model.

8. Event Bus​

Router sends events at key nodes for easy monitoring and debugging:

eventDescription
pilotdeck_router_decisionRouting decision completed
pilotdeck_router_fallbackSwitch alternate model
pilotdeck_router_token_saver_failedDecision failed
pilotdeck_router_zero_usage_retryRetry with empty response
pilotdeck_router_transient_retryTransient error retry
pilotdeck_router_execute_failedFinal execution failed
pilotdeck_router_custom_failedCustom routing failed

For complete fields and configuration examples, see YAML configuration file, see the operating steps Router User Guide。

Developer Showcase

View all →