in spring-ai-alibaba-graph/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/CompiledGraph.java [771:829]
public Data<Output> next() {
// GUARD: CHECK MAX ITERATION REACHED
if (++iteration > maxIterations) {
log.warn("Maximum number of iterations ({}) reached!", maxIterations);
return Data.done(currentState);
}
// GUARD: CHECK IF IT IS END
if (nextNodeId == null && currentNodeId == null)
return Data.done(currentState);
try {
// IS IT A RESUME FROM EMBED ?
if (resumedFromEmbed) {
final CompletableFuture<Output> future = getNodeOutput();
resumedFromEmbed = false;
return Data.of(future);
}
if (START.equals(currentNodeId)) {
nextNodeId = getEntryPoint(currentState);
currentNodeId = nextNodeId;
addCheckpoint(config, START, currentState, nextNodeId);
return Data.of(buildNodeOutput(START));
}
if (END.equals(nextNodeId)) {
nextNodeId = null;
currentNodeId = null;
return Data.of(buildNodeOutput(END));
}
// check on previous node
if (shouldInterruptAfter(currentNodeId, nextNodeId))
return Data.done();
if (shouldInterruptBefore(nextNodeId, currentNodeId))
return Data.done();
currentNodeId = nextNodeId;
AsyncNodeActionWithConfig action = nodes.get(currentNodeId);
if (action == null)
throw StateGraph.RunnableErrors.missingNode.exception(currentNodeId);
return evaluateAction(action, overAllState).get();
}
catch (Exception e) {
if (e instanceof ExecutionException executionException
&& executionException.getCause() instanceof GraphInterruptException interruptException) {
overAllState.setInterruptMessage(interruptException.getMessage());
return Data.done(buildNodeOutput(currentNodeId));
}
log.error(e.getMessage(), e);
return Data.error(e);
}
}