feat(langgraph): type interrupt() return by response_schema, test dataclass schema

This commit is contained in:
Elior Nataf Lackritz
2026-09-11 15:34:45 -04:00
parent c0e1399e22
commit 375dafb6c6
2 changed files with 27 additions and 1 deletions
+10
View File
@@ -14,6 +14,7 @@ from typing import (
NamedTuple,
TypeVar,
final,
overload,
)
from warnings import warn
@@ -37,6 +38,7 @@ from langgraph.warnings import LangGraphDeprecatedSinceV10, LangGraphDeprecatedS
# when used in standalone type aliases.
StateT = TypeVar("StateT")
OutputT = TypeVar("OutputT")
ResponseT = TypeVar("ResponseT")
if TYPE_CHECKING:
from langgraph.pregel.protocol import PregelProtocol
@@ -861,6 +863,14 @@ class Command(Generic[N], ToolOutputMixin):
PARENT: ClassVar[Literal["__parent__"]] = "__parent__"
@overload
def interrupt(value: Any, *, response_schema: type[ResponseT]) -> ResponseT: ...
@overload
def interrupt(value: Any, *, response_schema: dict[str, Any] | None = None) -> Any: ...
def interrupt(
value: Any, *, response_schema: dict[str, Any] | type[Any] | None = None
) -> Any:
+17 -1
View File
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from typing import Any
import pytest
@@ -105,6 +106,11 @@ class DecisionDict(TypedDict):
approved: bool
@dataclass
class DecisionData:
approved: bool
RAW_SCHEMA = {"type": "object", "properties": {"approved": {"type": "boolean"}}}
@@ -124,8 +130,18 @@ RAW_SCHEMA = {"type": "object", "properties": {"approved": {"type": "boolean"}}}
},
{"approved": True},
),
(
DecisionData,
{
"properties": {"approved": {"title": "Approved", "type": "boolean"}},
"required": ["approved"],
"title": "DecisionData",
"type": "object",
},
DecisionData(approved=True),
),
],
ids=["none", "raw_dict", "pydantic", "typeddict"],
ids=["none", "raw_dict", "pydantic", "typeddict", "dataclass"],
)
def test_interrupt_response_schema(
sync_checkpointer: BaseCheckpointSaver,