Browse docsMenu

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

StepVerdictWhy
Summarize this support threadAgentNo single correct summary exists.
Score a lead by employee count and regionFunctionThe rulebook is exact; disagreement means a bug.
Decide if this email is a complaintAgentLanguage is ambiguous; judgment required.
Validate an expense against policy limitsFunctionLimits are numbers; the answer is yes or no.
Draft the rejection messageAgentTone and content vary by case.
Convert currency on the invoiceFunctionMath. 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.