Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cookbook

lacause edited this page Mar 29, 2026 · 1 revision

Cookbook

Practical recipes and patterns for common tasks.

Recipe 1: Research → Validate → Report

Classic pattern: gather data from multiple sources, validate quality, produce a report.

name: validated-research
inputs:
 - name: topic
steps:
 # Parallel research
 - id: source_a
 pre_tools:
 - type: web_search
 query: "{input.topic} overview"
 inject_as: data
 prompt: "Analyze: {data}"
 output_var: research_a
 - id: source_b
 pre_tools:
 - type: web_search
 query: "{input.topic} criticism debate"
 inject_as: data
 prompt: "Analyze contrarian view: {data}"
 output_var: research_b
 # Validate
 - id: validate
 type: evaluator
 depends_on: [source_a, source_b]
 input_var: research_a
 criteria: "Are sources cited? Is data specific? Score 1-10."
 eval_scoring: true
 eval_threshold: 6
 on_fail: retry
 retry_target: source_a
 max_retries: 1
 prompt: "validate"
 output_var: validation
 # Report
 - id: report
 depends_on: [validate, source_b]
 prompt: |
 Write a balanced report using:
 Main research: {research_a}
 Contrarian view: {research_b}
 output_var: final_report
output: final_report

Recipe 2: Router-Based Code Review

Route to specialized reviewers based on codebase type.

name: smart-review
inputs:
 - name: path
steps:
 - id: classify
 type: router
 tools: [Glob, Read]
 prompt: |
 Look at {input.path}. Classify as: frontend, backend, or infra.
 routes:
 frontend: [review_ui, review_a11y]
 backend: [review_api, review_security]
 infra: [review_security, review_perf]
 default_route: backend
 output_var: type
 - id: review_ui
 depends_on: [classify]
 tools: [Read, Grep]
 prompt: "Review UI code at {input.path} for component design and UX."
 output_var: ui_review
 - id: review_a11y
 depends_on: [classify]
 tools: [Read, Grep]
 prompt: "Review accessibility at {input.path}."
 output_var: a11y_review
 - id: review_api
 depends_on: [classify]
 tools: [Read, Grep]
 prompt: "Review API design at {input.path}."
 output_var: api_review
 - id: review_security
 depends_on: [classify]
 tools: [Read, Grep]
 prompt: "Security audit of {input.path}."
 output_var: security_review
 - id: review_perf
 depends_on: [classify]
 tools: [Read, Grep, Bash]
 prompt: "Performance review of {input.path}."
 output_var: perf_review
 - id: summary
 depends_on: [review_ui, review_a11y, review_api, review_security, review_perf]
 prompt: |
 Compile final review report from available reviews:
 UI: {ui_review}
 A11y: {a11y_review}
 API: {api_review}
 Security: {security_review}
 Performance: {perf_review}
 output_var: report
output: report

Recipe 3: Loop with Early Exit

Iterate until a condition is met.

name: iterative-improvement
inputs:
 - name: draft
steps:
 - id: improve
 type: loop
 items_var: "1,2,3,4,5" # Max 5 iterations
 max_parallel: 1 # Sequential (each builds on previous)
 loop_until: '{eval_score} > "8"' # Stop when quality is high enough
 step_template:
 type: agent
 prompt: |
 Improve this draft (iteration {item}):
 {draft}
 Fix any issues found. Make it clearer and more complete.
 prompt: "Improve iteratively"
 output_var: improved
 - id: evaluate
 type: evaluator
 depends_on: [improve]
 input_var: improved
 criteria: "Score quality 1-10."
 eval_scoring: true
 eval_threshold: 8
 on_fail: skip
 prompt: "evaluate"
 output_var: eval_score
output: improved

Recipe 4: Human-in-the-Loop Pipeline

Get approval before expensive operations.

name: safe-deploy
inputs:
 - name: changes
steps:
 - id: analyze
 prompt: "Analyze these changes for risk: {input.changes}"
 output_var: risk_analysis
 - id: approve
 type: gate
 depends_on: [analyze]
 prompt: |
 Risk analysis: {risk_analysis}

 Approve deployment?
 timeout_hours: 4
 on_timeout: error
 output_var: approval
 - id: deploy
 depends_on: [approve]
 condition: '{approval} contains "approved"'
 tools: [Bash]
 prompt: "Deploy the changes: {input.changes}"
 output_var: deploy_result
output: deploy_result

Recipe 5: Data Pipeline with Transforms

Process data without unnecessary LLM calls.

name: data-pipeline
inputs:
 - name: api_url
steps:
 - id: fetch
 pre_tools:
 - type: http_fetch
 url: "{input.api_url}"
 inject_as: raw_data
 prompt: "Parse this API response into structured JSON: {raw_data}"
 output_var: parsed
 output_schema: json
 - id: extract_items
 type: transform
 operation: json_extract
 input_var: parsed
 json_path: "items"
 prompt: "extract"
 output_var: items
 - id: filter_active
 type: transform
 operation: filter
 input_var: items
 prompt: "filter"
 output_var: active_items
 - id: analyze
 depends_on: [filter_active]
 prompt: "Analyze these items and identify trends: {active_items}"
 output_var: analysis
output: analysis

Steps extract_items and filter_active cost zero tokens.

Recipe 6: Multi-Model Cost Optimization

Use the cheapest model that can handle each step.

name: cost-optimized
inputs:
 - name: document
steps:
 - id: classify
 model: claude-haiku-4-5 # Cheapest: 0ドル.25/M
 prompt: "Classify document type: {input.document}. Return: legal, technical, or business."
 output_var: doc_type
 - id: extract
 model: claude-haiku-4-5 # Simple extraction
 depends_on: [classify]
 prompt: "Extract key facts from: {input.document}"
 output_var: facts
 - id: analyze
 model: claude-sonnet-4-6 # Mid-tier: 3ドル/M
 depends_on: [extract]
 prompt: "Deep analysis of {doc_type} document. Facts: {facts}"
 output_var: analysis
 - id: executive_summary
 model: claude-opus-4-6 # Premium: 15ドル/M (only for final output)
 depends_on: [analyze]
 prompt: "Write executive summary: {analysis}"
 output_var: summary
output: summary

Pattern: Retry with Escalation

Start with a cheap model, escalate to expensive on failure.

- id: generate
 model: claude-haiku-4-5
 retry:
 max: 2
 delay_ms: 1000
 fallback_models:
 - claude-sonnet-4-6 # Try Sonnet if Haiku fails
 - claude-opus-4-6 # Try Opus as last resort
 prompt: "Generate complex analysis..."
 output_var: result

Pattern: Cached Expensive Steps

Cache results from expensive operations.

- id: market_data
 model: claude-opus-4-6
 cache:
 enabled: true
 ttl_minutes: 360 # Cache for 6 hours
 pre_tools:
 - type: web_search
 query: "market analysis {input.sector}"
 inject_as: web_data
 prompt: "Comprehensive market analysis of {input.sector}: {web_data}"
 output_var: market_analysis

Second run within 6 hours: 0 tokens, ~1ms.

See Also

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /