This commit is contained in:
Nuno Campos
2024-08-21 09:30:21 -07:00
parent 2bc0e2df42
commit 7ca37afc74
5 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -695,7 +695,7 @@ def _get_channels(
schema: Type[dict],
) -> tuple[dict[str, BaseChannel], dict[str, Type[ManagedValue]]]:
if not hasattr(schema, "__annotations__"):
return {"__root__": _get_channel(schema, allow_managed=False)}, {}
return {"__root__": _get_channel("__root__", schema, allow_managed=False)}, {}
all_keys = {
name: _get_channel(name, typ)
@@ -26,11 +26,11 @@ Value = dict[str, V]
Update = dict[str, Optional[V]]
class ScopedValue(WritableManagedValue[Value, Update]):
class SharedValue(WritableManagedValue[Value, Update]):
@staticmethod
def configure(scope: str) -> ConfiguredManagedValue:
def on(scope: str) -> ConfiguredManagedValue:
return ConfiguredManagedValue(
ScopedValue, {"scope": scope, "key": ChannelKeyPlaceholder}
SharedValue, {"scope": scope, "key": ChannelKeyPlaceholder}
)
@classmethod
+1 -1
View File
@@ -121,8 +121,8 @@ def local_write(
commit: Callable[[Sequence[tuple[str, Any]]], None],
processes: Mapping[str, PregelNode],
channels: Mapping[str, BaseChannel],
writes: Sequence[tuple[str, Any]],
managed: ManagedValueMapping,
writes: Sequence[tuple[str, Any]],
) -> None:
for chan, value in writes:
if chan == TASKS:
+5 -5
View File
@@ -59,7 +59,7 @@ from langgraph.graph.graph import START
from langgraph.graph.message import MessageGraph, add_messages
from langgraph.graph.state import StateGraph
from langgraph.kv.memory import MemoryKV
from langgraph.managed.scoped_value import ScopedValue
from langgraph.managed.scoped_value import SharedValue
from langgraph.prebuilt.chat_agent_executor import (
create_tool_calling_executor,
)
@@ -167,7 +167,9 @@ def test_graph_validation() -> None:
class State(TypedDict):
hello: str
shared_things: Annotated[dict[str, dict[str, Any]], ScopedValue("assistant_id")]
shared_things: Annotated[
dict[str, dict[str, Any]], SharedValue.on("assistant_id")
]
def node_a(state: State) -> State:
# typo
@@ -6205,9 +6207,7 @@ def test_start_branch_then(snapshot: SnapshotAssertion) -> None:
class State(TypedDict):
my_key: Annotated[str, operator.add]
market: str
shared: Annotated[
dict[str, dict[str, Any]], ScopedValue.configure("assistant_id")
]
shared: Annotated[dict[str, dict[str, Any]], SharedValue.on("assistant_id")]
def assert_shared_value(data: State, config: RunnableConfig) -> State:
assert "shared" in data
+1 -1
View File
@@ -563,7 +563,7 @@ async def test_invoke_single_process_in_out(mocker: MockerFixture) -> None:
assert app.input_schema.schema() == {"title": "LangGraphInput", "type": "integer"}
assert app.output_schema.schema() == {"title": "LangGraphOutput", "type": "integer"}
assert await app.ainvoke(2) == 3
assert await app.ainvoke(2, debug=True) == 3
assert await app.ainvoke(2, output_keys=["output"]) == {"output": 3}
assert await gapp.ainvoke(2) == 3