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:
- Context starts with
name: "World" - Step "greet" spawns zen-architect agent
- Prompt expands to: "Say hello to World"
- Agent response stored as
{{`{greeting}`}} - 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:
- Step 1 executes → summary stored to context
- Context now:
{file_path, summary} - Step 2 has access to BOTH
{{`{summary}`}}AND{{`{file_path}`}} - Step 2 executes → key_points stored
- 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:
- Bash step checks file existence (exit code 0 = exists, non-zero = missing)
- Exit code stored as
{{`{file_exists_code}`}} - IF code == 0: analyze step runs (file exists)
- ELSE: report-missing step runs (file not found)
- Skipped steps don't execute, their outputs are undefined
Key learning:
- Bash steps: Fast, no LLM overhead, capture exit codes
- Conditions: Python expressions evaluated before step
- Branching: Different paths based on runtime values
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:
- Step 1: AI analyzes impact
- Step 2: Recipe pauses, shows impact to human
- IF approved: Steps 3-4 execute (upgrade + verify)
- IF denied: Steps 3-4 skipped, recipe ends safely
Key learning:
- Approval gates prevent destructive operations without review
on_approval_denied: skip_remainingaborts safely- Human sees AI analysis before decision
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:
- Foreach step iterates over files list
- Spawns 3 concurrent sub-recipes (one per file, up to 3 at once)
- Each sub-recipe runs its lint-file step
- Results collected as array:
[{file: "auth.py", lint_result: "..."}, ...] - Aggregate step processes all results together
Key learning:
- Only foreach loops support parallelism
- Regular steps are always sequential
max_concurrentlimits parallel execution- Results are arrays of {foreach_var, step_outputs}
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 |