Prerequisites. Installed SDK · API key set · about 20 minutes. Familiarity with Pipeline overview helps.
What you’ll build
Build the routing pipeline
ai_routing takes a query string and a list of plain-text conditions. The model picks one and emits the matching path_N flag, which downstream nodes consume via dependencies=[router.path_N].merge(function="first", ...) then collapses to whichever branch produced a value.See the ai-routing-node example for the standalone pattern.Run both branches
Two inputs — one greeting, one technical — exercise both routing paths.The output’s
result key matches the output node’s node_name. If you see an empty result, the router picked a path with no downstream node — check that every path_N declared in conditions has a corresponding node with dependencies=[router.path_N].Add conditional logic with `ConditionNode`
For non-AI branching (numeric thresholds, string emptiness, etc.) use See the
condition with the typed primitives. condition.path_0 is the If, path_1 is Else-If, path_else is Else.condition-node example for the full operator catalogue.Compose with sub-pipelines
Big workflows want to be broken into modules. Reference an already-saved See the
Pipeline from inside a parent pipeline using PipelineNode. Pass the Pipeline object as pipeline= (not just its id) — the node introspects the sub-pipeline to expose its inputs as kwargs and its outputs as attributes.sub-pipeline example.Inspect every node's output while debugging
pipeline.run() only returns final outputs. To see what each intermediate node produced, run with pipeline.stream(inputs=...) instead — the streaming surface yields "stream" chunks for every node before the final "result" chunk.Intermediate
stream chunks are emitted when nodes are configured to publish them (e.g. an LLM node added with .llm(stream=True)). Pipelines without any streaming-configured node may produce only the final result chunk — that’s expected. See the intermediate-results example for the canonical pattern.Operational tips
- Numbered paths only.
ai_routingemitspath_0,path_1, …; there is nopath_elseon AI routing. If everypath_Ncould fail to match, add a fallback condition explicitly (e.g. a final"None of the above"condition). - Test sub-pipelines in isolation. Each
Pipelineruns independently. Hit a sub-pipeline directly when the parent is misbehaving — it narrows the bug fast. - Cache sub-pipeline ids. The parent references children by id; don’t recreate sub-pipelines on every deploy or you’ll leak orphans.
- Reach for
stream()while iterating. Once the pipeline is shaped right, the finalrun()is faster — but during development the per-node stream chunks save you from blind print-debugging the LLM prompt.
What’s next
Background batch
Run this workflow over thousands of inputs.
Sub-pipeline example
The composition pattern, isolated.
Pipeline reference
Every node type and method.
