Pipeline Composition
Composition turns small typed Flows into a reusable graph you can register, mutate, and drop inside a larger graph — without a second runtime. This example registers a two-stage pipeline, then does two things to it: extends it after construction, and wraps it as a single Flow.
The pieces
Section titled “The pieces”Each payload is an @io record; each stage is a Flow[In, Out]. Nothing here
knows how it will be composed.
Register a pipeline with surfaced ports
Section titled “Register a pipeline with surfaced ports”@retriever.register_pipeline names a graph and declares which internal ports
are visible from the outside. counter.then(policy, map=..., sync=...) wires the
stages; surface_policy="explicit" means only the listed ports cross the boundary.
Extend a declared pipeline
Section titled “Extend a declared pipeline”Because the graph is addressable by node name, you can replace a stage and inject an input on a live pipeline, then step it — no rebuild.
Compose a pipeline as a Flow
Section titled “Compose a pipeline as a Flow”retriever.build_pipeline_flow("golden.composable_counter") hands the registered
pipeline back as an ordinary Flow, so it nests inside a larger graph and its
surfaced output is a typed record.
What you get
Section titled “What you get”Real output. value=104 is Counter (1) + injected bias (3) + OverridePolicy
delta (100); the wrapped stage surfaces both aux and value as one typed record:
Why it’s shaped this way
Section titled “Why it’s shaped this way”Registration puts the graph in the runtime registry with an explicit port
contract, so a composed pipeline is a reusable unit, not a copy-pasted script.
Because payloads stay @io-typed across the boundary, you can:
- replace or inject into a stage by name after construction,
- wrap a whole pipeline as a Flow and nest it, and
- render either level as runtime IR or an HTML graph for inspection.
The rendering path is on the simulation and visualization lane; the field-access rules are in flow contracts.
Source: examples/advanced/core_composition/composable_pipelines.py.
