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 all 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
7 changes: 7 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.7 ms +- 1.4 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 51.4 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 91.5 ms +- 7.3 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 93.2 ms +- 0.7 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 589 ms +- 22 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 501 ms +- 5 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 921 ms +- 47 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 919 ms +- 16 ms ......................................... react_agent_10x: Mean +- std dev: 30.7 ms +- 0.7 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.3 ms +- 0.2 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 46.7 ms +- 0.8 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.7 ms +- 0.5 ms ......................................... react_agent_100x: Mean +- std dev: 342 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 269 ms +- 2 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 939 ms +- 11 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 836 ms +- 7 ms ......................................... wide_state_25x300: Mean +- std dev: 24.0 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 +- 5 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 267 ms +- 6 ms ......................................... wide_state_15x600: Mean +- std dev: 28.1 ms +- 0.6 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 17.8 ms +- 0.2 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 479 ms +- 5 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 468 ms +- 9 ms ......................................... wide_state_9x1200: Mean +- std dev: 28.0 ms +- 0.5 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 17.8 ms +- 0.1 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 | 609 ms | 589 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 22.8 ms | 22.3 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 935 ms | 919 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 94.7 ms | 93.2 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 47.4 ms | 46.7 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 28.5 ms | 28.0 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x | 31.1 ms | 30.7 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 933 ms | 921 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_sync | 273 ms | 269 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 18.0 ms | 17.8 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 317 ms | 313 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_sync | 52.0 ms | 51.4 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 302 ms | 299 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 15.5 ms | 15.4 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_sync | 506 ms | 501 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 37.0 ms | 36.7 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 24.2 ms | 24.0 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 842 ms | 836 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600 | 28.3 ms | 28.1 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 345 ms | 342 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 482 ms | 479 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 17.9 ms | 17.8 ms: 1.00x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 466 ms | 468 ms: 1.00x slower | +-----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.01x faster | +-----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (5): fanout_to_subgraph_10x_checkpoint, fanout_to_subgraph_10x, react_agent_
import logging
from collections import defaultdict
from typing import (
Expand Down Expand Up @@ -629,3 +629,10 @@
add_edge(key, end, conditional=True)

return graph

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