Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make CompiledGraph displayable in Jupyter with display() #2468

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libs/langgraph/langgraph/graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio

Check notice on line 1 in libs/langgraph/langgraph/graph/graph.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 61.0 ms +- 1.4 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 51.0 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 91.0 ms +- 7.6 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 92.9 ms +- 0.9 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 578 ms +- 19 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 498 ms +- 6 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 903 ms +- 43 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 912 ms +- 15 ms ......................................... react_agent_10x: Mean +- std dev: 30.6 ms +- 0.7 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.4 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 46.3 ms +- 0.8 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.4 ms +- 0.5 ms ......................................... react_agent_100x: Mean +- std dev: 342 ms +- 5 ms ......................................... react_agent_100x_sync: Mean +- std dev: 270 ms +- 3 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 929 ms +- 7 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 831 ms +- 5 ms ......................................... wide_state_25x300: Mean +- std dev: 24.1 ms +- 0.4 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 15.4 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 279 ms +- 4 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 267 ms +- 4 ms ......................................... wide_state_15x600: Mean +- std dev: 28.1 ms +- 0.4 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 17.8 ms +- 0.2 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 480 ms +- 5 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 465 ms +- 5 ms ......................................... wide_state_9x1200: Mean +- std dev: 28.1 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 17.8 ms +- 0.5 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 313 ms +- 3 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 299 ms +- 4 ms

Check notice on line 1 in libs/langgraph/langgraph/graph/graph.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +=========================================+=========+=======================+ | fanout_to_subgraph_100x | 628 ms | 578 ms: 1.09x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 973 ms | 903 ms: 1.08x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 93.9 ms | 91.0 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 855 ms | 831 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 937 ms | 912 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 95.2 ms | 92.9 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x | 62.4 ms | 61.0 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 47.2 ms | 46.3 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 946 ms | 929 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 318 ms | 313 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x | 31.1 ms | 30.6 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 18.1 ms | 17.8 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 37.0 ms | 36.4 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 22.8 ms | 22.4 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 347 ms | 342 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 472 ms | 465 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 24.4 ms | 24.1 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 18.0 ms | 17.8 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600 | 28.5 ms | 28.1 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 303 ms | 299 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_sync | 51.6 ms | 51.0 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_sync | 504 ms | 498 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint | 282 ms | 279 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 28.4 ms | 28.1 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 15.6 ms | 15.4 ms: 1.01x faster | +---------------------------------------
import logging
from collections import defaultdict
from typing import (
Expand Down Expand Up @@ -628,3 +628,11 @@
add_edge(key, end, conditional=True)

return graph

def _repr_mimebundle_(self, **kwargs) -> dict[str, Any]:
"""Mime bundle used by Jupyter to display the graph"""
output = {
"text/plain": repr(self),
"image/png": self.get_graph().draw_mermaid_png()
}
return output
Loading