What are Conductor Commands?
Conductor Commands are YAML-based flow control primitives that enable you to build sophisticated AI workflows with branching, loops, parallel execution, error handling, and advanced patterns like map-reduce. Think of them as the control structures of a programming language, but declarative and designed for edge execution. Commands operate on steps (member executions) and coordinate how they execute in relation to each other, enabling patterns from simple sequential flows to complex multi-agent orchestration.Command Categories
Parallel Execution
Run multiple steps concurrently for better performance
Loops
Iterate over data with foreach and while commands
Conditional Logic
Branch execution with if/then/else and switch
Error Handling
Graceful error recovery with try/catch/finally
Advanced Patterns
Map-reduce and other sophisticated workflows
Step-Level Features
Dependencies, conditions, timeouts, and retries
Quick Example
Here’s a real-world ensemble that uses multiple commands:Parallel
Execute multiple steps concurrently for improved performance. Syntax:waitFor(optional):all(default) waits for all steps to complete,anyreturns after first completion
- Fetching data from multiple APIs simultaneously
- Running multiple AI models in parallel for comparison
- Concurrent database queries
- Independent validation checks
Performance: Parallel execution can significantly reduce total workflow time. A workflow with 3 steps that each take 1 second runs in ~1 second with parallel vs ~3 seconds sequential.
Loops
ForEach
Iterate over an array of items, executing a step for each item. Syntax:items: Expression that resolves to an arraymaxConcurrency(optional): Maximum parallel executions (default: 1)breakWhen(optional): Expression to exit loop earlystep: Step definition to execute for each item
${item}: Current item from the array${index}: Current iteration index (0-based)
- Processing lists of records
- Batch AI inference
- Multi-target data collection
- Bulk validation
While
Execute steps repeatedly while a condition is true. Syntax:condition: Expression that resolves to booleanmaxIterations(optional): Maximum loop iterations (prevents infinite loops)steps: Array of steps to execute each iteration
- Pagination through API results
- Iterative refinement of AI outputs
- Processing until quality threshold met
- Queue-based workflows
Safety Limits: Always set
maxIterations on while loops to prevent infinite execution. Cloudflare Workers have a 30-second CPU time limit for HTTP requests.Conditionals
Branch
Conditional execution with if/then/else logic. Syntax:condition: Expression that resolves to booleanthen: Steps to execute if condition is trueelse(optional): Steps to execute if condition is false
- Quality-based routing
- Feature flags
- A/B testing
- Fallback strategies
Switch
Multi-way branching based on a value. Syntax:value: Expression to evaluate (string, number, boolean)cases: Map of possible values to step arraysdefault(optional): Steps to execute if no case matches
- Category-based routing
- Multi-tenant workflows
- Content type handling
- Priority-based processing
Error Handling
Try/Catch/Finally
Graceful error handling with optional cleanup. Syntax:steps: Steps to attemptcatch(optional): Steps to execute on errorfinally(optional): Steps to always execute (even on error)
${error.message}: Error message${error.stack}: Stack trace${error.code}: Error code (if available)
- External API calls with fallbacks
- Database operations with rollback
- Resource cleanup
- Error logging and alerting
Catch Scope: Error details are only available in the catch block via
${error.*} variables.Advanced Patterns
Map-Reduce
Parallel processing with aggregation. Syntax:items: Expression resolving to arraymaxConcurrency(optional): Parallel map executionsmap: Step to execute for each itemreduce: Step to aggregate all map outputs
- Large-scale document processing
- Distributed computation
- Batch AI inference with aggregation
- Multi-source data aggregation
Step-Level Features
Individual steps can have additional configuration regardless of the command they’re in.Dependencies
Explicit step ordering withdepends_on.
Syntax:
- Fine-grained control over parallel execution
- Complex dependency graphs
- Resource coordination
Conditional Execution
Skip steps withwhen condition.
Syntax:
- Feature flags
- Optional processing
- Environment-specific steps
Timeouts
Limit step execution time. Syntax:timeout: Maximum execution time in millisecondsonTimeout.fallback: Value to use if timeout occursonTimeout.error: Treat timeout as error (default: true)
Retry Logic
Automatic retry with backoff strategies. Syntax:attempts: Maximum retry attemptsbackoff: Strategy -fixed,linear, orexponentialinitialDelay(optional): First retry delay (ms)maxDelay(optional): Maximum delay between retriesretryOn(optional): Only retry specific error codes
fixed: Same delay between all retrieslinear: Delay increases linearly (delay, 2delay, 3delay)exponential: Delay doubles each time (delay, 2delay, 4delay, 8*delay)
Command Composition
Commands can be nested to create sophisticated workflows:Best Practices
Performance Optimization
Performance Optimization
- Use
parallelfor independent operations - Set appropriate
maxConcurrencyin foreach (5-10 is often optimal) - Add timeouts to prevent hanging operations
- Use
waitFor: anywhen only first result matters
Error Resilience
Error Resilience
- Always wrap external calls in try/catch
- Use retry logic for transient failures
- Set
maxIterationson all while loops - Provide fallback values for timeouts
Code Organization
Code Organization
- Use meaningful step IDs for complex flows
- Prefer branch over nested conditions
- Use switch for 3+ branches
- Keep nesting depth reasonable (3-4 levels max)
Debugging
Debugging
- Add logging members at key points
- Use state to track progress through loops
- Set step IDs for easier output reference
- Include metadata in outputs for tracing
Cost Management
Cost Management
- Cache expensive AI operations
- Use parallel sparingly (more compute = higher cost)
- Set
maxConcurrencyto prevent runaway costs - Add conditional guards for expensive paths
Examples
Parallel Processing
Multi-source data gathering with parallel execution
Conditional Logic
Quality-based routing and fallback strategies
Error Handling
Graceful degradation with try/catch
Company Intelligence
Real-world workflow using multiple commands

