Many AI products now use more than one language model. A large model gives the best answers, but each call is expensive. A small model is cheap and fast, but it fails more often on hard requests. A common design puts a router in front of the two models. The router sends easy requests to the small model and hard requests to the large model.
This design works, but it has a limit. The router is trained one time, and then it stays the same. The small model also stays the same. Every day, the large model solves problems that the small model cannot solve, and nobody learns from those answers. In this project, we asked a simple question: can the small model learn from the large model while the system runs, so that the router sends more work to the small model over time?
This post is based on our paper Real-time Adapting Routing (RAR): Improving Efficiency Through Continuous Learning in Software Powered by Layered Foundation Models, written with Kirill Vasilevski and Ahmed Hassan. The paper has the full method, setup, and results.
Why static routers leave money on the table
Current routers, such as those in RouteLLM, learn from a fixed training set. This causes three problems. First, the training data may not match the requests that real users send. Second, to change the routing decisions, you must collect new data and train the router again, which is expensive. Third, the small model never improves. If it fails on a type of request today, it will fail on the same type of request next month.
We think a layered system should behave more like a team. When a senior engineer solves a hard problem, a junior engineer can learn how they did it. After some time, the junior engineer can do that type of work alone.
How RAR works
RAR (Real-time Adaptive Routing) starts with a normal static router. When the router sends a request to the large model, the user gets the large model’s answer immediately. In the background, RAR also gives the same request to the small model. We call this shadow inference. Then RAR compares the two answers. There are three possible results.
- The small model is correct without help. RAR records this. Next time, similar requests go directly to the small model.
- The small model is correct only with help. RAR asks the large model to write a guide. A guide is a hint about how to think about the problem. It does not contain the answer. For example, a guide for a law question can say “Consider which constitutional principle applies here,” but it does not give the legal conclusion. If the small model gets the correct answer with the guide, RAR saves the guide.
- The small model fails even with help. RAR marks this type of request. Similar requests continue to go to the large model.
RAR stores the guides in a vector database that we call the skill and guide memory. When a new request arrives, RAR searches this memory for similar past requests. If it finds a useful guide, it gives the guide to the small model with the new request. Because a guide teaches a way of reasoning and not a specific answer, one guide can help with many related questions.
This design has an important property: RAR does not need to train any model again. All learning happens in context, through the guides and the routing memory.
What we found
We tested RAR on subsets of the MMLU benchmark. We chose questions that the small model, Mistral-7B, first answered incorrectly. These are the questions where a router normally has no choice but to call the large model. We used GPT-4o and Llama-3-70B as large models.
We compared RAR with an oracle static router. The oracle knows in advance which model will answer correctly, so it is the best possible static router.
- RAR sent 50.2% fewer requests to the large model than the oracle router (p < 0.001).
- RAR kept 90.5% of the response quality of the oracle router.
- Compared with the small model alone, quality improved by 349%. Compared with the small model with chain-of-thought prompting, it improved by 135%.
- RAR kept 89.5% of the quality of the large model alone.
We also wanted to know if the guides only help with the exact question they were written for. They do not. In professional law, the reuse of guides increased by 44.4% over four stages, so guides for one question helped with other law questions. We also saw a small transfer between subjects: guides from law questions improved results on high-school psychology and moral scenarios by 6% to 7%. Some reasoning patterns seem to be general.
Where this is useful
The most direct use is in cloud AI services. A provider can send more traffic to cheaper models, and that share grows as the system learns.
We think the idea is even more interesting on devices such as phones. A small model on the phone can handle more requests over time, with guides stored on the device. This has four advantages: private data stays on the device, answers come faster because there is no network call, cloud costs go down, and the guides become personal to each user.
Takeaways
A router does not have to be a fixed component. If it learns from the large model while it runs, the whole system becomes cheaper over time, and quality stays close to the large model. In our tests, half the calls to the large model were not necessary.
As models become larger and more expensive, we think systems will need this type of continuous learning to stay affordable. RAR shows one simple way to do it, without training a model again.
