Agentic Architectures

Catalogue / Tools & Action

Plan–Execute–Verify

Every step is checked before the next one may start

Shape
gate
Model calls
1 plan + 2 per step attempt (typically 8 to 20)
Latency
high
Complexity
medium

Also known as PEV, Checked execution

1

How do I stop one bad step from spoiling everything that follows?

In a plain plan, a wrong step two quietly poisons steps three to ten. Here a separate verifier checks each step's result against what the step promised. A failed step is redone with the verifier's reasons. The next step starts only after a pass.

You may need it if

  • Errors are found at the end, after every later step has built on them.
  • Each step has a result you can check, such as figures that reconcile or a file that loads.
  • Redoing the whole job is far more expensive than redoing one step.
2

When is checking every step too slow?

Use it when

  • Each step has an acceptance check you can state upfront: totals match, a query returns rows, a test passes.
  • Later steps depend on earlier ones being right.
  • A wrong final result is costly, as in financial reports, data migrations or customer-facing changes.

Avoid it when

  • No step has a clear pass condition. The verifier would only give opinions.
    Use Reflection instead
  • The only risk is a side effect on a live system, and the question is whether to allow it at all.
    Use Dry Run instead
  • Steps are cheap and independent, so an error in one does not spread to the others.
    Use Planning instead

What it costs

Model calls
1 plan + 2 per step attempt (typically 8 to 20)
Latency
high
Complexity
medium
3

How does a step get from plan to accepted?

The planner writes steps, each with an acceptance check. The executor does one step, the verifier judges it against its check, and a fixed rule decides. Pass moves to the next step. Fail returns the step with the reasons, up to a retry limit.

next step, orretry withreasonslast steppassedretries spenton a stepGoal: The goal and its constraints, or a plan already written by an earlier stage.GoalPlanner: Writes ordered steps, each with an acceptance check that a verifier can apply.PlannerPlan: The steps, their checks, their status and the reasons from every failed attempt.PlanExecutor: Carries out the current step, using the verifier's reasons when it is a retry.ExecutorVerifier: Applies the step's acceptance check to the result and returns pass or fail with reasons.VerifierStep passed?: A plain rule. Counts attempts per step and picks next step, retry, finish or fail.Step passed?Verified result: The result of the whole plan, every step having passed its check.VerifiedresultFailed step: The step that kept failing, with the verifier's reasons for each attempt.Failed step
  1. Step 1 of 5

    Steps come with their checks

    For "Migrate our customer list to the new billing system", the planner writes steps such as export, clean, import. Each has a check, for example "row count equals the source".

  2. Step 2 of 5

    One step is executed

    The executor reads the current step and does it. It does not move on, and it does not mark its own work as done.

  3. Step 3 of 5

    The verifier applies the check

    The verifier sees the step, its check and the result, and runs the check where it can, such as counting rows. It returns pass or fail with concrete reasons.

  4. Step 4 of 5

    Pass, retry or give up

    The gate records the outcome in the plan. A pass sends the next step to the executor. A fail sends the same step back with the reasons, until three attempts are used.

  5. Step 5 of 5

    Two different endings

    When the last step passes, the verified result leaves. When a step fails after its retries, the run stops there and the failure leaves with its reasons. Nothing after it ran.

What each part does
Goal
The goal and its constraints, or a plan already written by an earlier stage.
Planner
Writes ordered steps, each with an acceptance check that a verifier can apply.
Plan
The steps, their checks, their status and the reasons from every failed attempt.
Executor
Carries out the current step, using the verifier's reasons when it is a retry.
Verifier
Applies the step's acceptance check to the result and returns pass or fail with reasons.
Step passed?
A plain rule. Counts attempts per step and picks next step, retry, finish or fail.
Verified result
The result of the whole plan, every step having passed its check.
Failed step
The step that kept failing, with the verifier's reasons for each attempt.
  • Planner → Plan: steps and checks
  • Plan → Executor: current step and past reasons
  • Executor → Verifier: step result
  • Verifier → Step passed?: pass or fail with reasons
  • Step passed? → Plan: step status
  • Step passed? → Executor: next step, or retry with reasons
  • Step passed? → Verified result: last step passed
  • Step passed? → Failed step: retries spent on a step

