[BETA] Composer

gllm-pipeline | Tutorial: [BETA] Composer| Use Case: Build End-to-End RAG Pipeline| API Reference

What's a Composer?

A Composer is a fluent API builder that:

  1. Provides a chainable interface for building pipelines step by step.

  2. Manages a Pipeline instance internally and accumulates steps as you call methods.

  3. Offers both direct-style and builder-style patterns for complex operations (branching, conditionals, parallel execution).

  4. Returns the composed Pipeline via the .done() method when you're finished building.

The Composer pattern allows you to build pipelines in a readable, fluent manner:

pipeline = (
    Pipeline()
    .composer
    .step(my_component, {"input": "query"}, "result")
    .log("Processing result: {result}")
    .transform(lambda data: data["result"].upper(), ["result"], "upper_result")
    .terminate()
    .done()
)

Learn in greater detail about input maps in Input Mapping

Prerequisites

This example specifically requires completion of all setup steps listed on the Prerequisites page.

You should be familiar with these concepts:

Installation

Basic Composer Methods

We will first learn the basic composer methods that can be used to create a Pipeline using the fluent API.

Throughout this tutorial page, we will be using the Echo component below as a replacement for our SDK components.

step

The step method wraps and runs a Component with mapped inputs and stores outputs under a state key. This is the composer equivalent of the step() function.

When a step calls a Component, use input_map to map the component's parameter names to keys in your pipeline state. This tells the step where to read each argument.

Learn more about input maps: Input Mapping.

transform

The transform method applies a callable to selected state keys and writes the result. This is the composer equivalent of the transform() function.

bundle

The bundle method collects multiple state keys into a dictionary without changes to their values. This is the composer equivalent of the bundle() function.

log

The log method emits a message through an event emitter. Can be a plain string or a template with state placeholders. This is the composer equivalent of the log() function.

no_op

The no_op method creates a step that does nothing. This is useful as a placeholder step. This is the composer equivalent of the no_op() function.

terminate

The terminate method explicitly terminates the current Pipeline. This is useful as part of conditional flows. This is the composer equivalent of the terminate() function.

Branching

The Composer provides several methods for conditional execution and branching logic.

when / if_else

The Composer provides two approaches for conditional branching:

  1. Builder-style with when() - for fluent conditional building

  2. Direct-style with if_else() - when you have both branches ready

Builder-style: when().then().otherwise().end()

The when() method begins a fluent conditional builder that lets you define branches step-by-step:

Direct-style: if_else()

The if_else() method creates a conditional step when you already have both branches available:

As with the functional if_else(), the condition could also be a Component. In this case, you need to pass an input_map:

switch

The switch method selects a branch from a dict of options based on a condition output (string). Supports both builder-style and direct-style patterns.

Builder-style: switch().case().default().end()

Direct-style: switch()

toggle

The toggle method runs its if_branch if condition is true; otherwise behaves like no_op(). Condition can be callable, Component, or a string key looked up in merged state/config.

This method is useful to enable "optional" steps that are decided at runtime.

Builder-style: toggle().then().end()

Direct-style: toggle()

guard

The guard method evaluates a condition. On success runs success_branch. On failure runs failure_branch, then terminates the current Pipeline.

Builder-style: guard().on_success().on_failure().end()

Direct-style: guard()

Concurrency

The Composer provides methods for parallel execution and map-reduce operations.

parallel

The parallel method runs multiple branches in parallel and merges results. Each branch can be a step or a list of steps.

Builder-style: parallel().fork().end()

Direct-style: parallel()

map_reduce

The map_reduce method maps a function (or Component) over multiple items, then reduces results. This is the composer equivalent of the map_reduce() function.

Composition

subgraph

The subgraph method executes another Pipeline as a step, with flexible input/output mapping. This is the composer equivalent of the subgraph() function.

Complete Example

Here's a comprehensive example showing how to use the Composer to build a complete RAG pipeline:

This example demonstrates:

  • Basic steps (step, log, transform, bundle)

  • Conditional logic (when().then().end(), guard())

  • Fluent chaining of multiple operations

  • Clean, readable pipeline definition using the Composer API

The Composer provides a powerful and expressive way to build complex pipelines while maintaining readability and flexibility.

Last updated