Routing — pick the path before doing the work — step 9 of 9
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a routing layer that wraps the agent loop you
already know. Write run_router(question) that:
- Calls
fake_classifier(question)and normalizes the output (.strip().lower()). - Looks up the normalized category in
SPECIALISTS. If missing, fall back to"general". - Calls the specialist function with
question. Each specialist returns a dict shaped like{"answer": "...", "tools_used": N}. - Returns a single dict:
{"category": <normalized category used>, "answer": <specialist's answer>, "tools_used": <specialist's count>}.
Note: the category used is what you actually dispatched to —
that's "general" when the classifier produced something unknown,
not the raw classifier string.
The script runs four cases. Expected output:
category=billing tools=1 answer=refunded
category=technical tools=2 answer=restarted
category=general tools=0 answer=hours: 9-5
category=general tools=0 answer=fallback answer
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a routing layer that wraps the agent loop you
already know. Write run_router(question) that:
- Calls
fake_classifier(question)and normalizes the output (.strip().lower()). - Looks up the normalized category in
SPECIALISTS. If missing, fall back to"general". - Calls the specialist function with
question. Each specialist returns a dict shaped like{"answer": "...", "tools_used": N}. - Returns a single dict:
{"category": <normalized category used>, "answer": <specialist's answer>, "tools_used": <specialist's count>}.
Note: the category used is what you actually dispatched to —
that's "general" when the classifier produced something unknown,
not the raw classifier string.
The script runs four cases. Expected output:
category=billing tools=1 answer=refunded
category=technical tools=2 answer=restarted
category=general tools=0 answer=hours: 9-5
category=general tools=0 answer=fallback answer
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.