Skip to content

Commit c3c3409

Browse files
jasonphillipsbenjamincburns
authored andcommitted
fix: throw on duplicate subgraphs in diagram, only descend 1 level at a time
1 parent cf022e8 commit c3c3409

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

langchain-core/src/runnables/graph_mermaid.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export function drawMermaid(
110110
const subgraph = prefix.split(":").pop()!;
111111

112112
if (seenSubgraphs.has(prefix)) {
113-
return;
113+
throw new Error(
114+
`Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +
115+
"you're reusing a subgraph node with the same name. " +
116+
"Please adjust your graph to have subgraph nodes with unique names."
117+
);
114118
}
115119

116120
seenSubgraphs.add(prefix);
@@ -121,7 +125,9 @@ export function drawMermaid(
121125
const nestedPrefixes = sortPrefixesByDepth(
122126
Object.keys(edgeGroups).filter(
123127
(nestedPrefix) =>
124-
nestedPrefix.startsWith(`${prefix}:`) && nestedPrefix !== prefix
128+
nestedPrefix.startsWith(`${prefix}:`) &&
129+
nestedPrefix !== prefix &&
130+
nestedPrefix.split(":").length === prefix.split(":").length + 1
125131
)
126132
);
127133

0 commit comments

Comments
 (0)