hammerBuilding Pipelines

Three ways to build pipelines, how data flows through steps, and how to configure parameters and options.

🔨 Three Ways to Build

All three approaches produce the same underlying AiRunnableSequence.

Method 1: Fluent Chaining with .to()

The most common approach — chain components using .to():

pipeline = aiMessage()
    .user( "Translate '${text}' to ${language}" )
    .to( aiModel( "openai" ) )
    .to( aiTransform( r => r.content ) )

result = pipeline.run( {
    text    : "Hello, world!",
    language: "Spanish"
} )
// Result: "¡Hola, mundo!"

How it works:

  • Each .to() call creates a new AiRunnableSequence

  • The sequence contains all previous steps + the new step

  • Pipelines are immutable — chaining creates new sequences

Method 2: Helper Methods

Convenience methods for common patterns:

Method 3: Explicit Sequence

For advanced scenarios, create sequences manually:

When to use:

  • Building pipelines dynamically

  • Conditional step inclusion

  • Complex branching logic


📥 Input and Output Flow

Data Passing

Each step receives the previous step's output as its input:

The _input System Variable

When chaining AI stages with AiMessage templates, the previous stage's output is automatically available as ${_input} — no extra transform needed.

Basic usage:

With structured output:

Key points:

  • ${_input} contains the complete previous stage output

  • For struct outputs, fields are also available as ${_input_fieldName}

  • Original context variables from .run() are still accessible

  • Stages are only connected through _input — they remain encapsulated

Multi-stage example:

Input Types by Component

Component
Accepts
Example

AiMessage

Struct (bindings)

{ name: "Alice", role: "admin" }

AiModel

Messages array / AiMessage

[{ role: "user", content: "Hi" }]

AiTransform

Any type

String, struct, array, etc.

AiAgent

String (user message)

"What's the weather?"

Output Types

The final output depends on the last step in the pipeline:


⚙️ Parameters and Options

Default Parameters

Set parameters that apply to all executions of a pipeline:

Runtime Parameter Overrides

Override defaults at execution time:

Merge behavior: runtime parameters override defaults; unspecified parameters use defaults.

Options vs Parameters

Parameters configure the AI provider (model, temperature, etc.). Options configure the runnable behavior (returnFormat, timeout, logging).

Last updated