Workflow Series (01): Foundations — Three Execution Models and Anthropic's Five Patterns

AI Workflows aren't upgraded flowcharts — they're a fundamentally different execution model. Starting from a comparison of DAG / state machine / event-driven models, this article covers Anthropic's five core patterns: Prompt Chaining, Routing, Parallelization, Orchestrator-Subagents, and Evaluator-Optimizer, and how they compose into real production workflows.

·7 min read·AI Engineering

Workflows Are Not Flowcharts

Traditional workflows are deterministic: each node is code, branch conditions are boolean expressions, failures are predefined exception types. Same input, same output, every time.

Agent Workflows break those three assumptions:

Traditional Workflow (Airflow / n8n):
  Node             = Python function / API call (deterministic)
  Branch condition = x > 0 (boolean expression)
  Failure handling = try/except (predefined exception types)
 
Agent Workflow:
  Node             = LLM + tools (non-deterministic output)
  Branch condition = confidence ≥ 95% (semantic judgment)
  Failure handling = retry + human escalation + semantic fallback

Agent Workflows are one of three fundamentally different execution models, not an upgraded flowchart.


Three Execution Models

DAG (Directed Acyclic Graph)

Control flow is fully determined before execution begins. Nodes only move forward — no loops.

Examples: Airflow, n8n, GitHub Actions
Use case: data pipelines, ETL, scheduled jobs
 
Properties:
  → Structure is visualizable, execution order is transparent
  → No cycles (retry logic requires workarounds)
  → Right for deterministic data processing, wrong for AI tasks requiring dynamic branching

State Machine

The system has a finite set of states. Events trigger state transitions: current state + event → next state.

Examples: LangGraph, custom workflows with JSON state files
Use case: business processes with branching, retries, and human approval gates
 
Properties:
  → System state is serializable at any moment (supports interrupt and resume)
  → Cycles are native (retry = state rollback)
  → workflow_state.json is the state file; approval gates are waiting-for-event states

A Bug fix workflow as a state machine:

States: analyzing / fixing / reviewing / waiting_human / done / failed
Events: analyze_done / fix_passed / human_approved / timeout
Transitions:
  analyzing + analyze_done      → fixing
  fixing    + fix_passed        → reviewing
  reviewing + human_approved    → done
  reviewing + timeout           → waiting_human (escalate)

Event-Driven

Nodes communicate through messages. Each node subscribes to messages, processes them, and publishes new ones. Naturally asynchronous and long-running.

Examples: Temporal, AWS Step Functions, Apache Kafka Streams
Use case: long-running workflows (> 1 hour), enterprise-grade transactions
 
Properties:
  → Nodes are loosely coupled — independently deployable and scalable
  → Built-in persistence and Durable Execution guarantees
  → High operational complexity; not right for fast iteration

Which Model to Use

Data pipeline, deterministic nodes      → DAG
Branching / retries / approval gates    → State Machine
Runtime > 1 hour, strong consistency    → Event-Driven

Most AI Agent Workflows use the state machine model: it supports retry loops, serializable state, and interrupt-and-resume — all essential properties for AI workflows.


Anthropic's Five Core Patterns

Any Agent Workflow can be described using these five patterns. This vocabulary lets you communicate system architecture clearly with any engineer or stakeholder.

Pattern 1: Prompt Chaining

A → B → C
each step's output is the next step's input

When to use: Tasks decompose into ordered steps where each step's quality directly affects what follows.

Example: Bug fix workflow main chain
  Phase 1 (gather info) → Phase 2 (log analysis) → Phase 3 (root cause)
  → Phase 4 (code fix) → Phase 5 (submit) → Phase 7 (notify)

Key constraint: One step fails, the whole chain stops. Every step needs a defined on_failure behavior.

Pattern 2: Routing

Input → Classifier → [type A] → Agent A
                  → [type B] → Agent B
                  → [default] → Agent C

When to use: Different input types need different processing paths.

## Routing design example (Workflow Markdown format)
 
After Phase 3, route based on root cause confidence:
 
- confidence ≥ 95%         → proceed to Phase 4 (code fix)
- 60% ≤ confidence < 95%  → trigger Gate A (human confirms root cause)
- confidence < 60%         → retry Phase 3 (different angle, max 3 times)
- still < 60% after 3 tries → escalate to human

Key design requirement: The router must output an enumerated type, not free text. confidence < 60% is computable. "Analysis wasn't deep enough" is not.

Pattern 3: Parallelization

         → B1 →
A → split → B2 → merge → C
         → B3 →

