THE SHORT ANSWER
Design from GOAL → STEPS → DECISIONS → TOOLS → CHECKS → APPROVALS → STOPPING CONDITIONS. Keep exact rules in code, give the model only decisions that need interpretation, validate every tool boundary and define success, failure, escalation and budget before the loop runs.
Specify the final state
Replace ‘handle customer requests’ with an observable goal such as ‘prepare a supported answer for an agent to approve, or route the case to the correct queue.’ Define what must be true at completion, what remains outside scope and who owns the outcome.
- Trigger: what starts the work?
- Inputs: which sources are authoritative?
- Acceptance: what makes the outcome usable?
- Constraints: which policies, budgets and deadlines apply?
- Consequence: what can go wrong, and who is affected?
Separate steps from decisions
| Stage | Best control | Why |
|---|---|---|
| Check file type and size | Deterministic code | The rule is exact |
| Classify document purpose | Model with allowed labels | Language varies |
| Extract required fields | Model plus schema validation | Content varies; output shape does not |
| Approve a high-value exception | Authorised person | The consequence needs accountability |
| Write status to system | Tool with narrow permission | Execution should be explicit and auditable |
Do not ask the model to rediscover a fixed business rule on every turn. Reserve model choice for ambiguity that cannot be captured reliably in code.
Design each tool boundary
For every tool, define allowed inputs, identity, read or write scope, side effects, timeouts and an interpretable result. Validate model-generated arguments before execution. Return errors as observations the controller can route, rather than letting the model assume success.
Place approvals before external communication, financial changes, permission changes and other consequential actions. An approval should show the proposed action and essential evidence, not ask a person to supervise an opaque loop.
Evidence & context: OpenAI Developers · NIST
Write the ending before the loop
- Success: the final state is independently verified.
- Retry: the error is temporary and another attempt is safe.
- Repair: a bounded correction can resolve a validation failure.
- Escalate: a person must supply information or judgment.
- Fail: the task cannot continue safely.
- Stop: time, attempts, cost or scope reached its limit.
Evidence & context: Anthropic
Sources & further reading
- Building effective agents
Anthropic. A provider's engineering taxonomy of agents and workflows, not a universal industry definition. We use the conceptual distinction, not its changing product recommendations.
- Function calling
OpenAI Developers. Official documentation for model-selected function calls. The application, not the model, executes custom functions and must validate arguments, permissions and results.
- Generative Artificial Intelligence Profile (NIST AI 600-1)
NIST. Risk-management guidance, including confabulation. It does not establish a universal error rate.
Examples and exercises are illustrative unless attributed to a source. No independent expert review is claimed.
A correction, a counterexample or an experience worth sharing?
Join the conversation ↗