TypeScript API Reference
Build type-safe ensembles with full IDE support, autocomplete, and compile-time validation.Why TypeScript?
TypeScript ensembles offer several advantages over YAML:- Type Safety: Catch configuration errors at compile time
- IDE Support: Full autocomplete, inline documentation, and refactoring
- Dynamic Logic: Build steps conditionally using code
- Reusability: Share and compose steps across multiple ensembles
- Testing: Easier unit testing of ensemble configurations
Quick Start
createEnsemble
Create a new ensemble with the fluent builder API.Methods
.setDescription(description: string)
Set a description for the ensemble.
.setInput<T>()
Define the input type for the ensemble (TypeScript generics for type safety).
.setOutput<T>()
Define the output type for the ensemble.
.addStep(step: Step)
Add a step to the ensemble. Steps execute sequentially by default, but steps without dependencies run in parallel.
.addSteps(...steps: Step[])
Add multiple steps at once.
.build()
Finalize and return the ensemble configuration.
step
Create an individual step within an ensemble.Methods
.agent(name: string)
Reference an agent by name.
.operation(type: string)
Use an inline operation instead of an agent.
.input(inputs: Record<string, any>)
Provide inputs to the step. Supports expression syntax like ${input.field} and ${previousStep.output}.
.config(config: Record<string, any>)
Provide configuration for an operation.
.condition(expression: string)
Conditionally execute the step.
.retry(options: RetryOptions)
Configure retry behavior for the step.
.cache(options: CacheOptions)
Configure caching for the step.
.timeout(ms: number)
Set a timeout for the step.
Flow Control Primitives
TypeScript ensembles support advanced flow control patterns through specialized primitives.parallel
Execute multiple steps concurrently.branch
Conditional branching based on a condition.foreach
Iterate over an array, executing a step for each item.Options
tryStep
Error handling with try/catch semantics.switchStep
Multi-way branching based on a value.whileStep
Loop while a condition is true.mapReduce
Process items in parallel (map) then aggregate results (reduce).Version Primitives (Edgit Integration)
Version primitives enable referencing components managed by Edgit with precise version pinning. This is essential for production workflows requiring reproducible deployments.componentRef
Create a versioned reference to any component type.Options
versionedAgent
Create a versioned agent reference for use in ensemble steps.Batch Creation
versionedEnsemble
Reference and compose versioned sub-ensembles.deploymentRef
Reference components by deployment environment rather than explicit version.Version Constraints
Support for semver-style version constraints:| Constraint | Meaning | Example |
|---|---|---|
1.2.3 | Exact version | Only v1.2.3 |
^1.2.0 | Compatible (same major) | v1.2.0, v1.3.0, v1.9.9 |
~1.2.0 | Patch-compatible (same minor) | v1.2.0, v1.2.1, v1.2.9 |
>=1.0.0 | Minimum version | v1.0.0 and above |
<=2.0.0 | Maximum version | v2.0.0 and below |
latest | Latest available | Most recent version |
stable | Latest stable | Most recent non-prerelease |
Utility Functions
Integration with Edgit
Version primitives integrate directly with Edgit’s Git tag namespaces:Type-Specific Namespaces
Both Edgit (Git tags) and Conductor (KV storage) use type-specific namespaces:| Component Type | Git Tag Namespace | KV Key Prefix |
|---|---|---|
prompt | prompts/ | prompts: |
schema | schemas/ | schemas: |
config | configs/ | configs: |
script | scripts/ | scripts: |
query | queries/ | queries: |
template | templates/ | templates: |
tool | tools/ | tools: |
agent | agents/ | agents: |
ensemble | ensembles/ | ensembles: |
Complete Example
Here’s a complete TypeScript ensemble that demonstrates multiple features:Expression Syntax
TypeScript ensembles support the same expression syntax as YAML:Variable Access
Array Indexing
Nullish Coalescing (??)
Returns the first value that is notnull or undefined:
Falsy Coalescing (||)
Returns the first truthy value (catches"", 0, false, null, undefined):
Ternary Conditionals (?:)
Boolean Negation (!)
Conditionals
Filter Chains
Functions
AgentExecutionContext
When writing TypeScript handlers for agents, you receive a rich execution context with access to all project resources.Using AgentExecutionContext
Component Registries
Component registries provide access to versioned, reusable project resources:Discovery Registries
Discovery registries enable runtime introspection of available agents and ensembles:Project Configuration Access
Access the full project configuration from any agent:Type Definitions
EnsembleDefinition
AgentDefinition
OutputConfig
OutputFormat
ApiConfig
Project-level configuration for Execute API access control.RetryOptions
CacheOptions
Step
Migration from YAML
Converting a YAML ensemble to TypeScript:- YAML
- TypeScript
Best Practices
- Export as default - Always export your ensemble as the default export
- Use TypeScript generics - Define input/output types for better type safety
- Organize by domain - Keep related ensembles in the same directory
- Reuse steps - Extract common patterns into shared step factories
- Validate early - Use
ensemble conductor validateto check TypeScript ensembles

