Skip to main content

Outcome

Every step of the job sits where it is cheapest to get right. The model does the judgment: reading the request, choosing what to look up, explaining the result. Code does the rest, so those steps give the same answer on every run, cost no tokens, and can be tested without an agent.

The rule of thumb

If you can write the step as a function with a correct answer, write the function. Leave a step to the model only when it needs judgment or language: interpreting a messy request, deciding which case applies, writing for a person. Two quick tests. Would you accept a wrong answer one run in fifty? If not, it is code. Would two good operators do this step differently? If yes, it is the model’s.

Example

The payment-investigation runbook needs the net amount the customer paid over 30 days. The same split applies to the decline code table in references/decline-codes.md: a short table the model reads is fine, but once the mapping grows past a page or feeds a decision (refund or not), turn it into a lookup the script does.

Where the code lives

Pick the narrowest home that does the job:
  1. A script in the skill. Put it in the skill’s scripts/ folder and name the exact command in the runbook step. It ships with the skill to every template the skill is attached to. This covers most cases. See Skills and runbooks.
  2. A CLI or MCP tool on the template. When several skills or agents need the same operation, install it once as a tool provider package or expose it as an MCP tool. See Give it tools.
  3. A hook. When a check must run on every tool call, whatever the model decides (block writes to the ledger, require a ticket ID), write it as a guardrail hook. A runbook step can be skipped; a hook cannot. See Guardrails and approvals.
  4. Outside the agent. When the whole flow is fixed and only one step needs judgment, run the flow in your own job and call a session for that step through the API or a scheduled agent. The agent then never sees the parts it cannot improve.

Verify

  • Run the script by hand on one seeded case and check its output before an agent ever calls it.
  • In a test run, read the transcript: the agent should call the script, not redo its work in prose.
  • The grade on the step’s output stays the same across repeated runs of the same case. If it flips, something non-deterministic is still in the prompt.

Gotchas

  • “Be careful with the math” is not a fix. Stronger wording makes errors rarer, not impossible. Move the math into code.
  • The model recomputes anyway. Say in the runbook that the script’s output is final and must be quoted, not recalculated.
  • Code that hides judgment. Do not hard-code a decision that needs context (“refund if under $50”) unless that is truly the policy. Let the script return the facts and the policy threshold; let the model apply them to the case and explain.
  • Scripts need their tools. A script that calls Stripe still needs the provider on the template and requires.integrations on the skill.
  • Test the script on its own. A script is code: give it a small test with known inputs, separate from the agent’s evals. See Skill evals and session evals.

Skills and runbooks

Ship the script with the runbook that calls it.

Skill evals and session evals

Test the skill on its own, then the agent end to end.