Skip to content

The agent engineering platform.

fix: core: draw_mermaid() would create subgroup for edges with same src and tgt (#21275)

Nuno Campos6e1e0c7d5c4f
diff --git a/libs/core/langchain_core/runnables/graph_mermaid.py b/libs/core/langchain_core/runnables/graph_mermaid.py
index 61b922ae68..69a2d84562 100644
--- a/libs/core/langchain_core/runnables/graph_mermaid.py
+++ b/libs/core/langchain_core/runnables/graph_mermaid.py
@@ -64,8 +64,8 @@ def draw_mermaid(
subgraph = ""
# Add edges to the graph
for edge in edges:
- src_prefix = edge.source.split(":")[0]
- tgt_prefix = edge.target.split(":")[0]
+ src_prefix = edge.source.split(":")[0] if ":" in edge.source else None
+ tgt_prefix = edge.target.split(":")[0] if ":" in edge.target else None
# exit subgraph if source or target is not in the same subgraph
if subgraph and (subgraph != src_prefix or subgraph != tgt_prefix):
mermaid_graph += "\tend\n"