Skip to content

Commit e7938e4

Browse files
committed
feat(CompiledGraph): integrate embedding generator.
- manage resume state after completion of an embed generator work on #31
1 parent 3c254e8 commit e7938e4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,11 @@ private Optional<Data<Output>> getEmbedGenerator( Map<String,Object> partialStat
426426
.findFirst()
427427
.map( e ->
428428
Data.composeWith( (AsyncGenerator<Output>)e.getValue(), data -> {
429-
partialState.put( e.getKey(), data );
430-
currentState = AgentState.updateState(currentState, partialState, stateGraph.getChannels());
429+
if( !(data instanceof Map) ) {
430+
throw new IllegalArgumentException("Embedded generator must return a Map");
431+
}
432+
currentState = AgentState.updateState(currentState, (Map<String, Object>)data, stateGraph.getChannels());
433+
nextNodeId = nextNodeId(currentNodeId, currentState);
431434
})
432435
)
433436
;
@@ -439,7 +442,9 @@ private CompletableFuture<Data<Output>> evaluateAction(AsyncNodeAction<State> ac
439442
try {
440443

441444
Optional<Data<Output>> embed = getEmbedGenerator( partialState );
442-
if( embed.isPresent() ) return embed.get();
445+
if( embed.isPresent() ) {
446+
return embed.get();
447+
}
443448

444449
currentState = AgentState.updateState(currentState, partialState, stateGraph.getChannels());
445450
nextNodeId = nextNodeId(currentNodeId, currentState);
@@ -516,9 +521,7 @@ public Data<Output> next() {
516521
}
517522
catch( Exception e ) {
518523
log.error( e.getMessage(), e );
519-
CompletableFuture<Output> future = new CompletableFuture<>();
520-
future.completeExceptionally(e);
521-
return Data.of(future);
524+
return Data.error(e);
522525
}
523526

524527

0 commit comments

Comments
 (0)