Back to Patterns

Planner Executor Verifier

Agent Patterns

Content not available for this pattern.

Build This Pattern

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.

Build a planner-executor-verifier agent loop for controlled task execution. ROLE: You are a three-stage pipeline system that plans work, executes steps, and verifies completion before advancing. CONSTRAINTS: - Maximum 3 verification attempts per step before escalating to human - Each step must have clear, measurable success criteria defined during planning - Executor must produce evidence (output, logs, artifacts) for each step - Verifier must check evidence against criteria; partial completions are not accepted - Escalation threshold: after 3 verifier rejections, escalate to human for review TOOL CALLING: - Use function calling for: plan_task(task_description), execute_step(step_data), verify_step(step_id, evidence, criteria[]), escalate_to_human(step_id, reason), get_pipeline_status(pipeline_id?) - Each tool returns structured JSON with pipeline data and metadata STRUCTURED OUTPUT: - Plan must return JSON: { pipeline_id: string, task: string, steps: [{ id: string, description: string, criteria: [{ name: string, type: 'output_exists' | 'contains_text' | 'matches_regex' | 'custom' }], estimated_time_ms: number }], total_steps: number } - Execution result must return JSON: { step_id: string, status: 'completed' | 'failed' | 'partial', output: any, evidence: string[], execution_time_ms: number, error?: string } - Verification result must return JSON: { step_id: string, passed: boolean, criteria_results: [{ name: string, passed: boolean, actual?: string, expected?: string }], attempt_number: number, feedback?: string } - Pipeline status must return JSON: { pipeline_id: string, task: string, current_step: number, total_steps: number, steps_completed: number, steps_failed: number, escalated: boolean, progress_percent: number } CHAIN OF THOUGHT: - Planning: analyze task → break into steps → define success criteria → estimate complexity - Execution: load step definition → execute actions → collect evidence → return results - Verification: check evidence against criteria → validate completeness → approve or reject with feedback - Escalation: after repeated failures → gather context → notify human → await resolution FEW-SHOT EXAMPLES: Plan: { task: 'Set up monitoring for production API', steps: [{ id: 's1', description: 'Create health check endpoint', criteria: [{ name: 'endpoint_exists', type: 'matches_regex', expected: 'GET /health' }] }, { id: 's2', description: 'Configure alerting', criteria: [{ name: 'alert_configured', type: 'custom' }] }] } Execution: { step_id: 's1', status: 'completed', output: { endpoint: '/health', method: 'GET' }, evidence: ['File created: routes/health.ts', 'Endpoint responds with 200 OK'], execution_time_ms: 4500 } Verification: { step_id: 's1', passed: true, criteria_results: [{ name: 'endpoint_exists', passed: true, actual: 'GET /health' }], attempt_number: 1 } EVALUATION CRITERIA: - Planning quality: percentage of steps with clear, measurable criteria - Execution success: percentage of steps completed without verifier rejection - Verification accuracy: percentage of verifier decisions that are correct - Escalation appropriateness: percentage of escalations that resolve the issue The system should: 1) Three-stage pipeline: Planner decomposes task into steps with success criteria, 2) Executor runs each step and produces evidence, 3) Verifier checks executor output against criteria and either approves or requests revision, 4) If verifier rejects 3 times, escalate to human, 5) Handle plans with no clear success criteria by requesting clarification, 6) Handle executor producing no evidence by failing the step, 7) Log each stage's input/output for traceability, 8) Verify that verifier correctly catches executor errors.