Fluent API for building workflows

Provides a chainable interface for constructing complex workflows.

const workflow = new WorkflowBuilder('customer-onboarding', '1.0.0')
.agent('welcome-agent', {
input: { type: 'variable', name: 'customerData' },
output: 'welcomeMessage'
})
.tool('sendEmail', {
type: 'variable',
name: 'welcomeMessage'
})
.condition(
'${premium}',
(then) => then.agent('premium-onboarding'),
(else) => else.agent('standard-onboarding')
)
.build();

Constructors

Methods

  • Add an agent execution step

    Parameters

    • agentId: string
    • options: { input: StepInput; output?: string; retry?: RetryPolicy; timeout?: number }

    Returns this

    builder.agent('my-agent', {
    input: { type: 'variable', name: 'query' },
    output: 'agentResponse',
    timeout: 30000
    })
  • Add a tool execution step

    Parameters

    • toolName: string
    • input: StepInput
    • Optionaloptions: { output?: string; retry?: RetryPolicy; timeout?: number }

    Returns this

    builder.tool('sendEmail', {
    type: 'variable',
    name: 'emailData'
    })
  • Add a conditional branching step

    Parameters

    Returns this

    builder.condition(
    '${isPremium}',
    (then) => then.agent('premium-agent'),
    (else) => else.agent('standard-agent')
    )
  • Add a parallel execution step

    Parameters

    Returns this

    builder.parallel(
    (branch) => branch.agent('agent-1'),
    (branch) => branch.agent('agent-2'),
    (branch) => branch.tool('tool-1', input)
    )
  • Add a loop step

    Parameters

    • collection: StepInput
    • itemVariable: string
    • loopBuilder: (builder: WorkflowBuilder) => void
    • OptionalmaxIterations: number

    Returns this

    builder.loop(
    { type: 'variable', name: 'items' },
    'item',
    (loop) => loop
    .agent('process-item', {
    input: { type: 'variable', name: 'item' }
    })
    )
  • Add a human-in-the-loop step

    Parameters

    • prompt: string
    • Optionaloptions: string[]
    • Optionalconfig: { timeout?: number; assignee?: string; output?: string }

    Returns this

    builder.humanApproval(
    'Please approve this request',
    ['Approve', 'Reject'],
    {
    timeout: 3600000, // 1 hour
    output: 'approvalDecision'
    }
    )
  • Add a RAG query step

    Parameters

    • pipelineId: string
    • query: StepInput
    • Optionaloptions: { topK?: number; output?: string }

    Returns this

    builder.rag(
    'default-pipeline',
    { type: 'variable', name: 'userQuery' },
    {
    topK: 5,
    output: 'ragResults'
    }
    )
  • Add a data transformation step

    Parameters

    • input: StepInput
    • expression: string
    • output: string

    Returns this

    builder.transform(
    { type: 'variable', name: 'rawData' },
    '${$input.toUpperCase()}',
    'processedData'
    )
  • Create a retry policy

    Parameters

    • config: {
          maxRetries: number;
          initialDelay?: number;
          maxDelay?: number;
          backoffMultiplier?: number;
          retryableErrors?: string[];
      }

    Returns RetryPolicy