Where it connects

Entry
goal
TaskPlan

A goal with its constraints, or a written plan. When a plan arrives, the planner only adds a missing acceptance check to each step.

Exit
verified
AnswerDocumentOutcome

When: Every step passed its acceptance check.

The final result, then each step with its check, the number of attempts and the verifier's pass reason.

Exit
failed
Verdict

When: A step still fails its check after the retry limit.

The failing step, its check, the verifier's reasons for each attempt, and the list of steps that passed before it.

Working memory for one run
plan
Plan

Ordered steps with their acceptance checks, status per step, attempt counts and the reasons from each failed attempt.

4

What do I ask my assistant to set up?

The agents to launch

Planner

Write three to ten ordered steps for the goal. For each, give the action and one acceptance check that a wrong result would fail, such as a count, a total or a test. If you receive a plan, keep its steps and add a check to any step that has none.

Sees: The goal, the constraints and any plan received. Not results, since none exist yet.

Executor

Carry out the one step you are given and return its result. On a retry, fix the problems listed by the verifier. Do not judge your own work and do not start the next step.

Sees: The current step, the results of earlier passed steps and, on a retry, the verifier's reasons.

Verifier

Apply the acceptance check to the result. Run the check yourself when you can. Answer PASS or FAIL, then list concrete reasons pointing to the part of the result concerned. When the evidence is insufficient, answer FAIL and say what is missing.

Sees: The step, its acceptance check and the result. Not the executor's explanation or earlier attempts.

A prompt you can paste

Works with any assistant that can launch sub-agents. It contains the agents, the procedure and the stop rule above.

Framework-agnostic prompt
You are the orchestrator of a multi-agent workflow that follows the "Plan–Execute–Verify" architecture.
Launch every agent listed below as a separate sub-agent with its own context. Give each agent only the context stated for it. Do not do an agent's work yourself. If you cannot launch sub-agents, play each agent in a clearly separated turn and never let it use what is withheld from it.

# Task
[Describe your task here]

# Plan–Execute–Verify
Every step is checked before the next one may start.
Input: the task above. It must provide: A goal with its constraints, or a written plan. When a plan arrives, the planner only adds a missing acceptance check to each step. If something essential is missing, ask for it before starting.

Agents to launch:
- Planner: Write three to ten ordered steps for the goal. For each, give the action and one acceptance check that a wrong result would fail, such as a count, a total or a test. If you receive a plan, keep its steps and add a check to any step that has none.
  Context for this agent: The goal, the constraints and any plan received. Not results, since none exist yet.
- Executor: Carry out the one step you are given and return its result. On a retry, fix the problems listed by the verifier. Do not judge your own work and do not start the next step.
  Context for this agent: The current step, the results of earlier passed steps and, on a retry, the verifier's reasons.
- Verifier: Apply the acceptance check to the result. Run the check yourself when you can. Answer PASS or FAIL, then list concrete reasons pointing to the part of the result concerned. When the evidence is insufficient, answer FAIL and say what is missing.
  Context for this agent: The step, its acceptance check and the result. Not the executor's explanation or earlier attempts.

Procedure:
1. Launch the planner on the goal, or on the incoming plan to add missing checks. Store the steps.
2. Launch the executor on the first pending step.
3. Launch the verifier in a fresh context on the step, its check and the result.
4. On PASS, mark the step done and move to the next one. On FAIL, record the reasons and send the step back to the executor with them.
5. After 3 failed attempts on one step, stop the run and report the failure.

Stop rule: Stop when the last step passes, or when any step fails 3 attempts. Never skip a failed step to continue with the rest.

