from typesafe_sdk import Choice, TypeSafeClient client = TypeSafeClient() AGENTS = { "support": "Product issues, how-to questions, account access", "billing": "Charges, invoices, refunds, payment methods", "security": "Suspected fraud, compromised accounts, phishing reports", "engineering": "Bug reports with technical detail, API errors, outages", "sales": "Pricing, upgrades, new contracts", } ROUTE_POLICY = Policy(execute_at=0.80, confirm_at=0.55) def route(message: str) -> tuple[str | None, Action]: answer = client.system_one( state=message, questions={ "agent": Choice( instructions="Which specialist agent should own this request", criteria=AGENTS, ) }, ).answers["agent"] action = ROUTE_POLICY.decide(answer.confidence) if action is Action.EXECUTE: return answer.choice, action if action is Action.CONFIRM: # Ambiguous between a couple of agents: ask one clarifying question. top_two = sorted(answer.probabilities, key=answer.probabilities.get, reverse=True)[:2] return None, action # e.g. "Is this about a charge, or a bug in checkout?" using top_two return None, action # hand to a human or a stronger LLM router