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

langgraph: fix ismethod check in add_node #3032

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion libs/langgraph/langgraph/graph/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import inspect

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

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 61.5 ms +- 1.7 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 53.1 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 74.4 ms +- 0.9 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 95.3 ms +- 1.6 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 604 ms +- 24 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 521 ms +- 15 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 751 ms +- 12 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 962 ms +- 18 ms ......................................... react_agent_10x: Mean +- std dev: 31.0 ms +- 0.9 ms ......................................... react_agent_10x_sync: Mean +- std dev: 23.0 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 38.4 ms +- 0.7 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.9 ms +- 0.4 ms ......................................... react_agent_100x: Mean +- std dev: 343 ms +- 6 ms ......................................... react_agent_100x_sync: Mean +- std dev: 272 ms +- 3 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 643 ms +- 9 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 623 ms +- 7 ms ......................................... wide_state_25x300: Mean +- std dev: 23.3 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 15.3 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 249 ms +- 13 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 246 ms +- 13 ms ......................................... wide_state_15x600: Mean +- std dev: 27.2 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 17.8 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 429 ms +- 14 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 426 ms +- 13 ms ......................................... wide_state_9x1200: Mean +- std dev: 27.3 ms +- 0.6 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 17.8 ms +- 0.4 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 280 ms +- 13 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 276 ms +- 12 ms

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

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +=========================================+=========+=======================+ | fanout_to_subgraph_100x_checkpoint | 764 ms | 751 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 612 ms | 604 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 649 ms | 643 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 346 ms | 343 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_sync | 274 ms | 272 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 967 ms | 962 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_sync | 53.3 ms | 53.1 ms: 1.00x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 15.3 ms | 15.3 ms: 1.00x slower | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 17.7 ms | 17.8 ms: 1.00x slower | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 17.7 ms | 17.8 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 38.2 ms | 38.4 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x faster | +-----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (17): fanout_to_subgraph_10x_checkpoint_sync, fanout_to_subgraph_10x_checkpoint, wide_state_25x300_checkpoint_sync, wide_state_9x1200_checkpoint_sync, wide_state_9x1200_checkpoint, react_agent_10x_checkpoint_sync, react_agent_10x_sync, react_agent_100x_checkpoint_sync, wide_state_15x600, fanout_to_subgraph_10x, wide_state_15x600_checkpoint, wide_state_25x300_checkpoint, react_agent_10x, fanout_to_subgraph_100x_sync, wide_state_25x300, wide_state_9x1200, wide_state_15x600_checkpoint_sync
import logging
import typing
import warnings
Expand Down Expand Up @@ -361,7 +361,11 @@

ends = EMPTY_SEQ
try:
if (isfunction(action) or ismethod(getattr(action, "__call__", None))) and (
if (
isfunction(action)
or ismethod(action)
or ismethod(getattr(action, "__call__", None))
) and (
hints := get_type_hints(getattr(action, "__call__"))
or get_type_hints(action)
):
Expand Down
12 changes: 11 additions & 1 deletion libs/langgraph/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ def miss_all_hint(state, config):
def pre_foo(_) -> FooState:
return {"foo": "bar"}

def pre_bar(_) -> FooState:
return {"foo": "bar"}

class Foo:
def __call__(self, state: FooState) -> OutputState:
assert state.pop("foo") == "bar"
return {"input_state": state}

class Bar:
def my_node(self, state: FooState) -> OutputState:
assert state.pop("foo") == "bar"
return {"input_state": state}

graph = StateGraph(InputState, output=OutputState)
actions = [
complete_hint,
Expand All @@ -92,6 +100,8 @@ def __call__(self, state: FooState) -> OutputState:
miss_all_hint,
pre_foo,
Foo(),
pre_bar,
Bar().my_node,
]

for action in actions:
Expand All @@ -112,7 +122,7 @@ def get_name(action) -> str:
foo_state = FooState(foo="bar")
for i, c in enumerate(graph.stream(input_state, stream_mode="updates")):
node_name = get_name(actions[i])
if node_name == get_name(pre_foo):
if node_name in {"pre_foo", "pre_bar"}:
assert c[node_name] == foo_state
else:
assert c[node_name] == output_state
Expand Down
Loading