LongContextRouter: Context-Aware Model Routing for Long-Horizon LLM Agents
Abstract
Choosing a model for an LLM agent requires a delicate balance between task success and execution cost. However, standard routing methods are often myopic: they rely predominantly on the initial request, missing critical requirements buried in long-horizon task documents, prior messages, and execution records. We introduce LongContextRouter, a context-aware task-level router designed to capture this extended context through overlapping-window encoding and causal Transformer aggregation. This hierarchical representation interacts with learned candidate-model embeddings to predict task success, trained via pointwise and multi-positive listwise losses. A decoupled cost head allows model selection to dynamically reflect different cost preferences without requiring the success predictor to be retrained. Evaluated across four benchmarks and five candidate models—and leveraging historical execution text during training on SWE-bench Pro—LongContextRouter achieves 76.44% sample-average task success. This outperforms the strongest fixed-model baseline by 4.19 percentage points while simultaneously reducing recorded model-execution costs by 32.0%.
Then back it, or bet against it.
Related papers
Open the market on this paper to see 7 more related papers.