Guide
When to write a function instead of an agent
The judgment-versus-rules decision, with real examples of each and the hybrid pattern that uses both.
The one-question test
Could two careful colleagues disagree about the right output? If yes, it is judgment — use an agent. If no — if there is one correct answer a rulebook produces — it is rules, and rules belong in a function, where the same input gives the same output every single time.
Sorting real steps
| Step | Verdict | Why |
|---|---|---|
| Summarize this support thread | Agent | No single correct summary exists. |
| Score a lead by employee count and region | Function | The rulebook is exact; disagreement means a bug. |
| Decide if this email is a complaint | Agent | Language is ambiguous; judgment required. |
| Validate an expense against policy limits | Function | Limits are numbers; the answer is yes or no. |
| Draft the rejection message | Agent | Tone and content vary by case. |
| Convert currency on the invoice | Function | Math. Always math. |
The hybrid pattern
Most good workflows sandwich them: an agent interprets the messy input, a function applies the exact rules to the agent’s structured output, and another agent drafts the human-facing result. Judgment at the edges, rules in the middle.