Exits:
- `verified`, when: Every step passed its acceptance check. Deliver: The final result, then each step with its check, the number of attempts and the verifier's pass reason.
- `failed`, when: A step still fails its check after the retry limit. Deliver: The failing step, its check, the verifier's reasons for each attempt, and the list of steps that passed before it.

# Final deliverable
Either the verified result with each step's check and attempts, or the failing step with every attempt's reasons and the steps that passed before it, labelled verified or failed.

The same thing in code

LangGraph, python, package langgraph
import operator
from typing import Annotated, TypedDict, cast

from langchain.chat_models import init_chat_model
from langgraph.graph import END, START, StateGraph
from pydantic import BaseModel

llm = init_chat_model("anthropic:claude-sonnet-5-5")
MAX_ATTEMPTS = 3


class Step(BaseModel):
    action: str
    check: str  # a condition a wrong result would break: a count, a total, a test


class Plan(BaseModel):
    steps: list[Step]


class Verdict(BaseModel):
    passed: bool
    reasons: list[str]


class Input(TypedDict):
    goal: str


class State(Input):
    steps: list[Step]  # the plan store
    current: int
    attempts: int
    result: str
    reasons: list[str]
    passed: Annotated[list[str], operator.add]
    log: Annotated[list[str], operator.add]  # reasons from every failed attempt
    status: str


async def planner(state: State) -> dict:
    plan = cast(Plan, await llm.with_structured_output(Plan).ainvoke(
        "Write 3 to 10 ordered steps for the goal. For each give the action and one acceptance "
        "check that a wrong result would fail, such as a count, a total or a test.\n"
        f"Goal: {state['goal']}"))
    return {"steps": plan.steps, "current": 0, "attempts": 0, "reasons": []}


async def executor(state: State) -> dict:
    step = state["steps"][state["current"]]
    retry = f"\nFix these problems found by the verifier: {state['reasons']}" if state["reasons"] else ""
    reply = await llm.ainvoke(
        "Carry out this one step and return its result. Do not judge your own work and do not "
        f"start the next step.\nStep: {step.action}\nResults of earlier steps: {state['passed']}{retry}")
    return {"result": reply.text, "attempts": state["attempts"] + 1}


async def verifier(state: State) -> dict:
    step = state["steps"][state["current"]]
    # fresh call: the step, its check and the result, never the executor's reasoning
    verdict = cast(Verdict, await llm.with_structured_output(Verdict).ainvoke(
        "Apply the acceptance check to the result. Answer pass or fail with concrete reasons. "
        "When the evidence is insufficient, fail and say what is missing.\n"
        f"Step: {step.action}\nCheck: {step.check}\nResult: {state['result']}"))
    if verdict.passed:
        last = state["current"] + 1 == len(state["steps"])
        return {"passed": [state["result"]], "current": state["current"] + 1, "attempts": 0,
                "reasons": [], "status": "verified" if last else "next"}
    # the gate: a step gets 3 attempts, then the whole run stops
    spent = state["attempts"] >= MAX_ATTEMPTS
    return {"reasons": verdict.reasons, "log": [f"step {state['current'] + 1}: {verdict.reasons}"],
            "status": "failed" if spent else "retry"}


def gate(state: State) -> str:
    return "executor" if state["status"] in ("next", "retry") else END


graph = StateGraph(State, input_schema=Input)
graph.add_node("planner", planner)
graph.add_node("executor", executor)
graph.add_node("verifier", verifier)
graph.add_edge(START, "planner")
graph.add_edge("planner", "executor")
graph.add_edge("executor", "verifier")
graph.add_conditional_edges("verifier", gate)
app = graph.compile()


async def run(task: str):
    final = await app.ainvoke({"goal": task}, {"recursion_limit": 100})
    return {"status": final["status"], "results": final["passed"], "failures": final["log"]}

Give the verifier real tools (a test runner, a row counter) so that it runs each check instead of reading the result, and persist the plan with a checkpointer.

