Replies: 2 comments
-
Down the line it would be great to implement a more interactive interface to this, instead of just a png of a mermaid rendering. The ipython display has facilities for this using HTML as that representation, which means you could add in things like disclosure (click the node to see more properties of it, or collapse a subgraph), hovers, clicks, etc. It's probably possible to go overboard and write a whole langgraph studio knock off just in an HTML-base repr for the graph, though I doubt this would be usable (to be clear, I'm not suggesting that!). But a little bit more interactivity in the notebook would be great. |
Beta Was this translation helpful? Give feedback.
-
See PR at #2468 |
Beta Was this translation helpful? Give feedback.
-
At the moment it's pretty clunky to get a visual of either a langgraph graph or a langchain graph of runnables if you are using a jupyter (ipython) notebook. The canonical approach seems to be something like the following:
Where
graph
is aCompiledStateGraph
or the like.Jupyter has strong support for different mimetypes as a cell output format, and this includes PNG/JPG images as well as other mimetypes (notably, HTML). A more natural approach to visualizing the above would just be to write
Or, if it is the last item on the line in the cell, the
display()
function should be called automatically.To achieve this change is actually straight forward -- the display() function just looks for the presence of a few special methods on the object (graph) and if they exist then it will invoke them, and details are provided here: https://ipython.readthedocs.io/en/stable/config/integrating.html. This soft contract means there is no need for external dependencies to be added, which is particularly nice.
I propose that we add something like the following to the graph class:
This preserves the ability to print the graph and see an object reference, while also providing an inline png image of the mermaid representation. Here's an example screenshot showing how this would work in jupyter (specifically in the VS Code jupyter extension) with a monkey patch:
Beta Was this translation helpful? Give feedback.
All reactions