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 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
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.4 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 53.3 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 74.8 ms +- 1.2 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 96.3 ms +- 2.6 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 608 ms +- 25 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 520 ms +- 13 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 763 ms +- 22 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 964 ms +- 19 ms ......................................... react_agent_10x: Mean +- std dev: 30.9 ms +- 0.7 ms ......................................... react_agent_10x_sync: Mean +- std dev: 23.0 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 38.2 ms +- 0.8 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 37.0 ms +- 0.4 ms ......................................... react_agent_100x: Mean +- std dev: 343 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 272 ms +- 4 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 652 ms +- 8 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 629 ms +- 9 ms ......................................... wide_state_25x300: Mean +- std dev: 23.4 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 15.4 ms +- 0.4 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 253 ms +- 16 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 246 ms +- 14 ms ......................................... wide_state_15x600: Mean +- std dev: 27.4 ms +- 0.6 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 17.8 ms +- 0.2 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 433 ms +- 17 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 426 ms +- 15 ms ......................................... wide_state_9x1200: Mean +- std dev: 27.3 ms +- 0.6 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 17.7 ms +- 0.2 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 280 ms +- 14 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 275 ms +- 13 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 | +========================================+=========+=======================+ | react_agent_100x_sync | 274 ms | 272 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x | 346 ms | 343 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 23.2 ms | 23.4 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 95.6 ms | 96.3 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 17.7 ms | 17.8 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 623 ms | 629 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 15.3 ms | 15.4 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | wide_state_15x600 | 27.1 ms | 27.4 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 428 ms | 433 ms: 1.01x slower | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint | 248 ms | 253 ms: 1.02x slower | +----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x slower | +----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (18): fanout_to_subgraph_100x, wide_state_9x1200_checkpoint_sync, fanout_to_subgraph_100x_checkpoint_sync, react_agent_10x_sync, react_agent_10x, wide_state_9x1200_sync, wide_state_9x1200_checkpoint, wide_state_25x300_checkpoint_sync, fanout_to_subgraph_100x_checkpoint, fanout_to_subgraph_10x_sync, react_agent_10x_checkpoint, fanout_to_subgraph_100x_sync, react_agent_10x_checkpoint_sync, fanout_to_subgraph_10x, fanout_to_subgraph_10x_checkpoint, wide_state_9x1200, react_agent_100x_checkpoint, 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