Skip to content

Commit 266fe4a

Browse files
committed
feat: adds subgraph node action
work on #39
1 parent aaf57f1 commit 266fe4a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)