Tool schemas consume uncounted context
Detect: Actual input usage exceeds the estimate before evidence is included.
Recover: Include all prompt segments and adjust reservations.
Route work according to estimated context and output demand while preserving capability, evidence quality, and a hard task-level token budget.
Token-aware routing uses input size, expected output length, context-window limits, and remaining budget to choose an execution path. The destination may be a smaller model, a larger-context model, a retrieval step, a condensation stage, or an asynchronous job. Token count is a capacity signal, not a reliable measure of task difficulty.
Estimate the complete request: system instructions, tool schemas, retrieved evidence, conversation state, and reserved output all consume capacity. A short request can require difficult reasoning, while a long document may need simple extraction. Apply capability and policy constraints before optimizing token cost.
A prototype can compare token estimates with actual usage across a representative request set. Include multilingual text, tables, and tool-heavy prompts.
Production reserves output and tool-loop capacity, rejects impossible requests early, and reconciles estimated versus billed usage. Use model-specific tokenization where available rather than a universal characters-per-token rule.
At scale, tenant budgets and provider quotas shape routing decisions. Track truncation, fallback frequency, and downstream correction cost so apparently cheap routes do not increase total cost per successful task.
Counts or estimates all input segments and reserves expected output capacity.
Removes models and paths that cannot meet task, policy, or residency requirements.
Assigns per-step token ceilings from the remaining task allowance.
Selects extraction, retrieval, condensation, or model execution using validated thresholds.
Records actual consumption and updates estimates without changing completed accounting.
flowchart LR
Q["Request and evidence"] --> E["Full prompt estimator"]
E --> C["Capability and policy filter"]
C --> S["Budget strategy"]
S --> L["Compact extraction path"]
S --> R["Retrieve relevant passages"]
S --> M["Larger context model"]
L --> U["Usage and quality ledger"]
R --> U
M --> U
B["Remaining task budget"] --> SEstimate instructions, schemas, history, evidence, and expected output using the candidate model's tokenizer.
Verify context fit and reserve capacity for mandatory validation or additional tool observations.
Exclude paths that lack required language, reasoning, structure, or data-handling support.
Choose direct execution, smaller context retrieval, condensation, or a suitable model.
Apply output ceilings and stop optional iterations before exhausting the parent budget.
Record actual tokens, quality, and fallback cost to evaluate routing economics.
Insurance · Illustrative enterprise scenario, not a reported customer outcome.
A specialty insurer receives submissions ranging from short forms to lengthy engineering reports with scanned appendices.
Routing by file size alone sends difficult short submissions to weak models and wastes large-context calls on irrelevant attachments.
The assistant must extract specified underwriting facts with source references under a per-submission processing budget.
A tokenizer-aware estimator combines document structure with capability requirements and routes relevant sections to extraction or deeper review.
If estimates understate a scanned report's token demand, the system partitions evidence by semantic section rather than silently truncating required material.
Measure tokens per accepted field, context overflow, unsupported extraction, and total fallback cost. A lower model bill is useful only if review quality remains acceptable.
| Decision | Benefit | Cost |
|---|---|---|
| Smaller-model routing | Routine extraction can consume less inference capacity. | Capability mismatch can increase corrections and retries. |
| Aggressive condensation | More requests fit available context windows. | Evidence details may be lost and require retrieval again. |
| Hard token budgets | Cost exposure becomes predictable per task. | Difficult cases may need escalation before full completion. |
Detect: Actual input usage exceeds the estimate before evidence is included.
Recover: Include all prompt segments and adjust reservations.
Detect: Usage ledger shows high total cost despite low initial spend.
Recover: Change routing thresholds using end-to-end outcomes.
Evaluate task capability independently from length.
Retrieve or partition while preserving required coverage.
Budget input, output, and follow-up observations together.