Skip to content

Commit

Permalink
Merge pull request #2544 from langchain-ai/brace/type-interrupts-py
Browse files Browse the repository at this point in the history
fix(sdk-py): Add typing for interrupts
  • Loading branch information
nfcampos authored Dec 3, 2024
2 parents afa37d2 + d4bbb66 commit 64b99c1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions libs/sdk-py/langgraph_sdk/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Data models for interacting with the LangGraph API."""

from datetime import datetime
from typing import Any, Literal, NamedTuple, Optional, Sequence, TypedDict, Union
from typing import Any, Dict, Literal, NamedTuple, Optional, Sequence, TypedDict, Union

Json = Optional[dict[str, Any]]
"""Represents a JSON-like structure, which can be None or a dictionary with string keys and any values."""
Expand Down Expand Up @@ -176,6 +176,19 @@ class Assistant(AssistantBase):
"""The name of the assistant"""


class Interrupt(TypedDict, total=False):
"""Represents an interruption in the execution flow."""

value: Any
"""The value associated with the interrupt."""
when: Literal["during"]
"""When the interrupt occurred."""
resumable: bool
"""Whether the interrupt can be resumed."""
ns: Optional[list[str]]
"""Optional namespace for the interrupt."""


class Thread(TypedDict):
"""Represents a conversation thread."""

Expand All @@ -191,6 +204,8 @@ class Thread(TypedDict):
"""The status of the thread, one of 'idle', 'busy', 'interrupted'."""
values: Json
"""The current state of the thread."""
interrupts: Dict[str, list[Interrupt]]
"""Interrupts which were thrown in this thread"""


class ThreadTask(TypedDict):
Expand All @@ -199,7 +214,7 @@ class ThreadTask(TypedDict):
id: str
name: str
error: Optional[str]
interrupts: list[dict]
interrupts: list[Interrupt]
checkpoint: Optional[Checkpoint]
state: Optional["ThreadState"]
result: Optional[dict[str, Any]]
Expand Down

0 comments on commit 64b99c1

Please sign in to comment.