Claude Agent SDK, python, package claude-agent-sdk
from claude_agent_sdk import AgentDefinition, ClaudeAgentOptions, ResultMessage, query
from pydantic import BaseModel

MAX_ATTEMPTS = 3


class Step(BaseModel):
    action: str
    check: str


class Plan(BaseModel):
    steps: list[Step]


class Verdict(BaseModel):
    passed: bool
    reasons: list[str]


AGENTS = {
    "planner": AgentDefinition(
        description="Writes ordered steps, each with an acceptance check.",
        prompt="Write 3 to 10 ordered steps for the goal. For each, give the action and one "
        "acceptance check that a wrong result would fail, such as a count, a total or a test.",
        tools=[]),
    "executor": AgentDefinition(
        description="Carries out exactly one plan step.",
        prompt="Carry out the one step you are given and return its result. On a retry, fix the "
        "problems listed by the verifier. Do not judge your own work or start the next step.",
        tools=["Read", "Write", "Bash"]),
    "verifier": AgentDefinition(
        description="Applies a step's acceptance check to its result.",
        prompt="Apply the acceptance check to the result, running it yourself when you can. "
        "Answer pass or fail with concrete reasons. If evidence is missing, fail and say what.",
        tools=["Read", "Bash"]),
}


async def delegate(agent: str, brief: str, schema: type[BaseModel] | None = None) -> ResultMessage:
    # one query per call: a new session, so the sub-agent sees only this brief
    options = ClaudeAgentOptions(
        agents=AGENTS, allowed_tools=["Agent"],
        output_format={"type": "json_schema", "schema": schema.model_json_schema()} if schema else None)
    prompt = f"Delegate this to the {agent} agent and return its answer unchanged.\n\n{brief}"
    async for message in query(prompt=prompt, options=options):
        if isinstance(message, ResultMessage):
            return message
    raise RuntimeError(f"{agent} returned no result")


async def run(task: str):
    plan = Plan.model_validate((await delegate("planner", f"Goal: {task}", Plan)).structured_output)
    passed: list[str] = []
    for step in plan.steps:
        reasons: list[list[str]] = []
        for _ in range(MAX_ATTEMPTS):  # the gate: 3 attempts per step
            retry = f"\nFix these problems found by the verifier: {reasons[-1]}" if reasons else ""
            done = await delegate("executor", f"Step: {step.action}\nEarlier results: {passed}{retry}")
            result = done.result or ""
            checked = await delegate(
                "verifier", f"Step: {step.action}\nCheck: {step.check}\nResult: {result}", Verdict)
            verdict = Verdict.model_validate(checked.structured_output)
            if verdict.passed:
                passed.append(result)
                break
            reasons.append(verdict.reasons)
        else:
            # never skip a failed step: everything after it is left undone
            return {"status": "failed", "step": step, "reasons": reasons, "passed": passed}
    return {"status": "verified", "results": passed}

Narrow the executor's tools and set permission_mode for your environment; the verifier should keep only the tools it needs to run the checks.

OpenAI Agents SDK, python, package openai-agents
from agents import Agent, Runner
from pydantic import BaseModel

MAX_ATTEMPTS = 3


class Step(BaseModel):
    action: str
    check: str


class Plan(BaseModel):
    steps: list[Step]


class Verdict(BaseModel):
    passed: bool
    reasons: list[str]


planner = Agent(
    name="Planner",
    instructions="Write 3 to 10 ordered steps for the goal. For each, give the action and one "
    "acceptance check that a wrong result would fail, such as a count, a total or a test.",
    output_type=Plan,
)
executor = Agent(
    name="Executor",
    instructions="Carry out the one step you are given and return its result. On a retry, fix the "
    "problems listed by the verifier. Do not judge your own work or start the next step.",
)
verifier = Agent(
    name="Verifier",
    instructions="Apply the acceptance check to the result. Answer pass or fail with concrete "
    "reasons. When the evidence is insufficient, fail and say what is missing.",
    output_type=Verdict,
)


