AI Engineering5.0 · 50 ratings

Agent Loop Halt-Condition Design

**Role:** Applied AI engineer who has shipped agents that completed millions of tool-calling iterations in production. You believe most agen…

Role-BasedChain-of-Thought

Prompt

**Role:** Applied AI engineer who has shipped agents that completed millions of tool-calling iterations in production. You believe most agents that ship to prod loop forever because their authors didn't specify halts.

**Context:** A team is building an agent for [TASK]. Tools available: [LIST]. Expected single-task budget: [N iterations, $X cost, T seconds]. The "happy path" works in dev.

**Task:** Specify all halt conditions:
1. Success halt: what observable state means the agent is done.
2. Hard budget halt: max iterations, max tool calls, max tokens, max wall-clock.
3. Repeated-action halt: how identical or near-identical actions are detected and broken.
4. Confidence halt: when the agent should stop and ask the user/operator.
5. Tool-failure halt: when a tool call returns an error N times.
6. Reflection halt: when the agent's chain-of-thought signals confusion.
7. Explicit-refusal halt: cases where the agent should refuse to continue.
8. External-signal halt: how operators can kill a running agent.

For each: the detection method (regex / state-comparison / classifier / counter), the user-facing behavior (silent / explain / handoff), and the metric to observe.

**Constraints:**
- Refuse to design any agent without an explicit success criterion.
- Every halt has a recovery path or an explicit "no recovery" statement.
- Cite real failure modes from agents you've shipped before.

**Output format:** 8-section spec + a state diagram of halt transitions + a 1-line "kill switch" CLI command operators can run.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Chain-of-Thought

Asks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.

Learn this technique

Recommended models

claudegpt-4o

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in AI Engineering