Ensemble Structure
Key Concepts
Agents in Ensembles
Ensembles orchestrate agents:Input/Output Mapping
Input: Data passed to ensembleFlow 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
Usewhen conditions to select the appropriate response:
- Conditions are evaluated in order
- First matching
whencondition is used - Block without
whenacts 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: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 theformat field to automatically serialize responses and set Content-Type headers:
| Type | Content-Type | Description |
|---|---|---|
json | application/json | JSON serialization (default) |
text | text/plain | Plain text |
html | text/html | HTML content |
xml | application/xml | XML content |
csv | text/csv | CSV serialization from arrays |
markdown | text/markdown | Markdown content |
yaml | application/x-yaml | YAML serialization |
ics | text/calendar | iCalendar format |
rss | application/rss+xml | RSS feed |
atom | application/atom+xml | Atom feed |
format:
- Non-JSON content (XML, CSV, YAML, plain text)
- File downloads (CSV, iCalendar)
- API documentation formats (RSS, Atom)
- Automatic Content-Type handling
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
- Always provide a fallback - Include a default output block without
when - Order matters - Place more specific conditions first
- Use appropriate status codes - Follow HTTP semantics
- Include error details - Help clients debug issues
- Set proper headers - Content-Type, Cache-Control, etc.
- Handle authentication - Return 401/403 for auth failures
- Validate input - Return 422 for validation errors
- Use format for non-JSON - Use the
formatfield 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
- TypeScript
- YAML
Flow Control in TypeScript
TypeScript ensembles support advanced flow control primitives:For complete TypeScript API documentation, see the TypeScript API Reference.
Best Practices
- Start Simple - One agent, then add complexity
- Parallel by Default - Conductor parallelizes automatically
- Cache Strategically - Cache expensive operations
- Handle Failures - Always have fallbacks
- Use State Sparingly - Only when truly needed
- Test Thoroughly - Integration test ensembles
- Monitor Performance - Track execution times
- Version Components - Use Edgit for prompts/configs

