Skip to main content

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:

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: This alignment ensures Git tags created by Edgit map directly to KV keys used by Conductor at runtime.

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 not null 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:

Best Practices

  1. Export as default - Always export your ensemble as the default export
  2. Use TypeScript generics - Define input/output types for better type safety
  3. Organize by domain - Keep related ensembles in the same directory
  4. Reuse steps - Extract common patterns into shared step factories
  5. Validate early - Use ensemble conductor validate to check TypeScript ensembles

Next Steps

Your First Ensemble

Build your first ensemble

YAML Schema

YAML configuration reference

CLI Commands

Command line reference

Flow Control

Advanced flow patterns