I’m using langgraph in a Jupyter notebook to build a simple state machine and then render the graph with Mermaid via mermaid.ink. In one snippet of code, naming the node "A" causes a timeout error from Mermaid:
%%capture --no-stderr
%pip install -U langgraph typing-extensions
from IPython.display import Image
from typing_extensions import TypedDict
from langgraph.graph import StateGraph
class ClientContext(TypedDict):
client_id: str
graph_builder = StateGraph(ClientContext)
def chatbot(state: ClientContext):
return {"messages": "Yam"}
graph_builder.add_node("A", chatbot)
graph_builder.set_entry_point("A")
graph_builder.set_finish_point("A")
graph = graph_builder.compile()
graph_image = Image(graph.get_graph().draw_mermaid_png()) # <-- Times out
The error is:
TimeoutError: The read operation timed out
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='mermaid.ink', port=443):
Read timed out. (read timeout=10)
Has anyone else encountered Mermaid timeout errors specifically tied to certain node labels in langgraph or Mermaid diagrams?
When I change the node name to "chatbot" (see code below), everything runs normally and the Mermaid diagram is successfully rendered:
from IPython.display import Image
from typing_extensions import TypedDict
from langgraph.graph import StateGraph
class ClientContext(TypedDict):
client_id: str
graph_builder = StateGraph(ClientContext)
def chatbot(state: ClientContext):
return {"messages": "Yam"}
graph_builder.add_node("chatbot", chatbot)
graph_builder.set_entry_point("chatbot")
graph_builder.set_finish_point("chatbot")
graph = graph_builder.compile()
graph_image = Image(graph.get_graph().draw_mermaid_png()) # <-- Works
