A router reads each message and hands it to the right specialist: billing or tech support.
AI · intermediate · 6 min · 20 steps · free
def billing_agent(message):
return 'Billing: your last invoice was 499 rupees.'
def tech_agent(message):
return 'Tech: try restarting the router.'
# Stands in for a small, fast model that only decides who should answer.
def router(message):
if 'bill' in message or 'invoice' in message:
return billing_agent
return tech_agent
for message in ['why is my bill so high', 'the internet is down']:
specialist = router(message)
print(specialist(message))billing_agent(). Its body does not run yet: it runs each time the function is called.tech_agent(). Its body does not run yet: it runs each time the function is called.router(). Its body does not run yet: it runs each time the function is called.message is created with the value 'why is my bill so high'.router(), with message = 'why is my bill so high'. It gets its own names.billing_agent.specialist now holds the billing agent itself.billing_agent(), with message = 'why is my bill so high'. It gets its own names.'Billing: your last invoice was 499 rupees.'.billing_agent() has finished, so its names are gone. It prints Billing: your last invoice was 499 rupees..message changes from 'why is my bill so high' to 'the internet is down'.router(), with message = 'the internet is down'. It gets its own names.tech_agent.router() has finished, so its names are gone. The value it returned, function tech_agent(), is stored in specialist.tech_agent(), with message = 'the internet is down'. It gets its own names.'Tech: try restarting the router.'.tech_agent() has finished, so its names are gone. It prints Tech: try restarting the router..for message in ['why is my bill so high', 'the internet is down'].Answer: More tools and rules mean more mistakes
Answer: An agent (function)
← Agentic RAG: Rewrite, Search, Decide · Guardrails: Injection and Allow-lists →