Interface FlowStep<T>
- Type Parameters:
T- the type of value this step produces and clips into the context under its step name
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
EasyAI.flow() pipeline: a single unit of work that reads the
shared FlowContext and produces a result.
A step is just a function FlowContext -> result. What it does inside is entirely
yours: call a plain Java service (inventory.checkStock(...)), or — only where you
genuinely need language — call the LLM (EasyAI.extract(...).from(ctx.inputText()) or
EasyAI.chat().build().send(...)). The flow itself never calls a model; it only runs the
steps you wrote, in the order you wrote them. That is the whole point: the order is
your deterministic Java, the model is invited in only at the edges you declare.
Familiar analogy: a single station on an assembly line. The job folder
(FlowContext) slides in with everything the previous stations clipped into it; this
station reads what it needs, does its one job, and clips its own result back into the folder
before it slides on. A station does not decide the order of the line — that was fixed when the
line was laid out.
Place in the flow
EasyAI.flow()
→ FlowBuilder.step("checkStock", ctx -> ...) // you register a FlowStep here
→ FlowBuilder.build() → Flow
→ Flow.run(input) → invokes each FlowStep.run(ctx) in registration order
Because a step is a pure function of its FlowContext, it is trivially unit-testable:
hand it a FlowContext carrying a canned prior result (a mocked LLM output, say) and
assert on what it returns — no live model, no HTTP.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionrun(FlowContext ctx) Runs this step against the flow's shared context.
-
Method Details
-
run
Runs this step against the flow's shared context.Called by
Flow.run(Object)once, at this step's position in the pipeline. TheFlowContextpassed in is an immutable snapshot holding the flow's original input plus the results of every step that already ran, keyed by their step names (read them withFlowContext.get(String, Class)). The value returned here is stored under this step's name and becomes visible to every later step (and toFlowContext.result()/FlowContext.trail()at the end).Checked exceptions are allowed so a step can call service methods that throw without ceremony;
Flow.run(Object)wraps any thrown exception in aFlowExceptiontagged with this step's name and stops the pipeline.- Parameters:
ctx- the shared, immutable-snapshot context for this run (nevernull)- Returns:
- this step's result, to be stored under the step's name for downstream steps
- Throws:
Exception- if the step fails; the flow wraps it inFlowExceptionand aborts
-