Skip to content

Commit 83e7132

Browse files
committed
refactor(CompiledGraph.java): refine node output construction
Refactors the `streamSnapshots` to return the __START__ completion as StateSnaphot instead of NodeOutput work on #74
1 parent da251d4 commit 83e7132

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/src/main/java/org/bsc/langgraph4j/CompiledGraph.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ public Optional<State> invoke(Map<String,Object> inputs ) {
376376
* @param inputs the input map
377377
* @param config the invoke configuration
378378
* @return an AsyncGenerator stream of NodeOutput
379-
* @throws Exception if there is an error creating the stream
380379
*/
381380
public AsyncGenerator<NodeOutput<State>> streamSnapshots( Map<String,Object> inputs, RunnableConfig config ) {
382381
Objects.requireNonNull(config, "config cannot be null");
@@ -587,9 +586,16 @@ public Data<Output> next() {
587586

588587
if( START.equals(currentNodeId) ) {
589588
nextNodeId = getEntryPoint( currentState );
589+
590+
var cp = addCheckpoint( config, START, currentState, nextNodeId );
591+
592+
var output = ( cp.isPresent() && config.streamMode() == StreamMode.SNAPSHOTS) ?
593+
buildStateSnapshot(cp.get()) :
594+
buildNodeOutput( currentNodeId );
595+
590596
currentNodeId = nextNodeId;
591-
addCheckpoint( config, START, currentState, nextNodeId );
592-
return Data.of( buildNodeOutput( START ) );
597+
598+
return Data.of( output );
593599
}
594600

595601
if( END.equals(nextNodeId) ) {

0 commit comments

Comments
 (0)