When to use: Subtasks are independent and can run concurrently, or you need multiple perspectives to compare and select the best result.

# Fan-out: run 3 fix candidates concurrently
from concurrent.futures import ThreadPoolExecutor, as_completed
 
candidates = ["candidate_a", "candidate_b", "candidate_c"]
 
with ThreadPoolExecutor(max_workers=3) as executor:
    futures = {
        executor.submit(run_fix_candidate, c, bug_info): c
        for c in candidates
    }
    results = {}
    for future in as_completed(futures):
        candidate = futures[future]
        results[candidate] = future.result()
 
# Fan-in: select the best passing candidate
best = max(
    (r for r in results.values() if r["passed"]),
    key=lambda r: r["test_coverage"],
    default=None,
)

Important caveat: Parallelization speedup is capped by Amdahl's Law. Three concurrent branches plus one sequential merge step typically yields ~1.5x speedup, not 3x. (See Skill Series Article 05 for measured data.)

Pattern 4: Orchestrator-Subagents

Orchestrator (main Agent)
  ├── spawn Subagent A (isolated session)
  ├── spawn Subagent B (isolated session)
  └── collect results → make decision

When to use: Tasks decompose into independent subtasks, each needing focused context without access to the main Agent's full history.

Three design principles for subagents:

Principle 1: Input completeness
  The task prompt contains everything the subagent needs.
  It cannot depend on "implicit context from the main Agent."
 
Principle 2: Output contract strictness
  Output must conform to the declared JSON schema.
  {"passed": bool, "result": {...}, "error": str | null}
 
Principle 3: Structured failure output
  Even on failure, write {"passed": false, "error": "specific reason"}.
  A missing output file looks like a timeout to the main Agent.

Pattern 5: Evaluator-Optimizer

Generator → Evaluator → [score ≥ threshold] → output

         [score < threshold] → feedback → Generator (retry)
                                          max_retries = 3

When to use: Output quality matters and the first attempt may not meet the bar. Iterative improvement is viable.

# Evaluation loop definition in workflow YAML
phase_4_fix:
  generator: write-android-code
  evaluator: run-unit-tests
  quality_threshold:
    min_test_coverage: 80%
    all_tests_passed: true
  on_fail:
    max_retries: 3
    feedback_to_generator: true   # pass failure reason back to generator
  on_max_retries_exceeded:
    action: human_escalation      # escalate after 3 tries, never infinite loop

Anti-pattern: An evaluation loop without max_retries runs forever. Evaluator feedback must name a specific problem. "Make it better" is not feedback.


Patterns Compose Into Real Workflows

Real production workflows combine multiple patterns. A Bug fix workflow contains all five:

Overall structure:    Prompt Chaining (main chain, Phase 1→7)
 
Phase 3 internally:   Evaluator-Optimizer (root cause analysis, max 3 retries)
 
Phase 3→4 transition: Routing (route by confidence score)
 
Phase 4 internally:   Parallelization (3 candidates concurrently)
                      + Evaluator-Optimizer (test each candidate)
 
Phase 5/7 writes:     Routing (human approval gate = special routing branch)
 
Overall control:      Orchestrator-Subagents (main Agent runs the state machine,
                      spawns a subagent for each Phase)

Mapping each part of your system to a pattern is the starting point for design review.


Workflow Expression Formats

A workflow's "code" can take many forms. There's no single right answer:

FormatExampleBest for
Markdown + YAMLworkflow.md + config.yamlFrequent iteration; readable by non-engineers
Python code (LangGraph)StateGraph + node functionsComplex state machines; code-level testing
Visual configuration (n8n)Canvas + JSONAPI integration-heavy; AI is just one step
Natural languageAGENTS.md + task promptsEarly exploration; rapid prototyping

The choice affects maintainability, testability, and execution engine selection. The next article (W2: Design Patterns) covers how to structure these files.


Summary

  1. Agent Workflows are state machines: non-deterministic nodes, semantic branching, semantic fallback — the three assumptions of traditional DAGs all fail
  2. Five patterns are a shared vocabulary: Prompt Chaining, Routing, Parallelization, Orchestrator-Subagents, Evaluator-Optimizer — any workflow can be described with these five
  3. Real workflows combine patterns: identifying which part of your system maps to which pattern is what system design ability looks like in practice

References


Check out PrimeSkills — a curated marketplace of AI agents and skills that have been validated in real-world, enterprise-grade workflows. No fluff, just what actually works.

Find more useful knowledge and interesting products on my Homepage