This commit is contained in:
Nuno Campos
2024-09-19 13:20:45 -07:00
parent 5de9b35416
commit 95c1ca3adc
4 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ lint lint_diff lint_package lint_tests:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE)
[ "$(PYTHON_FILES)" != "langgraph" ] || poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
[ "$(PYTHON_FILES)" = "" ] || poetry run mypy langgraph --cache-dir $(MYPY_CACHE)
format format_diff:
poetry run ruff format $(PYTHON_FILES)
@@ -1,4 +1,4 @@
from typing import Generic, NamedTuple, Optional, Sequence, Type, Union
from typing import Any, Generic, NamedTuple, Optional, Sequence, Type, Union
from typing_extensions import Self
@@ -6,8 +6,8 @@ from langgraph.channels.base import BaseChannel, Value
from langgraph.errors import EmptyChannelError, InvalidUpdateError
class WaitForNames(NamedTuple, Generic[Value]):
names: set[Value]
class WaitForNames(NamedTuple):
names: set[Any]
class DynamicBarrierValue(
+12 -6
View File
@@ -268,13 +268,15 @@ class Graph:
path_map_ = path_map.copy()
elif isinstance(path_map, list):
path_map_ = {name: name for name in path_map}
elif callable(path) and (
rtn_type := get_type_hints(path.__call__).get("return")
if hasattr(path, "__call__")
else get_type_hints(path).get("return")
):
elif isinstance(path, Runnable):
path_map_ = None
elif rtn_type := get_type_hints(path.__call__).get( # type: ignore[operator]
"return"
) or get_type_hints(path).get("return"):
if get_origin(rtn_type) is Literal:
path_map_ = {name: name for name in get_args(rtn_type)}
else:
path_map_ = None
else:
path_map_ = None
except Exception:
@@ -417,6 +419,7 @@ class Graph:
# create empty compiled graph
compiled = CompiledGraph(
builder=self,
nodes={},
channels={START: EphemeralValue(Any), END: EphemeralValue(Any)},
input_channels=START,
@@ -429,7 +432,6 @@ class Graph:
auto_validate=False,
debug=debug,
)
compiled.builder = self
# attach nodes, edges, and branches
for key, node in self.nodes.items():
@@ -449,6 +451,10 @@ class Graph:
class CompiledGraph(Pregel):
builder: Graph
def __init__(self, *, builder: Graph, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.builder = builder
def attach_node(self, key: str, node: NodeSpec) -> None:
self.channels[key] = EphemeralValue(Any)
self.nodes[key] = (
+1 -1
View File
@@ -453,6 +453,7 @@ class StateGraph(Graph):
)
compiled = CompiledStateGraph(
builder=self,
config_type=self.config_schema,
nodes={},
channels={
@@ -471,7 +472,6 @@ class StateGraph(Graph):
debug=debug,
store=store,
)
compiled.builder = self
compiled.attach_node(START, None)
for key, node in self.nodes.items():