Designing AI agent skills and loops that know when to stop

I write each agent skill as a contract in seven parts, from inputs to stop conditions. Each loop runs until a check passes. If a limit trips first, such as three repair passes, the decision comes back to me.

A closed copper ring with a small glass inspection window, standing on a marble desk
Illustration: a closed copper ring with a small glass inspection window, standing on a marble desk.

A skill is a reusable contract for one class of work. It tells an agent what it may receive, what it may do and what it must return. It also says how the result is checked and when the agent must stop. The prompt is one part of it.

In most tools, an AI agent skill is a folder with a SKILL.md file: YAML frontmatter with a name and description, then instructions, plus any scripts or reference material it needs. The agent reads the name and description first and loads the rest when a task matches, which Anthropic’s documentation calls progressive disclosure. That format tells the agent when to reach for a skill. The contract below sets what the skill may do once it is running.

Start with the skill contract

Inputs
The files, facts, URLs and constraints, plus a definition of the outcome requested.
Authority
The tools and state changes allowed, and the line past which approval is needed.
Method
The checks and actions, in order, that make the work repeatable.
Output
The exact format of the answer or deliverable, and the person who will read it.
Checks
The observable facts the skill must show before it may claim success.
Failures
Known ways the work can look complete while the outcome is still broken.
Stop conditions
Limits on attempts, time, cost, risk and confidence, so the work cannot run forever.

Deterministic loops for work with one checkable answer

A deterministic outcome has a predicate that a test can settle. Examples are a command that exited cleanly, internal links that all resolve and structured data that parses. A file hash that matches the deployed asset counts too, as does a redirect that lands on the canonical URL. The loop should be mechanical and idempotent, so running it twice does no harm.

  1. ObserveRead the current state.
  2. CompareEvaluate an exact predicate.
  3. ActMake one small, limited change.
  4. Re-runUse the same check again.
  5. ExitPass, or stop at the retry budget.
The deterministic loop as pseudocode
for attempt in range(3):
    state = inspect()
    if predicate(state):
        return PASS(state.evidence)
    apply_bounded_fix(state)

# Inspect once more: the last permitted repair may have succeeded.
state = inspect()
if predicate(state):
    return PASS(state.evidence)
return BLOCKED(state.evidence)

The loop needs four things: a stable predicate, a fixed retry budget, results I can inspect and steps that are safe to repeat. “Run the link checker until it reports zero broken internal links, with at most three repair passes” meets all four. “Keep trying until it looks right” has no predicate to test.

Non-deterministic loops for work that needs judgement

Research synthesis, naming, visual critique, prioritisation and explanatory writing have no single provably correct answer. Running the same model again can produce a different result that is still usable. So the loop manages the variance and does not pretend it away.

  1. FrameState audience and rubric.
  2. SampleProduce one or more candidates.
  3. CritiqueScore claims and trade-offs.
  4. SynthesiseKeep the strongest parts.
  5. GateAccept, retry or ask a human.

Five controls keep it in check: a named rubric, independent review, a source for each claim, a confidence threshold and a hard limit on attempts or time. Extra generations do not, by themselves, make an answer more true. A second reviewer helps only when it has a separate job: falsify claims, test the fit for the audience or find a missed trade-off.

In software, non-deterministic is the precise term. “Undeterministic” is understandable, and the design problem is the same: the process can vary, so the acceptance rule has to be written down.

Hybrid loops that put model judgement inside deterministic checks

Most agent work worth doing is hybrid. I let the model interpret, propose, rank or write where judgement helps. Then I surround that uncertain core with checks that do not depend on taste.

  • Deterministic in: identity, source set, permissions, schema, format and budget.
  • Model judgement: interpret, propose, compare and synthesise.
  • Deterministic out: claims, links, tests, policy, hashes and live-state checks.
Four kinds of hybrid work, with the judgement the model makes and the checks that enclose it.
WorkNon-deterministic coreDeterministic enclosure
ResearchSelect the most useful evidence and explain it.Primary-source requirement, dates, links, quotation limits, claim ledger.
Page designChoose hierarchy, rhythm, imagery and emphasis.Tokens, breakpoints, contrast, overflow, performance budget, browser checks.
Release reviewJudge which diff creates material risk.Revision identity, changed-path inventory, test suite, preview, live hash.
MonitoringDecide whether an observed change matters.Fetch status, timestamp, diff, known categories, escalation threshold.

One loop for both kinds of work

  1. SenseCheck the current state before trusting memory.
  2. FrameDefine the outcome, the risk and the checks.
  3. RouteSelect the skill and its authority.
  4. ActTake the smallest step that makes sense.
  5. VerifyRun exact checks and a review with a budget.
  6. RecordSave the state, the check results and what is still uncertain.
  7. LearnChange the skill when outcomes disagree.

The loop is complete only when what happened can change the contract. When a failure recurs, I add a precondition, a test or a stop condition to the skill, instead of another paragraph telling the agent to “be careful”.

Five limits that stop endless refinement

  • Attempt budget: a fixed number of repair or generation passes.
  • Progress test: continue only if the last pass changed a check result or removed a known defect.
  • Confidence floor: below it, the agent labels what it is unsure of or escalates, without polishing the wording to hide the doubt.
  • Risk gate: irreversible, public, financial, permission or message-sending actions wait for my approval.
  • Definition of done: completion is measured against the user’s outcome, and a file the agent produced counts only if it delivers that outcome.

For a working example, see how Hermes routes skills through Telegram. To apply the pattern, start with the verification and routing templates.

Suhail Mohebi · published 17 July 2026 · the cover is a generated illustration

Use this

Skill contract (SKILL.md starter)Markdown · v1.1 · 14 Nov 2026 · 8 KB
Download the template (.md) ↓

← Previous: Why my AI agent was slow: 61 skills and 27 tool schemas

Want this inside your team’s workflow? The Verified AI Operations Sprint tests one workflow in ten working days. See the sprint →

Start with the skill contract
  1. Start with the skill contract
  2. Deterministic loops for work with one checkable answer
  3. Non-deterministic loops for work that needs judgement
  4. Hybrid loops that put model judgement inside deterministic checks
  5. One loop for both kinds of work
  6. Five limits that stop endless refinement