diff --git a/libs/sdk-js/package.json b/libs/sdk-js/package.json index 6c3d5a06c..6f1cd8d0b 100644 --- a/libs/sdk-js/package.json +++ b/libs/sdk-js/package.json @@ -1,6 +1,6 @@ { "name": "@langchain/langgraph-sdk", - "version": "0.0.59", + "version": "0.0.60", "description": "Client library for interacting with the LangGraph API", "type": "module", "packageManager": "yarn@1.22.19", diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 52051f1e8..54acd5232 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -482,15 +482,47 @@ export class ThreadsClient< * Metadata for the thread. */ metadata?: Metadata; + /** + * ID of the thread to create. + * + * If not provided, a random UUID will be generated. + */ threadId?: string; + /** + * How to handle duplicate creation. + * + * @default "raise" + */ ifExists?: OnConflictBehavior; + /** + * Graph ID to associate with the thread. + */ + graphId?: string; + /** + * Apply a list of supersteps when creating a thread, each containing a sequence of updates. + * + * Used for copying a thread between deployments. + */ + supersteps?: Array<{ + updates: Array<{ values: unknown; command?: Command; asNode: string }>; + }>; }): Promise> { return this.fetch>(`/threads`, { method: "POST", json: { - metadata: payload?.metadata, + metadata: { + ...payload?.metadata, + graph_id: payload?.graphId, + }, thread_id: payload?.threadId, if_exists: payload?.ifExists, + supersteps: payload?.supersteps?.map((s) => ({ + updates: s.updates.map((u) => ({ + values: u.values, + command: u.command, + as_node: u.asNode, + })), + })), }, }); } @@ -639,40 +671,6 @@ export class ThreadsClient< ); } - /** - * Create a new thread from a batch states. - */ - async bulkUpdateState( - supersteps: Array<{ - updates: Array<{ values: unknown; command?: Command; asNode: string }>; - }>, - options?: { - graphId?: string; - threadId?: string; - metadata?: Metadata; - ifExists?: OnConflictBehavior; - }, - ): Promise> { - return this.fetch>("/threads/state/batch", { - method: "POST", - json: { - supersteps: supersteps.map((s) => ({ - updates: s.updates.map((u) => ({ - values: u.values, - command: u.command, - as_node: u.asNode, - })), - })), - thread_id: options?.threadId, - metadata: { - ...options?.metadata, - graph_id: options?.graphId, - }, - if_exists: options?.ifExists, - }, - }); - } - /** * Patch the metadata of a thread. * diff --git a/libs/sdk-py/langgraph_sdk/client.py b/libs/sdk-py/langgraph_sdk/client.py index 6f4583b7f..4418e66de 100644 --- a/libs/sdk-py/langgraph_sdk/client.py +++ b/libs/sdk-py/langgraph_sdk/client.py @@ -839,6 +839,8 @@ class ThreadsClient: metadata: Json = None, thread_id: Optional[str] = None, if_exists: Optional[OnConflictBehavior] = None, + supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, + graph_id: Optional[str] = None, ) -> Thread: """Create a new thread. @@ -848,6 +850,9 @@ class ThreadsClient: If None, ID will be a randomly generated UUID. if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood. Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread). + supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. + Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments. + graph_id: Optional graph ID to associate with the thread. Returns: Thread: The created thread. @@ -863,10 +868,28 @@ class ThreadsClient: payload: Dict[str, Any] = {} if thread_id: payload["thread_id"] = thread_id - if metadata: - payload["metadata"] = metadata + if metadata or graph_id: + payload["metadata"] = { + **(metadata or {}), + **({"graph_id": graph_id} if graph_id else {}), + } if if_exists: payload["if_exists"] = if_exists + if supersteps: + payload["supersteps"] = [ + { + "updates": [ + { + "values": u["values"], + "command": u.get("command"), + "as_node": u["as_node"], + } + for u in s["updates"] + ] + } + for s in supersteps + ] + return await self.http.post("/threads", json=payload) async def update(self, thread_id: str, *, metadata: dict[str, Any]) -> Thread: @@ -3036,6 +3059,8 @@ class SyncThreadsClient: metadata: Json = None, thread_id: Optional[str] = None, if_exists: Optional[OnConflictBehavior] = None, + supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, + graph_id: Optional[str] = None, ) -> Thread: """Create a new thread. @@ -3045,6 +3070,9 @@ class SyncThreadsClient: If None, ID will be a randomly generated UUID. if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood. Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread). + supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. + Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments. + graph_id: Optional graph ID to associate with the thread. Returns: Thread: The created thread. @@ -3060,10 +3088,28 @@ class SyncThreadsClient: payload: Dict[str, Any] = {} if thread_id: payload["thread_id"] = thread_id - if metadata: - payload["metadata"] = metadata + if metadata or graph_id: + payload["metadata"] = { + **(metadata or {}), + **({"graph_id": graph_id} if graph_id else {}), + } if if_exists: payload["if_exists"] = if_exists + if supersteps: + payload["supersteps"] = [ + { + "updates": [ + { + "values": u["values"], + "command": u.get("command"), + "as_node": u["as_node"], + } + for u in s["updates"] + ] + } + for s in supersteps + ] + return self.http.post("/threads", json=payload) def update(self, thread_id: str, *, metadata: dict[str, Any]) -> Thread: @@ -3307,7 +3353,7 @@ class SyncThreadsClient: Example Usage: - response = 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", diff --git a/libs/sdk-py/pyproject.toml b/libs/sdk-py/pyproject.toml index 75e402fee..92e942441 100644 --- a/libs/sdk-py/pyproject.toml +++ b/libs/sdk-py/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langgraph-sdk" -version = "0.1.57" +version = "0.1.58" description = "SDK for interacting with LangGraph API" authors = [] license = "MIT"