[BETA] Composer
gllm-pipeline | Tutorial: [BETA] Composer| Use Case: Build End-to-End RAG Pipeline| API Reference
New in gllm-pipeline v0.4.18
This feature is still in Beta.
What's a Composer?
A Composer is a fluent API builder that:
Provides a chainable interface for building pipelines step by step.
Manages a
Pipelineinstance internally and accumulates steps as you call methods.Offers both direct-style and builder-style patterns for complex operations (branching, conditionals, parallel execution).
Returns the composed
Pipelinevia 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
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.
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:
Builder-style with
when()- for fluent conditional buildingDirect-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