async def run(task: str):
    plan = (await Runner.run(planner, f"Goal: {task}")).final_output_as(Plan)
    passed: list[str] = []
    for step in plan.steps:
        reasons: list[list[str]] = []
        for _ in range(MAX_ATTEMPTS):  # the gate: 3 attempts per step
            retry = f"\nFix these problems found by the verifier: {reasons[-1]}" if reasons else ""
            done = await Runner.run(executor, f"Step: {step.action}\nEarlier results: {passed}{retry}")
            result = str(done.final_output)
            # a separate run: the verifier never sees the executor's reasoning
            checked = await Runner.run(
                verifier, f"Step: {step.action}\nCheck: {step.check}\nResult: {result}")
            verdict = checked.final_output_as(Verdict)
            if verdict.passed:
                passed.append(result)
                break
            reasons.append(verdict.reasons)
        else:
            return {"status": "failed", "step": step, "reasons": reasons, "passed": passed}
    return {"status": "verified", "results": passed}

Give the verifier function tools that run the acceptance checks (tests, counts, totals) so its verdict rests on evidence, not on reading.

Vercel AI SDK, typescript, package ai
import { anthropic } from '@ai-sdk/anthropic';
import { generateText, Output } from 'ai';
import { z } from 'zod';

const model = anthropic('claude-sonnet-5-5');
const MAX_ATTEMPTS = 3;

const planSchema = z.object({
  steps: z.array(z.object({ action: z.string(), check: z.string() })),
});
const verdictSchema = z.object({ passed: z.boolean(), reasons: z.array(z.string()) });

export async function run(task: string) {
  const { output: plan } = await generateText({
    model,
    instructions:
      'Write 3 to 10 ordered steps for the goal. For each, give the action and one acceptance ' +
      'check that a wrong result would fail, such as a count, a total or a test.',
    prompt: `Goal: ${task}`,
    output: Output.object({ schema: planSchema }),
  });

  const passed: string[] = [];
  for (const step of plan.steps) {
    const reasons: string[][] = [];
    let ok = false;
    // the gate: 3 attempts per step
    for (let attempt = 0; attempt < MAX_ATTEMPTS && !ok; attempt++) {
      const retry = reasons.length ? `\nFix these problems: ${reasons.at(-1)!.join('; ')}` : '';
      const { text: result } = await generateText({
        model,
        instructions:
          'Carry out the one step you are given and return its result. Do not judge your own ' +
          'work and do not start the next step.',
        prompt: `Step: ${step.action}\nEarlier results: ${passed.join('\n')}${retry}`,
      });
      // a separate call: the step, its check and the result only
      const { output: verdict } = await generateText({
        model,
        instructions:
          'Apply the acceptance check to the result. Answer pass or fail with concrete reasons. ' +
          'When the evidence is insufficient, fail and say what is missing.',
        prompt: `Step: ${step.action}\nCheck: ${step.check}\nResult: ${result}`,
        output: Output.object({ schema: verdictSchema }),
      });
      if (verdict.passed) {
        passed.push(result);
        ok = true;
      } else {
        reasons.push(verdict.reasons);
      }
    }
    if (!ok) return { status: 'failed' as const, step, reasons, passed };
  }
  return { status: 'verified' as const, results: passed };
}

Add tools to the verifier call that actually run each acceptance check, and keep the attempt log for the failure report.

Snippets are generated when the site is built and type-checked against the SDK versions listed in the repository. Treat them as a starting skeleton.

What goes wrong

  • Checks that cannot fail make the verifier decorative. Each one must name a measurable condition.
  • Showing the verifier the executor's reasoning invites agreement. Give it the result only.
  • Allowing the run to continue past a failed step defeats the pattern. A failed step stops everything after it.

Chain it

Its result can feed

It can take the result of

Directly