Chapter 2

Narrow the Task Boundary First

"Store assistant" sounds solid, but for an agent it's useless - it says nothing about what the agent does and, above all, what it doesn't. A working contract lists the supported intents, the allowed data, the possible outcomes, and the actions the agent fundamentally does not perform. That's not bureaucracy but the boundary inside which the system can be verified.

For our example the contract fits in a short YAML, and it's worth writing before any code.

agent: commerce_support_v1
goal: resolve a policy or specific-order question
supports:
  - answer using the store's active rules
  - check the current user's order status
  - prepare a refund calculation
  - prepare an operator handoff
never:
  - read someone else's order
  - change address, payment, or order
  - issue a refund without explicit confirmation
done_when:
  - answer
  - clarification_required
  - approval_required
  - handoff_required
  - blocked

Note two things. The never list isn't a wish addressed to the model but what physically must not be available to it: reading someone else's order, changing payment, issuing a refund without confirmation. And done_when lists ALL the allowed finals, including the safe exits - a clarification, a request for confirmation, a handoff, a block. The agent always ends with one of them, not with "free text."

Behind this is a simple economics of error. Where the cost of error is high - money, personal data, contractual promises, irreversible changes - you need code, an audit trail, and explicit confirmation. Where it's low, an extra question or a handoff is almost always cheaper than a confident fabrication; so the safe exits must be part of the contract, not an emergency case.

To feel which level of system a task even needs, run it through the builder - it'll suggest whether a single call, a workflow, or a full loop is enough.

Interactive lab 1

Choose the minimal architecture

A single model call with structured output. Move the expensive action into a separate approval and commit service.

The contract is narrowed - now it's worth seeing where it lands as a whole. The entire architecture fits in a few blocks.

Knowledge check

What does the never list in an agent contract mean?

Links