Skip to content

The agent engineering platform.

Fix missing labels (#18356)

Nuno Campos7891934173b4
diff --git a/libs/core/langchain_core/runnables/graph.py b/libs/core/langchain_core/runnables/graph.py
index 77137d0a86..557a2028c3 100644
--- a/libs/core/langchain_core/runnables/graph.py
+++ b/libs/core/langchain_core/runnables/graph.py
@@ -263,4 +263,17 @@ class Graph:
) -> Union[bytes, None]:
from langchain_core.runnables.graph_png import PngDrawer
- return PngDrawer(fontname, labels).draw(self, output_file_path)
+ default_node_labels = {
+ node.id: node_data_str(node) for node in self.nodes.values()
+ }
+
+ return PngDrawer(
+ fontname,
+ LabelsDict(
+ nodes={
+ **default_node_labels,
+ **(labels["nodes"] if labels is not None else {}),
+ },
+ edges=labels["edges"] if labels is not None else {},
+ ),
+ ).draw(self, output_file_path)