Skip to content

Commit

Permalink
Merge pull request #1904 from langchain-ai/nc/29sep/thread-history-su…
Browse files Browse the repository at this point in the history
…bgraph

sdk-py: Add arg to get history for subgraphs
  • Loading branch information
nfcampos authored Sep 30, 2024
2 parents 620cffd + 7fba675 commit 904904c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,17 +1031,20 @@ async def update_state(
async def get_history(
self,
thread_id: str,
*,
limit: int = 10,
before: Optional[str] = None,
before: Optional[str | Checkpoint] = None,
metadata: Optional[dict] = None,
checkpoint: Optional[Checkpoint] = None,
) -> list[ThreadState]:
"""Get the state history of a thread.
Args:
thread_id: The ID of the thread to get the state of.
checkpoint: Get history for this subgraph. If empty defaults to root.
limit: The maximum number of results to return.
before: Thread timestamp to get history before.
metadata: The metadata of the thread history to get.
before: Get history before this checkpoint.
metadata: Filter checkpoints by metadata.
Returns:
list[ThreadState]: the state history of the thread.
Expand All @@ -1051,8 +1054,6 @@ async def get_history(
thread_state = await client.threads.get_history(
thread_id="my_thread_id",
limit=5,
before="my_timestamp",
metadata={"name":"my_name"}
)
""" # noqa: E501
Expand All @@ -1063,6 +1064,8 @@ async def get_history(
payload["before"] = before
if metadata:
payload["metadata"] = metadata
if checkpoint:
payload["checkpoint"] = checkpoint
return await self.http.post(f"/threads/{thread_id}/history", json=payload)


Expand Down Expand Up @@ -2994,17 +2997,20 @@ def update_state(
def get_history(
self,
thread_id: str,
*,
limit: int = 10,
before: Optional[str] = None,
before: Optional[str | Checkpoint] = None,
metadata: Optional[dict] = None,
checkpoint: Optional[Checkpoint] = None,
) -> list[ThreadState]:
"""Get the state history of a thread.
Args:
thread_id: The ID of the thread to get the state of.
checkpoint: Get history for this subgraph. If empty defaults to root.
limit: The maximum number of results to return.
before: Thread timestamp to get history before.
metadata: The metadata of the thread history to get.
before: Get history before this checkpoint.
metadata: Filter checkpoints by metadata.
Returns:
list[ThreadState]: the state history of the thread.
Expand All @@ -3026,6 +3032,8 @@ def get_history(
payload["before"] = before
if metadata:
payload["metadata"] = metadata
if checkpoint:
payload["checkpoint"] = checkpoint
return self.http.post(f"/threads/{thread_id}/history", json=payload)


Expand Down

0 comments on commit 904904c

Please sign in to comment.