Skip to content

Commit

Permalink
refactor(core/StateGraph.java): update node construction and refactor…
Browse files Browse the repository at this point in the history
… subgraph management

- Replace `SubGraphNodeAction` with `SubCompiledGraphNode`
- Rename methods to clarify their purpose (`onlySubStateGraphNodes`, `exceptSubStateGraphNodes`)
  • Loading branch information
bsorrentino committed Feb 6, 2025
1 parent 5c02247 commit 6dc6be4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions core/src/main/java/org/bsc/langgraph4j/StateGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ public StateGraph<State> addSubgraph(String id, CompiledGraph<State> subGraph) t
throw Errors.invalidNodeIdentifier.exception(END);
}

var node = new Node<>(id, (config ) ->
new SubgraphNodeAction<>(subGraph)
);
var node = new SubCompiledGraphNode<>(id, subGraph);

if (nodes.elements.contains(node)) {
throw Errors.duplicateNodeError.exception(id);
Expand All @@ -279,7 +277,7 @@ public StateGraph<State> addSubgraph(String id, StateGraph<State> subGraph) thro

subGraph.validateGraph();

var node = new SubGraphNode<>( id, subGraph );
var node = new SubStateGraphNode<>( id, subGraph );

if (nodes.elements.contains(node)) {
throw Errors.duplicateNodeError.exception(id);
Expand Down Expand Up @@ -435,16 +433,16 @@ public boolean anyMatchById(String id ) {
.anyMatch( n -> Objects.equals( n.id(), id) );
}

public List<SubGraphNode<State>> subGraphNodes() {
public List<SubStateGraphNode<State>> onlySubStateGraphNodes() {
return elements.stream()
.filter(n -> n instanceof SubGraphNode<State>)
.map(n -> (SubGraphNode<State>) n)
.filter(n -> n instanceof SubStateGraphNode<State>)
.map(n -> (SubStateGraphNode<State>) n)
.toList();
}

public List<Node<State>> withoutSubGraphNodes() {
public List<Node<State>> exceptSubStateGraphNodes() {
return elements.stream()
.filter(n -> !(n instanceof SubGraphNode<State>) )
.filter(n -> !(n instanceof SubStateGraphNode<State>) )
.toList();
}
}
Expand Down

0 comments on commit 6dc6be4

Please sign in to comment.