From 647c5737f0be5fa36246e7e4df0467e1956397b1 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Mon, 15 Jul 2024 12:15:43 -0400 Subject: [PATCH] sdk-py: add if_exists to threads.create (#1009) --- libs/sdk-py/langgraph_sdk/client.py | 4 ++++ libs/sdk-py/langgraph_sdk/schema.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libs/sdk-py/langgraph_sdk/client.py b/libs/sdk-py/langgraph_sdk/client.py index 8611b0e36..14c812e8b 100644 --- a/libs/sdk-py/langgraph_sdk/client.py +++ b/libs/sdk-py/langgraph_sdk/client.py @@ -29,6 +29,7 @@ from langgraph_sdk.schema import ( GraphSchema, Metadata, MultitaskStrategy, + OnConflictBehavior, Run, StreamMode, Thread, @@ -344,6 +345,7 @@ class ThreadsClient: *, metadata: Metadata = None, thread_id: Optional[str] = None, + if_exists: Optional[OnConflictBehavior] = None, ) -> Thread: """Create a new thread.""" payload: Dict[str, Any] = {} @@ -351,6 +353,8 @@ class ThreadsClient: payload["thread_id"] = thread_id if metadata: payload["metadata"] = metadata + if if_exists: + payload["if_exists"] = if_exists return await self.http.post("/threads", json=payload) async def update(self, thread_id: str, *, metadata: dict[str, Any]) -> Thread: diff --git a/libs/sdk-py/langgraph_sdk/schema.py b/libs/sdk-py/langgraph_sdk/schema.py index e40fc71cd..3e9d6c064 100644 --- a/libs/sdk-py/langgraph_sdk/schema.py +++ b/libs/sdk-py/langgraph_sdk/schema.py @@ -11,6 +11,8 @@ StreamMode = Literal["values", "messages", "updates", "events", "debug"] MultitaskStrategy = Literal["reject", "interrupt", "rollback", "enqueue"] +OnConflictBehavior = Literal["raise", "do_nothing"] + All = Literal["*"]