Basic Patterns
Simple Agent Loop with Auto-Approve
The standard agent pattern: call LLM, execute tools, repeat while there’s work.whilecondition 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.- 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.- Use
tool_filterto restrict available tools tag:readonlyincludes view, grep, glob, etc.- Pair with a planning-specific system prompt
Conditional Logic
Branch Based on Exit Code
Route workflow based on command success/failure.runnodes exposeexit_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.- Always check both
!= nullandsize() > 0 - The label-only case acts as default (no condition)
Loop While Condition Met
Retry while tests fail (up to iteration limit). Usesfork with memo: false so each iteration starts fresh from the original request, with targeted error feedback injected after failures.
whilecondition evaluated after each iteration withoutputs.*containing resultsthread: mode: forkwithmemo: falsegives each iteration a fresh start from the original requestinject.conditionadds error feedback only after the first iteration fails- In loop body,
iter.iterationis 0-indexed; inwhilecheck, it reflects completed iterations
Multi-Agent
Two Agents Taking Turns on Same Thread
Agents alternate on shared context (e.g., proposer/critic debate).- Both agents use
thread: mode: inheritto share context - Each agent sees what the other wrote
- Use
injectto add turn-specific instructions
Parallel Agents with Join
Launch multiple agents simultaneously, wait for all to complete.- See Threads for thread mode documentation (
fork,new,inherit) - Use unique
keyvalues for each parallel branch join: allwaits for all incoming edges
Groups for Different Model Configs
Configure different settings for each agent type.- Groups appear as collapsible sections in UI
- Use
tag: agentto 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.- Check
total_result_charsto decide filtering - Use
ephemeral: trueso 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.thread_token_countavailable after ExecuteTools or SaveMessage- Compact saves its summary message internally with the new context sequence
- No
save_messageblock needed for Compact nodes
Conditional Message Saving
Save messages only under certain conditions.save_message.conditioncontrols 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.- Multiple approve actions can have different
valuefields - Access chosen action via
nodes.approval.action_value type: customfor non-standard responses
Audit Check Before Tool Execution
Run an auditor agent before allowing tool execution.- Use
response_toolto force structured output - Define
optionsas choice names with descriptions - LLM returns
{ choice: "option_name", value: "explanation" } - Access response data via
nodes.<execute_tools_node>.response_data.<tool_name>.choiceor.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 }.
response_toolis 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>.choiceor.value
Worktrees
Create Worktree for Isolated Work
Give an agent its own working directory.- Include
workflow.idin name for uniqueness force: trueoverwrites existing worktree with same name- Reference worktree path via
nodes.create_worktree.path
Copy Env Files to Worktree
Include configuration files in new worktree.copy_filessearches recursively for matching filenames- Directory structure is preserved (e.g.,
frontend/.env→worktree/frontend/.env) - Files are copied from source repo, not current worktree
Multiple Parallel Worktrees
Create isolated environments for competing implementations.- Create worktrees in parallel for faster setup
- Use
thread: mode: newso implementations don’t share context - Each parallel edge needs its own
- from:block