Skip to content

Commit

Permalink
Merge pull request #1036 from langchain-ai/nc/16jul/node-state
Browse files Browse the repository at this point in the history
Add node state, customizable graph input and output schemas
  • Loading branch information
nfcampos authored Jul 18, 2024
2 parents 87e80fe + b5b0f8d commit 50861cd
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 49 deletions.
3 changes: 3 additions & 0 deletions libs/langgraph/langgraph/channels/any_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class AnyValue(Generic[Value], BaseChannel[Value, Value, Value]):
def __init__(self, typ: Type[Value]) -> None:
self.typ = typ

def __eq__(self, value: object) -> bool:
return isinstance(value, AnyValue)

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
6 changes: 6 additions & 0 deletions libs/langgraph/langgraph/channels/binop.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def __init__(self, typ: Type[Value], operator: Callable[[Value, Value], Value]):
except Exception:
pass

def __eq__(self, value: object) -> bool:
return (
isinstance(value, BinaryOperatorAggregate)
and value.operator == self.operator
)

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
7 changes: 7 additions & 0 deletions libs/langgraph/langgraph/channels/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def __init__(
self.ctx = ctx
self.actx = actx

def __eq__(self, value: object) -> bool:
return (
isinstance(value, Context)
and value.ctx == self.ctx
and value.actx == self.actx
)

@property
def ValueType(self) -> Any:
"""The type of the value stored in the channel."""
Expand Down
3 changes: 3 additions & 0 deletions libs/langgraph/langgraph/channels/dynamic_barrier_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, typ: Type[Value]) -> None:
self.names = None
self.seen = set()

def __eq__(self, value: object) -> bool:
return isinstance(value, DynamicBarrierValue) and value.names == self.names

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
3 changes: 3 additions & 0 deletions libs/langgraph/langgraph/channels/ephemeral_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def __init__(self, typ: Type[Value], guard: bool = True) -> None:
self.typ = typ
self.guard = guard

def __eq__(self, value: object) -> bool:
return isinstance(value, EphemeralValue) and value.guard == self.guard

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
3 changes: 3 additions & 0 deletions libs/langgraph/langgraph/channels/last_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class LastValue(Generic[Value], BaseChannel[Value, Value, Value]):
def __init__(self, typ: Type[Value]) -> None:
self.typ = typ

def __eq__(self, value: object) -> bool:
return isinstance(value, LastValue)

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
3 changes: 3 additions & 0 deletions libs/langgraph/langgraph/channels/named_barrier_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, typ: Type[Value], names: set[Value]) -> None:
self.names = names
self.seen = set()

def __eq__(self, value: object) -> bool:
return isinstance(value, NamedBarrierValue) and value.names == self.names

@property
def ValueType(self) -> Type[Value]:
"""The type of the value stored in the channel."""
Expand Down
7 changes: 7 additions & 0 deletions libs/langgraph/langgraph/channels/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def __init__(
self.seen = set[Value]()
self.values = list[Value]()

def __eq__(self, value: object) -> bool:
return (
isinstance(value, Topic)
and value.unique == self.unique
and value.accumulate == self.accumulate
)

@property
def ValueType(self) -> Any:
"""The type of the value stored in the channel."""
Expand Down
5 changes: 3 additions & 2 deletions libs/langgraph/langgraph/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ def add_edge(
start_nodes[start], end_nodes[end], label, conditional
)

for key, (node, metadata) in self.builder.nodes.items():
for key, n in self.builder.nodes.items():
node = n.runnable
if xray:
subgraph = (
node.get_graph(
Expand All @@ -501,7 +502,7 @@ def add_edge(
start_nodes[key] = n
end_nodes[key] = n
else:
n = graph.add_node(node, key, metadata=metadata)
n = graph.add_node(node, key, metadata=n.metadata)
start_nodes[key] = n
end_nodes[key] = n
for start, end in sorted(self.builder._all_edges):
Expand Down
Loading

0 comments on commit 50861cd

Please sign in to comment.