One layer, routed by task
The web chat has used the AI SDK since Day 10, while each of the other call sites chose a model size for itself. Today every call site names a task instead, and one table chooses the model. The curriculum names 4 tasks: chat, extraction, summarization and title generation. WorkBot has no titles to generate, but it does have triage, reading, research, page generation and a judge, so its table has 8 rows.
Study first
- Where the providers differ: read the 2
streamfunctions ofsrc/lib/providers.tsside by side,anthropic()andopenai(), each about 60 lines against the raw SDK. Anthropic puts the system prompt besidemessages, and OpenAI puts it besideinput. In Anthropic's API, a tool call is atool_useblock, after which the model stops withstop_reason: "tool_use"and the caller runs the tool. In OpenAI's, a tool call is afunction_callitem, and the loop ends when a completed response holds none. Anthropic takes a tool result as a block in the next user message, while OpenAI takes it as an item appended after the model's own items are replayed. The token fields and the reasoning effort setting have different names, anddocs/routing.mdputs all of these differences in a table. - What the AI SDK covers, and what leaks through:
generateTextandstreamTexthide the request shape, the tool loop and structured output. Both providers constrain structured output to a schema, each with its own strictness. Caching controls stay provider-specific, such asproviderOptions.anthropic.cacheControlon the chat route's system prompt, and so does reasoning effort. The terminal chat from Day 6 uses the raw SDKs, so the wire format stays visible. - Measure behavior differences, such as instruction following, refusal boundaries and verbosity, instead of reading about them. The golden set from Day 19 holds refusal and escalation cases, so a provider's refusal boundary shows in its chat score.
- An open-weight model served by an inference provider is one more provider behind the same interface, and one more column in the table. The same evals answer whether a route can use it, while where it fits is the business's question, such as on-premise hosting, data residency or cost at volume.
- Keep model identifiers in configuration, never in application code. A route is a provider and a size, such as
anthropic/small, resolved against the provider's model table, and the ids and prices stay inproviders.ts.
Build
- Write
src/lib/routing.tswith 8 tasks: chat, generate, research, summarize, extract, triage, read and judge.routesmaps each task to its routes, in order. AddmodelOf(route)andmodelFor(task), and moveaiModel(provider, id)here from the chat module, still traced. - Make every call site name its task. In the chat route, that is the summary, the answer and the memory extraction. Elsewhere it is the generate, intake, voice and documents routes, the approval workflow, the request actions and the CLIs. Then delete the size-picking function,
chatModel. - Add
ROUTEStoconfig.ts, astask=provider/sizepairs. The routing module checks them when it loads, which innext devis the first request that needs a model. A pair that names no task or no route throws, with the list of both, instead of routing to a default, and an emptyROUTESis no override. RemoveCHAT_PROVIDERandCHAT_MODEL. - Write tests that every route in the table resolves to a provider's model, and that a bad pair throws. Test that an override replaces a task's first model and keeps the rest behind it.
Done when
grep -rn chatModel src clifinds nothing, andpnpm testpasses.ROUTES=chat=anthropic/medium pnpm devfails the first request that needs a model, and names the tasks and routes it accepts.- After a chat turn and a dashboard generated at
/dashboards,/admin/tracesshows the small model for the chat and the large one for the generation.
Technical notes
- A route is
${ProviderName}/${Size}, a template literal type. The compiler checks the table, andallRoutesis built from the 2 lists at run time for theROUTEScheck. - A route's models form a chain, in which each model is the fallback of the one before (next part). The chain's
modelIdis its first model's, and the traces page groups by it. The model that answered is in the response, asresponse.modelId, and each model in the chain writes its own trace row. - Two call sites are not routed. The Claude Agent SDK pipeline (Day 12) runs on the Claude Code sign-in, and the framework comparison (Day 23) compares one model on purpose.



