Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public abstract class BaseLlmFlow implements BaseFlow {

// Warning: This is local, in-process state that won't be preserved if the runtime is restarted.
// "Max steps" is experimental and may evolve in the future (e.g., to support persistence).
protected int stepsCompleted = 0;
protected final int maxSteps;

public BaseLlmFlow(
Expand Down Expand Up @@ -393,8 +392,12 @@ private Flowable<Event> runOneStep(InvocationContext context) {
*/
@Override
public Flowable<Event> run(InvocationContext invocationContext) {
return run(invocationContext, 0);
}

private Flowable<Event> run(InvocationContext invocationContext, int stepsCompleted) {
Flowable<Event> currentStepEvents = runOneStep(invocationContext).cache();
if (++stepsCompleted >= maxSteps) {
if (stepsCompleted + 1 >= maxSteps) {
logger.debug("Ending flow execution because max steps reached.");
return currentStepEvents;
}
Expand All @@ -413,7 +416,7 @@ public Flowable<Event> run(InvocationContext invocationContext) {
return Flowable.empty();
} else {
logger.debug("Continuing to next step of the flow.");
return Flowable.defer(() -> run(invocationContext));
return Flowable.defer(() -> run(invocationContext, stepsCompleted + 1));
}
}));
}
Expand Down