Workflow Patterns

Five composable patterns — chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer — that cover most of what production agent systems actually do.

▶ Watch this reel

What you'll learn

  1. Prompt chaining & routing
  2. Parallelization
  3. Orchestrator-workers
  4. Evaluator-optimizer

Remember this

Chaining & routing

Parallelization

Orchestrator-workers

Evaluator-optimizer

Code: Evaluator-optimizer, implemented

async def refine_until_pass(spec: str, checks: list[callable],
                              max_rounds: int = 3) -> Draft:
    draft = await llm(GEN_PROMPT, spec=spec)
    history = []

    for round in range(max_rounds):
        # mechanical checks first — free and honest
        failures = [c(draft) for c in checks if not c(draft)]
        if not failures:
            return draft

        # model judge for the non-mechanical criteria
        critique = await llm(CRITIQUE_PROMPT, draft=draft,
                             failures=failures)
        history.append({"round": round, "critique": critique})
        draft = await llm(REFINE_PROMPT, spec=spec, draft=draft,
                          feedback=critique)          # fix ONLY the gaps

    # budget out → escalate with full history
    await escalate_to_human(draft, history)
    return draft   # labeled 'unrefined' — never silently final