Skip to main content
Copy-and-adapt snippets for building workflows. Each example shows the minimal YAML needed for a specific technique.

Basic Patterns

Simple Agent Loop with Auto-Approve

The standard agent pattern: call LLM, execute tools, repeat while there’s work.
Key points:
  • while condition checks for non-empty tool_calls to continue looping
  • No approval step means tools execute automatically

Manual Approval Mode

Add an approval gate before tool execution.
Key points:
  • Approval blocks until user responds or timeout
  • Check nodes.approval.status == 'approved' before proceeding

Plan Mode (Read-Only Tools)

Restrict agent to read-only tools for planning without modifications.
Key points:
  • Use tool_filter to restrict available tools
  • tag:plan includes read-only tools plus planning tools (create_plan, add_task, etc.)
  • Pair with a planning-specific system prompt

Conditional Logic

Branch Based on Exit Code

Route workflow based on command success/failure.
Key points:
  • run nodes expose exit_code, stdout, stderr
  • Use conditions to branch on exit_code

Branch Based on Tool Calls Present

Check if LLM made tool calls to decide next step.
Key points:
  • Always check both != null and size() > 0
  • The label-only case acts as default (no condition)

Loop While Condition Met

Retry while tests fail (up to iteration limit). Uses fork with memo: false so each iteration starts fresh from the original request, with targeted error feedback injected after failures.
Key points:
  • while condition evaluated after each iteration with outputs.* containing results
  • thread: mode: fork with memo: false gives each iteration a fresh start from the original request
  • inject.condition adds error feedback only after the first iteration fails
  • In loop body, iter.iteration is 0-indexed; in while check, it reflects completed iterations

Multi-Agent

Two Agents Taking Turns on Same Thread

Agents alternate on shared context (e.g., proposer/critic debate).
Key points:
  • Both agents use thread: mode: inherit to share context
  • Each agent sees what the other wrote
  • Use inject to add turn-specific instructions

Parallel Agents with Join

Launch multiple agents simultaneously, wait for all to complete.
Key points:
  • See Threads for thread mode documentation (fork, new, inherit)
  • Use unique key values for each parallel branch
  • join: all waits for all incoming edges

Groups for Different Model Configs

Configure different settings for each agent type.
Key points:
  • Groups appear as collapsible sections in UI
  • Use tag: agent to enable preset picker
  • Reference group inputs as inputs.GroupName.field

Context Management

Filter Large Tool Results with CallLLM

Reduce context bloat by summarizing large outputs.
Key points:
  • Check total_result_chars to decide filtering
  • Use ephemeral: true so filter call doesn’t add to thread
  • Save filtered content with original tool_results for proper UI display

Compact When Tokens Exceed Threshold

Trigger context compaction after tool execution.
Key points:
  • thread_token_count available after ExecuteTools or SaveMessage
  • Compact saves its summary message internally with the new context sequence
  • No save_message block needed for Compact nodes

Conditional Message Saving

Save messages only under certain conditions.
Key points:
  • save_message.condition controls whether message is saved
  • Useful for feedback loops (only inject on failure)
  • Message content can reference node outputs via output.*

Approvals and Oversight

Custom Approval with Multiple Actions

Offer multiple response options beyond approve/deny.
Key points:
  • Multiple approve actions can have different value fields
  • Access chosen action via nodes.approval.action_value
  • type: custom for non-standard responses

Audit Check Before Tool Execution

Run an auditor agent before allowing tool execution.
Key points:
  • Use response_tool to force structured output
  • Define options as choice names with descriptions
  • LLM returns { choice: "option_name", value: "explanation" }
  • Access response data via nodes.<execute_tools_node>.response_data.<tool_name>.choice or .value
  • Auditor can use cheaper/faster model

Response Tools for Structured Feedback

Force LLM to provide structured responses via a “response tool.” Response tools use a simplified options-based format where output is always { choice, value }.
Key points:
  • response_tool is a synthetic tool only the LLM can call
  • Define options as option_name: "description for LLM"
  • Output is always { choice: string, value: string }
  • Must execute tools to capture the structured data
  • Access via nodes.<node>.response_data.<tool_name>.choice or .value

Worktrees

Create Worktree for Isolated Work

Give an agent its own working directory.
Key points:
  • Include workflow.id in name for uniqueness
  • force: true overwrites existing worktree with same name
  • Reference worktree path via nodes.create_worktree.path

Copy Env Files to Worktree

Include configuration files in new worktree.
Key points:
  • copy_files searches recursively for matching filenames
  • Directory structure is preserved (e.g., frontend/.envworktree/frontend/.env)
  • Files are copied from source repo, not current worktree

Multiple Parallel Worktrees

Create isolated environments for competing implementations.
Key points:
  • Create worktrees in parallel for faster setup
  • Use thread: mode: new so implementations don’t share context
  • Each parallel edge needs its own - from: block

Complete Workflow Examples

Full workflow definitions showing how patterns combine into real-world solutions.

Code Review Pipeline

Automatically review PRs with multiple specialized agents.
Key techniques:
  • Parallel agents for different review focuses
  • Fork threads to isolate each reviewer’s context
  • Join to wait for all reviews before summarizing

Test-Driven Bug Fix

Implement a fix using a test-first approach with retry loop.
Key techniques:
  • Test-first approach ensures fix is verified
  • Loop with iteration limit prevents infinite retries
  • Conditional message injection adds context on failures

Documentation Generator

Generate documentation for a codebase with structure analysis.
Key techniques:
  • Sequential pipeline: analyze → generate → review
  • Thread inheritance maintains context across stages
  • Specialized prompts for each role

Parallel Implementation Competition

Have multiple agents implement the same feature, then pick the best.
Key techniques:
  • Worktrees provide isolated Git environments
  • thread: mode: new keeps implementations separate
  • Join synchronizes parallel work
  • Final comparison sees both implementations’ context