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(langgraph): Add tags and run name to message stream output #2312

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions libs/langgraph/langgraph/pregel/messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import (

Check notice on line 1 in libs/langgraph/langgraph/pregel/messages.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 57.8 ms +- 1.5 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 48.7 ms +- 0.5 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 82.3 ms +- 1.6 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 90.4 ms +- 0.6 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 540 ms +- 12 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 476 ms +- 5 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 903 ms +- 40 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 900 ms +- 19 ms ......................................... react_agent_10x: Mean +- std dev: 30.3 ms +- 0.6 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.0 ms +- 0.1 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 46.0 ms +- 1.0 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 35.7 ms +- 0.5 ms ......................................... react_agent_100x: Mean +- std dev: 338 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 269 ms +- 3 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 917 ms +- 9 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 820 ms +- 9 ms ......................................... wide_state_25x300: Mean +- std dev: 23.2 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 14.7 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 275 ms +- 9 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 262 ms +- 3 ms ......................................... wide_state_15x600: Mean +- std dev: 27.0 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 16.9 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 478 ms +- 9 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 459 ms +- 7 ms ......................................... wide_state_9x1200: Mean +- std dev: 27.0 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 16.9 ms +- 0.1 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 309 ms +- 3 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 295 ms +- 3 ms

Check notice on line 1 in libs/langgraph/langgraph/pregel/messages.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +========================================+=========+=======================+ | react_agent_100x_checkpoint_sync | 870 ms | 820 ms: 1.06x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 47.9 ms | 46.0 ms: 1.04x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 36.8 ms | 35.7 ms: 1.03x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 22.4 ms | 22.0 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 17.2 ms | 16.9 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 17.1 ms | 16.9 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 313 ms | 309 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint_sync | 265 ms | 262 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 464 ms | 459 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 545 ms | 540 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 298 ms | 295 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 924 ms | 917 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 91.0 ms | 90.4 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_sync | 48.9 ms | 48.7 ms: 1.00x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 868 ms | 903 ms: 1.04x slower | +----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.01x faster | +----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (13): wide_state_25x300_checkpoint, fanout_to_subgraph_10x, wide_state_15x600, fanout_to_subgraph_10x_checkpoint, wide_state_15x600_checkpoint, react_agent_10x, react_agent_100x_sync, fanout_to_subgraph_100x_sync, wide_state_25x300, wide_state_25x300_sync, wide_state_9x1200, react_agent_100x, fanout_to_subgraph_100x_checkpoint_sync
Any,
AsyncIterator,
Callable,
Expand Down Expand Up @@ -61,12 +61,13 @@
parent_run_id: Optional[UUID] = None,
tags: Optional[list[str]] = None,
metadata: Optional[dict[str, Any]] = None,
name: Optional[str] = None,
**kwargs: Any,
) -> Any:
if metadata and (not tags or TAG_NOSTREAM not in tags):
self.metadata[run_id] = (
tuple(cast(str, metadata["langgraph_checkpoint_ns"]).split(NS_SEP)),
metadata,
{"name": name, "tags": tags, **metadata},
)

def on_llm_new_token(
Expand Down Expand Up @@ -112,16 +113,17 @@
parent_run_id: Optional[UUID] = None,
tags: Optional[List[str]] = None,
metadata: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
**kwargs: Any,
) -> Any:
if (
metadata
and kwargs.get("name") == metadata.get("langgraph_node")
and name == metadata.get("langgraph_node")
and (not tags or TAG_HIDDEN not in tags)
):
self.metadata[run_id] = (
tuple(cast(str, metadata["langgraph_checkpoint_ns"]).split(NS_SEP)),
metadata,
{"name": name, "tags": tags, **metadata},
)

def on_chain_end(
Expand Down
Loading