Pattern 1: Constructor Injection
Configuration known at build time — model, prompt template, threshold, API client. Same step class, different parameters, different behavior.@Bean with constructor injection.
Pattern 2: Input Chaining
Each step receives the previous step’s output as itsinput parameter. No context keys, no configuration — just linear data flow.
Pattern 3: Context Keys
What if step C needs step A’s output, but step B sits between them? The executor auto-propagates every step’s output intoAgentContext under Steps.outputOf(stepName). Any downstream step can read any prior step’s result by name.
Typed context for structured data
When steps produce structured data (lists, records, domain objects), downstream steps cast from the auto-propagated output:Pattern 4: Mixed — All Three Together
Real-world steps combine constructor config + input chaining + context state:Pattern 5: Context Writes (updateContext)
A step’s primary job is to return a value — the category string for branching, the translated text for the next step. But sometimes a step also knows metadata that other steps need: the confidence score, the detected language, the list of sources used.
Without updateContext(), the only way to pass all of this is to return a record — which forces every downstream step to know about that record type, killing reusability. With updateContext(), the step returns its primary output AND publishes metadata as typed context keys.
Example: Classification with confidence and reasoning
"medical" as its primary output (used by the branch). The confidence and reasoning are published as side-channel metadata. Any downstream step reads them without knowing anything about the classifier’s internals:
Example: Language detection as side-channel
ContextKey constants as its published output contract. Downstream steps read by key — no coupling to the producing step’s record type.
Most users never need
updateContext(). Start with input chaining (Pattern 1). Add Steps.outputOf() when you need non-adjacent data (Pattern 3). Reach for updateContext() only when a step genuinely produces metadata that should travel separately from its primary output.Quick Reference
Related
DSL Primitives
Sequential, parallel, gate, loop, branch, and more
Complete Examples
Runnable integration tests including context writes