mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-30 11:49:38 +02:00
@@ -361,7 +361,11 @@ class StateGraph(Graph):
|
||||
|
||||
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)
|
||||
):
|
||||
|
||||
@@ -79,11 +79,19 @@ def test_state_schema_with_type_hint():
|
||||
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,
|
||||
@@ -92,6 +100,8 @@ def test_state_schema_with_type_hint():
|
||||
miss_all_hint,
|
||||
pre_foo,
|
||||
Foo(),
|
||||
pre_bar,
|
||||
Bar().my_node,
|
||||
]
|
||||
|
||||
for action in actions:
|
||||
@@ -112,7 +122,7 @@ def test_state_schema_with_type_hint():
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user