Skip to content

Commit

Permalink
refactor(CompiledGraph.java): remove redundant graph validation and e…
Browse files Browse the repository at this point in the history
…dge processing
  • Loading branch information
bsorrentino committed Feb 11, 2025
1 parent 5ef408c commit dd24149
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions core/src/main/java/org/bsc/langgraph4j/CompiledGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,6 @@ static <State extends AgentState> StateGraphNodesAndEdges<State> process(StateGr

var sgWorkflow = subgraphNode.subGraph();

// validate subgraph
sgWorkflow.validateGraph();

// Process START Node
var sgEdgeStart = sgWorkflow.edges.edgeBySourceId(START).orElseThrow();

Expand All @@ -637,7 +634,7 @@ static <State extends AgentState> StateGraphNodesAndEdges<State> process(StateGr
throw new GraphStateException( format("the node '%s' has not present as target in graph!", subgraphNode.id()) );
}

for( var edgeWithSubgraphTargetId :edgesWithSubgraphTargetId ) {
for( var edgeWithSubgraphTargetId : edgesWithSubgraphTargetId ) {

var sgEdgeStartTarget = sgEdgeStart.target();

Expand All @@ -647,8 +644,8 @@ static <State extends AgentState> StateGraphNodesAndEdges<State> process(StateGr

var newEdge = edgeWithSubgraphTargetId.withSourceAndTargetIdsUpdated( subgraphNode,
Function.identity(),
( id ) -> subgraphNode.formatId( sgEdgeStartTarget.id() ) );

( id ) -> Objects.equals( id, subgraphNode.id() ) ?
subgraphNode.formatId( sgEdgeStartTarget.id() ) : id );
result.edges().elements.remove(edgeWithSubgraphTargetId);
result.edges().elements.add( newEdge );

Expand All @@ -662,7 +659,9 @@ static <State extends AgentState> StateGraphNodesAndEdges<State> process(StateGr
sgEdgesEnd.stream()
.map( e -> e.withSourceAndTargetIdsUpdated( subgraphNode,
subgraphNode::formatId,
( id ) -> edgeWithSubgraphSourceId.target().id())
( id ) -> Objects.equals(id,END) ?
edgeWithSubgraphSourceId.target().id() :
subgraphNode.formatId(id) )
)
.forEach(result.edges().elements::add);
result.edges().elements.remove(edgeWithSubgraphSourceId);
Expand All @@ -680,7 +679,7 @@ static <State extends AgentState> StateGraphNodesAndEdges<State> process(StateGr
// Process nodes

sgWorkflow.nodes.elements.stream()
.map( n -> n.withIdUpdated( subgraphNode::formatId ) )
.map( n -> n.withIdUpdated( subgraphNode::formatId) )
.forEach(result.nodes().elements::add);

}
Expand Down

0 comments on commit dd24149

Please sign in to comment.