Lesson 3: Decisions and Routing
Your classifier returns a priority and confidence. Now you need different things to happen for different results.
Urgent and confident? Notify the team. Needs action but not urgent? Create a task. Newsletter? Archive it. Uncertain about anything? Send it to a human.
The Decide Step
Add a decide step after classification:
machine classify_email
accepts subject as text, is required sender as text, is required body as text
responds with routed_to as text priority as text confidence as number reason as text
implements ask classify, using: "anthropic:claude-haiku-4" with task "Classify this email.\n\nFrom: ${input.sender}\nSubject: ${input.subject}\nBody: ${input.body}" returns priority as text, is required, choices: ["urgent", "today", "later", "ignore"] confidence as number, is required, range: [0.0, 1.0] action as text, is required reason as text
decide route if classify.confidence < 0.7 {routed_to: "human_review", priority: classify.priority, confidence: classify.confidence, reason: "Low confidence: " + classify.reason} else if classify.priority == "urgent" {routed_to: "notify_team", priority: "urgent", confidence: classify.confidence, reason: classify.reason} else if classify.action == "create_task" {routed_to: "create_task", priority: classify.priority, confidence: classify.confidence, reason: classify.reason} else if classify.priority == "ignore" {routed_to: "archive", priority: "ignore", confidence: classify.confidence, reason: classify.reason} else {routed_to: "inbox", priority: classify.priority, confidence: classify.confidence, reason: classify.reason}decide is pure logic, like compute. No AI, no cost, instant. It reads the classification result and picks a path.
The confidence check comes first. If the AI is not sure, a human reviews it regardless of priority. Safety before speed.
What You See When It Runs
/run classify_emailWith “URGENT: Server down” from [email protected]:
routed_to: "notify_team"priority: "urgent"confidence: 0.95reason: "Production outage from operations team"With “Quick question” from someone you do not recognize:
routed_to: "human_review"priority: "today"confidence: 0.58reason: "Low confidence: Could be urgent or routine, unclear sender"With “Weekly deals!” from [email protected]:
routed_to: "archive"priority: "ignore"confidence: 0.99reason: "Marketing newsletter from retail store"The Execution Trace
After running, check the trace:
/timeline [run_id]You will see two steps:
[1] classify ask 420ms $0.0003 anthropic:claude-haiku-4[2] route decide 0ms $0.0000The AI step took 420ms and cost a fraction of a cent. The routing step was instant and free. The trace shows you exactly what happened, how long it took, and what it cost.
Three Kinds of Steps
You now know all three basic step types:
| Step | What it does | Uses AI? | Costs money? |
|---|---|---|---|
ask | AI reasoning | Yes | Yes |
compute | Data transformation | No | No |
decide | Conditional routing | No | No |
The pattern: AI does the judgment. Logic does the routing and formatting. You choose where AI is involved and where it is not. That choice is visible in the code and in the cost trace.
What Comes Next
The machine routes to “notify_team” or “create_task” but does not actually do those things yet. Next lesson: connecting to real systems. Send a message in Microsoft Teams when urgent. Create a task in Planner when action is needed. That is where this becomes useful.