Recipe Examples - Progressive Learning

Learn recipes through 5 progressive examples, building from the simplest "hello world" to advanced parallel processing. Each example introduces new concepts.

Example 1: Hello Recipes (Simplest)

Concepts: Basic structure, context variables, single step

name: "hello-recipe"
description: "Your first recipe"
version: "1.0.0"

context:
  name: "World"

steps:
  - id: "greet"
    agent: "foundation:zen-architect"
    prompt: "Say hello to {{`{name}`}}"
    output: "greeting"

What happens:

  1. Context starts with name: "World"
  2. Step "greet" spawns zen-architect agent
  3. Prompt expands to: "Say hello to World"
  4. Agent response stored as {{`{greeting}`}}
  5. Recipe completes with final context containing greeting

Run it:

amplifier run "execute hello-recipe.yaml"

# Or customize:
amplifier run "execute hello-recipe.yaml with name=Alice"

Key learning: Context variables ({{`{name}`}}) are replaced before agent sees prompt.

Example 2: Two-Step Analysis (Context Accumulation)

Concepts: Multiple steps, output chaining, context growth

name: "file-analysis"
description: "Analyze a file in two steps"
version: "1.0.0"

context:
  file_path: "README.md"

steps:
  - id: "summarize"
    agent: "foundation:explorer"
    prompt: "Read {{`{file_path}`}} and write a 3-sentence summary"
    output: "summary"
    timeout: 300

  - id: "extract-key-points"
    agent: "foundation:zen-architect"
    prompt: |
      Based on this summary: {{`{summary}`}}

      Identify 3 key points from {{`{file_path}`}}.
    output: "key_points"
    timeout: 300

What happens:

  1. Step 1 executes → summary stored to context
  2. Context now: {file_path, summary}
  3. Step 2 has access to BOTH {{`{summary}`}} AND {{`{file_path}`}}
  4. Step 2 executes → key_points stored
  5. Final context: {file_path, summary, key_points}

Key learning: Each step sees all previous outputs. Context accumulates!

Example 3: Conditional Workflow (Branching)

Concepts: Bash steps, exit codes, conditions, branching logic

name: "conditional-workflow"
version: "1.0.0"

context:
  file_path: "src/auth.py"

steps:
  - id: "check-file-exists"
    type: "bash"
    command: "test -f {{`{file_path}`}}"
    output_exit_code: "file_exists_code"
    on_error: "continue"

  - id: "analyze-if-exists"
    condition: "{{`{file_exists_code}`}} == '0'"
    agent: "foundation:zen-architect"
    prompt: "Analyze {{`{file_path}`}} for code quality"
    output: "analysis"

  - id: "report-missing"
    condition: "{{`{file_exists_code}`}} != '0'"
    agent: "foundation:zen-architect"
    prompt: "File {{`{file_path}`}} not found. Suggest where it should be."
    output: "alternatives"

What happens:

  1. Bash step checks file existence (exit code 0 = exists, non-zero = missing)
  2. Exit code stored as {{`{file_exists_code}`}}
  3. IF code == 0: analyze step runs (file exists)
  4. ELSE: report-missing step runs (file not found)
  5. Skipped steps don't execute, their outputs are undefined

Key learning:

Example 4: Approval Gates (Human-in-Loop)

Concepts: Safety gates, human approval, skip on denial

name: "careful-upgrade"
description: "Upgrade with human approval"
version: "1.0.0"

context:
  package: "requests"

steps:
  - id: "analyze-impact"
    agent: "foundation:zen-architect"
    prompt: "Analyze what upgrading {{`{package}`}} would change in requirements.txt"
    output: "impact_analysis"

  - id: "approval-gate"
    requires_approval: true
    approval_prompt: |
      Impact Analysis: {{`{impact_analysis}`}}

      This will modify requirements.txt.
      Proceed with upgrade?
    on_approval_denied: "skip_remaining"

  - id: "apply-upgrade"
    type: "bash"
    command: "pip install --upgrade {{`{package}`}}"
    output: "upgrade_result"
    timeout: 600

  - id: "verify"
    type: "bash"
    command: "pip show {{`{package}`}}"
    output: "verification"

What happens:

  1. Step 1: AI analyzes impact
  2. Step 2: Recipe pauses, shows impact to human
  3. IF approved: Steps 3-4 execute (upgrade + verify)
  4. IF denied: Steps 3-4 skipped, recipe ends safely

Key learning:

Example 5: Parallel Processing (Advanced)

Concepts: Foreach loops, parallel execution, result aggregation

name: "multi-file-lint"
description: "Lint multiple files in parallel"
version: "1.0.0"

context:
  files:
    - "src/auth.py"
    - "src/users.py"
    - "src/db.py"
    - "src/api.py"

steps:
  - id: "parallel-lint"
    foreach: "{{`{files}`}}"
    foreach_var: "file"
    max_concurrent: 3
    steps:
      - id: "lint-file"
        agent: "foundation:zen-architect"
        prompt: "Lint {{`{file}`}} and report code quality issues"
        output: "lint_result"
        timeout: 300
    output: "all_lint_results"

  - id: "aggregate-results"
    agent: "foundation:zen-architect"
    prompt: |
      Summarize all lint results: {{`{all_lint_results}`}}

      Identify the most critical issues across all files.
    output: "summary"

What happens:

  1. Foreach step iterates over files list
  2. Spawns 3 concurrent sub-recipes (one per file, up to 3 at once)
  3. Each sub-recipe runs its lint-file step
  4. Results collected as array: [{file: "auth.py", lint_result: "..."}, ...]
  5. Aggregate step processes all results together

Key learning:

Learning Progression Summary

Example Concepts Introduced Next Step
1. Hello Recipes Basic structure, variables, single step Add second step
2. Two-Step Analysis Multiple steps, output chaining Add branching
3. Conditional Workflow Bash steps, conditions, branching Add safety
4. Approval Gates Human review, safety gates Add concurrency
5. Parallel Processing Foreach, concurrent execution Build real workflows!

Official Examples Repository

The recipes bundle includes 11 working examples:

Recipe File Complexity What It Demonstrates
simple-analysis-recipe.yaml Beginner Basic 3-step sequential flow
bash-step-example.yaml Beginner Shell commands, env vars, exit codes
conditional-workflow.yaml Intermediate Conditional logic, branching
code-review-recipe.yaml Intermediate Real-world analysis pipeline
dependency-upgrade-recipe.yaml Intermediate Approval gates, error handling
parallel-analysis-recipe.yaml Advanced Foreach loops, concurrent execution
comprehensive-review.yaml Advanced All features combined

View all examples on GitHub →

Next Steps