Skip to main content
Agents do work. Ensembles coordinate agents.

Ensemble Structure

Key Concepts

Agents in Ensembles

Ensembles orchestrate agents:

Input/Output Mapping

Input: Data passed to ensemble
Access in agents:
Output: Shape the final result

Flow Control

Sequential Execution

Agents run in order by default:

Parallel Execution

Agents without dependencies run in parallel:

Conditional Execution

Skip agents based on conditions:

State Management

Share state across agents:

Ensemble Caching

Cache entire ensemble results:

Error Handling

Fallbacks

Validation

Conditional Output Blocks

Control HTTP response status codes, headers, and body formats based on execution results. Conditional outputs allow you to implement proper REST API semantics, handle errors gracefully, and support multiple response formats.

Basic Conditional Outputs

Use when conditions to select the appropriate response:
Key concepts:
  • Conditions are evaluated in order
  • First matching when condition is used
  • Block without when acts as default fallback
  • Always provide a fallback for safety

Custom Status Codes

Support all HTTP status codes (2xx, 3xx, 4xx, 5xx):

HTTP Redirects

Implement redirects with custom status codes:
Redirect status codes:
  • 301 - Permanent redirect (browsers cache)
  • 302 - Temporary redirect (default)
  • 303 - See Other (POST → GET)
  • 307 - Temporary redirect (preserve method)
  • 308 - Permanent redirect (preserve method)

Custom Headers

Add custom headers to responses:

Response Formats

Use the format field to automatically serialize responses and set Content-Type headers:
Format Options:
When to use format:
  • Non-JSON content (XML, CSV, YAML, plain text)
  • File downloads (CSV, iCalendar)
  • API documentation formats (RSS, Atom)
  • Automatic Content-Type handling
When to use body (default JSON):
  • JSON API responses
  • Object/array data structures
  • Standard REST APIs

Complex Example: RESTful CRUD

Complete example with multiple status codes and error handling:

Best Practices

  1. Always provide a fallback - Include a default output block without when
  2. Order matters - Place more specific conditions first
  3. Use appropriate status codes - Follow HTTP semantics
  4. Include error details - Help clients debug issues
  5. Set proper headers - Content-Type, Cache-Control, etc.
  6. Handle authentication - Return 401/403 for auth failures
  7. Validate input - Return 422 for validation errors
  8. Use format for non-JSON - Use the format field for CSV, XML, YAML, etc.

Real-World Patterns

RAG Pipeline

Multi-Agent Analysis

HITL Approval Flow

A/B Testing in Ensembles

Test different variants:

TypeScript Ensembles

For developers who prefer TypeScript, you can create ensembles programmatically with full type safety:

Basic Example

Flow Control in TypeScript

TypeScript ensembles support advanced flow control primitives:
For complete TypeScript API documentation, see the TypeScript API Reference.

Best Practices

  1. Start Simple - One agent, then add complexity
  2. Parallel by Default - Conductor parallelizes automatically
  3. Cache Strategically - Cache expensive operations
  4. Handle Failures - Always have fallbacks
  5. Use State Sparingly - Only when truly needed
  6. Test Thoroughly - Integration test ensembles
  7. Monitor Performance - Track execution times
  8. Version Components - Use Edgit for prompts/configs

Next Steps

TypeScript API

Complete TypeScript reference

Flow Control

Advanced flow patterns

State Management

Deep dive into state

Playbooks

Real-world examples