Skip to content

Commit

Permalink
sdk-py: Update return type annotation for Thread.update_state() met…
Browse files Browse the repository at this point in the history
…hods. (#2050)

### Summary
The response body of the endpoint `POST /threads/{thread_id}/state`
looks like this:
```
{
    "checkpoint": {
        "thread_id": "e2496803-ecd5-4e0c-a779-3226296181c2",
        "checkpoint_ns": "",
        "checkpoint_id": "1ef4a9b8-e6fb-67b1-8001-abd5184439d1",
        "checkpoint_map": {}
    }
}
```
  • Loading branch information
andrewnguonly authored Oct 8, 2024
1 parent 254b12a commit 82c316b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
37 changes: 31 additions & 6 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Thread,
ThreadState,
ThreadStatus,
ThreadUpdateStateResponse,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1060,7 +1061,7 @@ async def update_state(
as_node: Optional[str] = None,
checkpoint: Optional[Checkpoint] = None,
checkpoint_id: Optional[str] = None, # deprecated
) -> None:
) -> ThreadUpdateStateResponse:
"""Update the state of a thread.
Args:
Expand All @@ -1070,15 +1071,27 @@ async def update_state(
checkpoint: The checkpoint to update the state of.
Returns:
None
ThreadUpdateStateResponse: Response after updating a thread's state.
Example Usage:
await client.threads.update_state(
response = await client.threads.update_state(
thread_id="my_thread_id",
values={"messages":[{"role": "user", "content": "hello!"}]},
as_node="my_node",
)
print(response)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
{
'checkpoint': {
'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
'checkpoint_ns': '',
'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
'checkpoint_map': {}
}
}
""" # noqa: E501
payload: Dict[str, Any] = {
Expand Down Expand Up @@ -3109,7 +3122,7 @@ def update_state(
as_node: Optional[str] = None,
checkpoint: Optional[Checkpoint] = None,
checkpoint_id: Optional[str] = None, # deprecated
) -> None:
) -> ThreadUpdateStateResponse:
"""Update the state of a thread.
Args:
Expand All @@ -3119,15 +3132,27 @@ def update_state(
checkpoint: The checkpoint to update the state of.
Returns:
None
ThreadUpdateStateResponse: Response after updating a thread's state.
Example Usage:
await client.threads.update_state(
response = client.threads.update_state(
thread_id="my_thread_id",
values={"messages":[{"role": "user", "content": "hello!"}]},
as_node="my_node",
)
print(response)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
{
'checkpoint': {
'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
'checkpoint_ns': '',
'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
'checkpoint_map': {}
}
}
""" # noqa: E501
payload: Dict[str, Any] = {
Expand Down
7 changes: 7 additions & 0 deletions libs/sdk-py/langgraph_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ class ThreadState(TypedDict):
"""Tasks to execute in this step. If already attempted, may contain an error."""


class ThreadUpdateStateResponse(TypedDict):
"""Represents the response from updating a thread's state."""

checkpoint: Checkpoint
"""Checkpoint of the latest state."""


class Run(TypedDict):
"""Represents a single execution run."""

Expand Down

0 comments on commit 82c316b

Please sign in to comment.