File tree 1 file changed +35
-0
lines changed
core-jdk8/src/main/java/org/bsc/langgraph4j/subgraph
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .bsc .langgraph4j .subgraph ;
2
+
3
+ import lombok .NonNull ;
4
+ import org .bsc .async .AsyncGenerator ;
5
+ import org .bsc .langgraph4j .CompiledGraph ;
6
+ import org .bsc .langgraph4j .NodeOutput ;
7
+ import org .bsc .langgraph4j .RunnableConfig ;
8
+ import org .bsc .langgraph4j .action .AsyncNodeActionWithConfig ;
9
+ import org .bsc .langgraph4j .action .NodeActionWithConfig ;
10
+ import org .bsc .langgraph4j .state .AgentState ;
11
+
12
+ import java .util .Map ;
13
+
14
+ import static org .bsc .langgraph4j .utils .CollectionsUtils .mapOf ;
15
+
16
+ public class SubgraphNodeAction <State extends AgentState > implements NodeActionWithConfig <State > {
17
+
18
+ public static <State extends AgentState > AsyncNodeActionWithConfig <State > of ( @ NonNull CompiledGraph <State > subGraph ) {
19
+ return AsyncNodeActionWithConfig .node_async ( new SubgraphNodeAction <State >(subGraph ) );
20
+ }
21
+
22
+ final CompiledGraph <State > subGraph ;
23
+
24
+ protected SubgraphNodeAction (CompiledGraph <State > subGraph ) {
25
+ this .subGraph = subGraph ;
26
+ }
27
+
28
+ @ Override
29
+ public Map <String , Object > apply (State state , RunnableConfig config ) throws Exception {
30
+
31
+ AsyncGenerator <NodeOutput <State >> generator = subGraph .stream ( state .data (), config );
32
+
33
+ return mapOf ( "_subgraph" , generator );
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments