Agentic Engineering from First Principles All chaptersLecturesLabDownload the book
Part III · Making Agents Think and Work

Chapter 15: Routing

Central questionHow should an agent decide which capability, workflow, or model should handle a task?

Lecture

Chapter principle

Routing maps an observed task, plus system state, through a routing policy to a capability, model or workflow, and then to an outcome. So here is the principle from this chapter. Routing is resource allocation under uncertainty. Judge it by downstream outcomes, not by the sophistication of the router.

Key takeaways

Experiments

Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.

Experiment 27: Sending each task to the right place

Can a router send each request to the right place, and what does a wrong choice cost?

Seven requests must each go to one of three routes: math (a calculator), policy (answers from company policy documents) or write (drafting text). Three routers are compared: simple keyword rules; a real model given plain descriptions of the routes; and the same model given a sharper description of the policy route. Mistakes have a cost: a policy question sent elsewhere costs 5, any other mistake costs 1. This is a recorded run of a real model. A new run may route differently.

Experiment 28: Cheap model or strong model?

Can a system save money by using a cheap model when it is good enough?

Two real models answer five sums without a calculator. FAST is a small model costing 1 unit per call; STRONG is a larger one costing 10. The units are illustrative, not prices. Three sums are easy; the two with brackets are hard for FAST. Five strategies are compared: always FAST, always STRONG, an oracle that knows which sums are hard, a router that guesses from the length of the sum, and a cascade that tries FAST first and asks STRONG only when an exact check fails. This is a recorded run of real models. A new run may differ.

All the code for this chapter: github.com/agentic-engineering-book/code

This is Chapter 15 of Agentic Engineering from First Principles: thirty chapters, a case study and fifty-nine executable experiments, from a single model call to controlled, self-improving agents.
Download the bookBrowse all chapters
← Chapter 14: Search and Tree ReasoningChapter 16: Parallelism →