The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core[minor]: handle boolean data in draw_mermaid (#23135)
Vadym Bardab483bf509520
diff --git a/libs/core/langchain_core/runnables/graph.py b/libs/core/langchain_core/runnables/graph.pyindex 4f35205e85..bb4559f35a 100644--- a/libs/core/langchain_core/runnables/graph.py+++ b/libs/core/langchain_core/runnables/graph.py@@ -11,6 +11,7 @@ from typing import (List,NamedTuple,Optional,+ Protocol,Tuple,Type,TypedDict,@@ -25,6 +26,11 @@ if TYPE_CHECKING:from langchain_core.runnables.base import Runnable as RunnableType+class Stringifiable(Protocol):+ def __str__(self) -> str:+ ...++class LabelsDict(TypedDict):"""Dictionary of labels for nodes and edges in a graph."""@@ -55,7 +61,7 @@ class Edge(NamedTuple):source: strtarget: str- data: Optional[str] = None+ data: Optional[Stringifiable] = Noneconditional: bool = False@@ -253,7 +259,7 @@ class Graph:self,source: Node,target: Node,- data: Optional[str] = None,+ data: Optional[Stringifiable] = None,conditional: bool = False,) -> Edge:"""Add an edge to the graph and return it."""diff --git a/libs/core/langchain_core/runnables/graph_mermaid.py b/libs/core/langchain_core/runnables/graph_mermaid.pyindex b99c90f9a7..402b0ee4f3 100644--- a/libs/core/langchain_core/runnables/graph_mermaid.py+++ b/libs/core/langchain_core/runnables/graph_mermaid.py@@ -81,7 +81,7 @@ def draw_mermaid(# Add BR every wrap_label_n_words wordsif edge.data is not None:edge_data = edge.data- words = edge_data.split() # Split the string into words+ words = str(edge_data).split() # Split the string into words# Group words into chunks of wrap_label_n_words sizeif len(words) > wrap_label_n_words:edge_data = "<br>".join(diff --git a/libs/core/langchain_core/runnables/graph_png.py b/libs/core/langchain_core/runnables/graph_png.pyindex 75983ad279..0fbeec7e35 100644--- a/libs/core/langchain_core/runnables/graph_png.py+++ b/libs/core/langchain_core/runnables/graph_png.py@@ -160,8 +160,8 @@ class PngDrawer:self.add_node(viz, node)def add_edges(self, viz: Any, graph: Graph) -> None:- for start, end, label, cond in graph.edges:- self.add_edge(viz, start, end, label, cond)+ for start, end, data, cond in graph.edges:+ self.add_edge(viz, start, end, str(data), cond)def update_styles(self, viz: Any, graph: Graph) -> None:if first := graph.first_node():