TL;DR
SWE-Router is a novel framework for optimizing the cost of agentic software engineering (SWE) tasks by intelligently routing them between "cheap" and "expensive" LLMs. Unlike traditional routers that guess a task's difficulty from the initial prompt alone, SWE-Router lets a cheap model explore for a few turns first, using the resulting "partial trajectory" to make a much more informed decision about whether to escalate to a frontier model.
What Problem Does This Paper Address?
In the world of agentic software engineering, we use LLMs to autonomously browse repositories, run tests, and write patches. While frontier models (like Gemini 1.5 Pro or GPT-4o) are highly capable, they are also incredibly expensive to run for every single bug fix.
The standard solution is LLM routing: using a smaller model to predict if a task is "easy" enough for a cheap LLM or "hard" enough to require a frontier model. However, the authors identify a "Bayes-error floor" in existing routers. A bug report (the prompt) is often ambiguous; a simple-sounding issue might require a massive multi-module refactor, while a complex-sounding one might be a one-line typo. You often can't tell the difference until you actually start digging into the code.
Methods
The core innovation of SWE-Router is Value-Based Temporal Routing. Instead of making a snap judgment at turn zero, the system follows a three-step process:
- Exploration: A "weak" (cheap) model ($m_1$) runs for a fixed number of turns ($K$, typically 3-4). During these turns, it performs actions like listing files or searching for keywords.
- The Value Head: A specialized classifier (the authors fine-tuned a Qwen2.5-Coder-7B model) reads this "partial trajectory"—the thoughts, actions, and environment observations (like stack traces or file contents). It then predicts the probability that the weak model will successfully solve the task.
- Routing Decision: If the predicted success is high, the weak model continues. If it's low, the system "escalates," restarting the task from scratch using a "strong" (expensive) model ($m_2$).
The authors also provide a formal Bayes-optimality theorem (Theorem 4.1), proving that conditioning on the agent's own intermediate observations is mathematically guaranteed to be as good as or better than prompt-only routing.
Datasets
The researchers evaluated their approach using:
- SWE-Bench Verified: A curated subset of real-world GitHub issues used to test LLM coding capabilities.
- SWE-Smith: A large-scale synthetic dataset used for training the value head.
- New Contribution: The authors released a multi-LLM trajectory dataset, providing the community with the raw data of how different models (GPT-4o-mini, DeepSeek-V3.2, Gemini-1.5-Pro) navigate these tasks.
Key Insights and Ideas
- Observations are the Signal: The most valuable information for routing isn't in the bug report; it's in the feedback from the environment. A failed test or a specific file structure reveals the task's true difficulty far better than a human-written description.
- Exploration is Cheap: The early turns of an SWE agent are usually spent on localization (finding the bug). This "legwork" is computationally cheaper than the final patch synthesis, making it the perfect task for a weak model.
- The Synergy Effect: Interestingly, the SWE-Router curve occasionally passes above the "all-strong" model performance. This suggests that by correctly routing "easy" tasks to the weak model, the system avoids instances where the strong model might over-complicate a simple fix and fail.
Key Results
The authors tested two pairs: GPT-4o-mini $\rightarrow$ Gemini-1.5-Pro and DeepSeek-V3.2 $\rightarrow$ Gemini-1.5-Pro.
- Performance Boost: SWE-Router improved Route-AUC (a metric measuring the trade-off between cost and success) by +12 to +15 percentage points over the best prompt-only baselines.
- Cost Efficiency: On SWE-Bench Verified, the system achieved significant cost reductions while maintaining the majority of the frontier model's performance.
- Trajectory Matters: The non-temporal version of their router ($K=0$, prompt-only) performed significantly worse, confirming that the "temporal" aspect—watching the model work—is the secret sauce.
Limitations and Future Work
- The "Restart" Penalty: Currently, when the router decides to escalate, it restarts the strong model from the original prompt. This discards the work the weak model did. While the authors note that "warm-starting" the strong model on the weak model's reasoning can sometimes introduce bias or errors, finding a way to pass on useful "discovery" information without the "mistakes" is a clear next step.
- Safety and Misuse: The authors acknowledge that trajectory-based routing could potentially be used to bypass safety filters that are more robust in frontier models.
- Multi-Objective Routing: Future iterations could look at routing not just for cost and performance, but also for latency or safety simultaneously.
Summary updated