From 81f95a8d001a1eb7839ca3d40898eb2f5b060e77 Mon Sep 17 00:00:00 2001 From: Larsen Date: Thu, 12 Dec 2024 15:44:03 -0800 Subject: [PATCH 1/3] update attribute of Command supports BaseModel type --- libs/langgraph/langgraph/types.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 850f8ff41..01073e62d 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -19,6 +19,8 @@ cast, ) +from pydantic import BaseModel + from langchain_core.runnables import Runnable, RunnableConfig from typing_extensions import Self @@ -271,7 +273,7 @@ class Command(Generic[N], ToolOutputMixin): """ graph: Optional[str] = None - update: Union[dict[str, Any], Sequence[tuple[str, Any]]] = () + update: Union[dict[str, Any], Sequence[tuple[str, Any]], BaseModel] = () resume: Optional[Union[Any, dict[str, Any]]] = None goto: Union[Send, Sequence[Union[Send, str]], str] = () @@ -287,6 +289,8 @@ def __repr__(self) -> str: def _update_as_tuples(self) -> Sequence[tuple[str, Any]]: if isinstance(self.update, dict): return list(self.update.items()) + elif isinstance(self.update, BaseModel): + return list(self.update.model_dump().items()) elif isinstance(self.update, (list, tuple)) and all( isinstance(t, tuple) and len(t) == 2 and isinstance(t[0], str) for t in self.update @@ -298,9 +302,6 @@ def _update_as_tuples(self) -> Sequence[tuple[str, Any]]: PARENT: ClassVar[Literal["__parent__"]] = "__parent__" -StreamChunk = tuple[tuple[str, ...], str, Any] - - class StreamProtocol: __slots__ = ("modes", "__call__") From 31b2c2fb26b6702e9e4a0e2f60741978471355ab Mon Sep 17 00:00:00 2001 From: Larsen Date: Thu, 12 Dec 2024 15:59:44 -0800 Subject: [PATCH 2/3] restore accidentally deleted line --- libs/langgraph/langgraph/types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 01073e62d..222e37866 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -302,6 +302,8 @@ def _update_as_tuples(self) -> Sequence[tuple[str, Any]]: PARENT: ClassVar[Literal["__parent__"]] = "__parent__" +StreamChunk = tuple[tuple[str, ...], str, Any] + class StreamProtocol: __slots__ = ("modes", "__call__") From fad19824e4228d9ac42d6de1b6f4aa8306ea5efe Mon Sep 17 00:00:00 2001 From: Larsen Date: Thu, 12 Dec 2024 16:00:52 -0800 Subject: [PATCH 3/3] spacing nit --- libs/langgraph/langgraph/types.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 222e37866..1f91bc5ef 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -304,6 +304,7 @@ def _update_as_tuples(self) -> Sequence[tuple[str, Any]]: StreamChunk = tuple[tuple[str, ...], str, Any] + class StreamProtocol: __slots__ = ("modes", "__call__")