langgraph-sdk 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/PKG-INFO +1 -1
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/__init__.py +1 -1
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/client.py +360 -12
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/schema.py +14 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/.gitignore +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/LICENSE +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/Makefile +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/README.md +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/auth/__init__.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/auth/exceptions.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/auth/types.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/py.typed +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/langgraph_sdk/sse.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/pyproject.toml +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/tests/test_api_parity.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/tests/test_select_fields_sync.py +0 -0
- {langgraph_sdk-0.2.2 → langgraph_sdk-0.2.4}/uv.lock +0 -0
|
@@ -15,6 +15,7 @@ import logging
|
|
|
15
15
|
import os
|
|
16
16
|
import re
|
|
17
17
|
import sys
|
|
18
|
+
import warnings
|
|
18
19
|
from collections.abc import AsyncIterator, Iterator, Mapping, Sequence
|
|
19
20
|
from types import TracebackType
|
|
20
21
|
from typing import (
|
|
@@ -45,6 +46,7 @@ from langgraph_sdk.schema import (
|
|
|
45
46
|
CronSelectField,
|
|
46
47
|
CronSortBy,
|
|
47
48
|
DisconnectMode,
|
|
49
|
+
Durability,
|
|
48
50
|
GraphSchema,
|
|
49
51
|
IfNotExists,
|
|
50
52
|
Item,
|
|
@@ -69,6 +71,7 @@ from langgraph_sdk.schema import (
|
|
|
69
71
|
ThreadSortBy,
|
|
70
72
|
ThreadState,
|
|
71
73
|
ThreadStatus,
|
|
74
|
+
ThreadStreamMode,
|
|
72
75
|
ThreadUpdateStateResponse,
|
|
73
76
|
)
|
|
74
77
|
from langgraph_sdk.sse import SSEDecoder, aiter_lines_raw, iter_lines_raw
|
|
@@ -991,6 +994,34 @@ class AssistantsClient:
|
|
|
991
994
|
params=params,
|
|
992
995
|
)
|
|
993
996
|
|
|
997
|
+
async def count(
|
|
998
|
+
self,
|
|
999
|
+
*,
|
|
1000
|
+
metadata: Json = None,
|
|
1001
|
+
graph_id: str | None = None,
|
|
1002
|
+
headers: Mapping[str, str] | None = None,
|
|
1003
|
+
params: QueryParamTypes | None = None,
|
|
1004
|
+
) -> int:
|
|
1005
|
+
"""Count assistants matching filters.
|
|
1006
|
+
|
|
1007
|
+
Args:
|
|
1008
|
+
metadata: Metadata to filter by. Exact match for each key/value.
|
|
1009
|
+
graph_id: Optional graph id to filter by.
|
|
1010
|
+
headers: Optional custom headers to include with the request.
|
|
1011
|
+
params: Optional query parameters to include with the request.
|
|
1012
|
+
|
|
1013
|
+
Returns:
|
|
1014
|
+
int: Number of assistants matching the criteria.
|
|
1015
|
+
"""
|
|
1016
|
+
payload: dict[str, Any] = {}
|
|
1017
|
+
if metadata:
|
|
1018
|
+
payload["metadata"] = metadata
|
|
1019
|
+
if graph_id:
|
|
1020
|
+
payload["graph_id"] = graph_id
|
|
1021
|
+
return await self.http.post(
|
|
1022
|
+
"/assistants/count", json=payload, headers=headers, params=params
|
|
1023
|
+
)
|
|
1024
|
+
|
|
994
1025
|
async def get_versions(
|
|
995
1026
|
self,
|
|
996
1027
|
assistant_id: str,
|
|
@@ -1340,6 +1371,38 @@ class ThreadsClient:
|
|
|
1340
1371
|
params=params,
|
|
1341
1372
|
)
|
|
1342
1373
|
|
|
1374
|
+
async def count(
|
|
1375
|
+
self,
|
|
1376
|
+
*,
|
|
1377
|
+
metadata: Json = None,
|
|
1378
|
+
values: Json = None,
|
|
1379
|
+
status: ThreadStatus | None = None,
|
|
1380
|
+
headers: Mapping[str, str] | None = None,
|
|
1381
|
+
params: QueryParamTypes | None = None,
|
|
1382
|
+
) -> int:
|
|
1383
|
+
"""Count threads matching filters.
|
|
1384
|
+
|
|
1385
|
+
Args:
|
|
1386
|
+
metadata: Thread metadata to filter on.
|
|
1387
|
+
values: State values to filter on.
|
|
1388
|
+
status: Thread status to filter on.
|
|
1389
|
+
headers: Optional custom headers to include with the request.
|
|
1390
|
+
params: Optional query parameters to include with the request.
|
|
1391
|
+
|
|
1392
|
+
Returns:
|
|
1393
|
+
int: Number of threads matching the criteria.
|
|
1394
|
+
"""
|
|
1395
|
+
payload: dict[str, Any] = {}
|
|
1396
|
+
if metadata:
|
|
1397
|
+
payload["metadata"] = metadata
|
|
1398
|
+
if values:
|
|
1399
|
+
payload["values"] = values
|
|
1400
|
+
if status:
|
|
1401
|
+
payload["status"] = status
|
|
1402
|
+
return await self.http.post(
|
|
1403
|
+
"/threads/count", json=payload, headers=headers, params=params
|
|
1404
|
+
)
|
|
1405
|
+
|
|
1343
1406
|
async def copy(
|
|
1344
1407
|
self,
|
|
1345
1408
|
thread_id: str,
|
|
@@ -1622,6 +1685,53 @@ class ThreadsClient:
|
|
|
1622
1685
|
params=params,
|
|
1623
1686
|
)
|
|
1624
1687
|
|
|
1688
|
+
async def join_stream(
|
|
1689
|
+
self,
|
|
1690
|
+
thread_id: str,
|
|
1691
|
+
*,
|
|
1692
|
+
last_event_id: str | None = None,
|
|
1693
|
+
stream_mode: ThreadStreamMode | Sequence[ThreadStreamMode] = "run_modes",
|
|
1694
|
+
headers: Mapping[str, str] | None = None,
|
|
1695
|
+
params: QueryParamTypes | None = None,
|
|
1696
|
+
) -> AsyncIterator[StreamPart]:
|
|
1697
|
+
"""Get a stream of events for a thread.
|
|
1698
|
+
|
|
1699
|
+
Args:
|
|
1700
|
+
thread_id: The ID of the thread to get the stream for.
|
|
1701
|
+
last_event_id: The ID of the last event to get.
|
|
1702
|
+
headers: Optional custom headers to include with the request.
|
|
1703
|
+
params: Optional query parameters to include with the request.
|
|
1704
|
+
|
|
1705
|
+
Returns:
|
|
1706
|
+
Iterator[StreamPart]: An iterator of stream parts.
|
|
1707
|
+
|
|
1708
|
+
???+ example "Example Usage"
|
|
1709
|
+
|
|
1710
|
+
```python
|
|
1711
|
+
|
|
1712
|
+
for chunk in client.threads.join_stream(
|
|
1713
|
+
thread_id="my_thread_id",
|
|
1714
|
+
last_event_id="my_event_id",
|
|
1715
|
+
):
|
|
1716
|
+
print(chunk)
|
|
1717
|
+
```
|
|
1718
|
+
|
|
1719
|
+
""" # noqa: E501
|
|
1720
|
+
query_params = {
|
|
1721
|
+
"stream_mode": stream_mode,
|
|
1722
|
+
}
|
|
1723
|
+
if params:
|
|
1724
|
+
query_params.update(params)
|
|
1725
|
+
return self.http.stream(
|
|
1726
|
+
f"/threads/{thread_id}/stream",
|
|
1727
|
+
"GET",
|
|
1728
|
+
headers={
|
|
1729
|
+
**({"Last-Event-ID": last_event_id} if last_event_id else {}),
|
|
1730
|
+
**(headers or {}),
|
|
1731
|
+
},
|
|
1732
|
+
params=query_params,
|
|
1733
|
+
)
|
|
1734
|
+
|
|
1625
1735
|
|
|
1626
1736
|
class RunsClient:
|
|
1627
1737
|
"""Client for managing runs in LangGraph.
|
|
@@ -1712,7 +1822,7 @@ class RunsClient:
|
|
|
1712
1822
|
context: Context | None = None,
|
|
1713
1823
|
checkpoint: Checkpoint | None = None,
|
|
1714
1824
|
checkpoint_id: str | None = None,
|
|
1715
|
-
checkpoint_during: bool | None = None,
|
|
1825
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
1716
1826
|
interrupt_before: All | Sequence[str] | None = None,
|
|
1717
1827
|
interrupt_after: All | Sequence[str] | None = None,
|
|
1718
1828
|
feedback_keys: Sequence[str] | None = None,
|
|
@@ -1725,6 +1835,7 @@ class RunsClient:
|
|
|
1725
1835
|
headers: Mapping[str, str] | None = None,
|
|
1726
1836
|
params: QueryParamTypes | None = None,
|
|
1727
1837
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
1838
|
+
durability: Durability | None = None,
|
|
1728
1839
|
) -> AsyncIterator[StreamPart]:
|
|
1729
1840
|
"""Create a run and stream the results.
|
|
1730
1841
|
|
|
@@ -1744,7 +1855,7 @@ class RunsClient:
|
|
|
1744
1855
|
context: Static context to add to the assistant.
|
|
1745
1856
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
1746
1857
|
checkpoint: The checkpoint to resume from.
|
|
1747
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
1858
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
1748
1859
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
1749
1860
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
1750
1861
|
feedback_keys: Feedback keys to assign to run.
|
|
@@ -1762,6 +1873,10 @@ class RunsClient:
|
|
|
1762
1873
|
headers: Optional custom headers to include with the request.
|
|
1763
1874
|
params: Optional query parameters to include with the request.
|
|
1764
1875
|
on_run_created: Callback when a run is created.
|
|
1876
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
1877
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
1878
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
1879
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
1765
1880
|
|
|
1766
1881
|
Returns:
|
|
1767
1882
|
AsyncIterator[StreamPart]: Asynchronous iterator of stream results.
|
|
@@ -1797,6 +1912,13 @@ class RunsClient:
|
|
|
1797
1912
|
```
|
|
1798
1913
|
|
|
1799
1914
|
""" # noqa: E501
|
|
1915
|
+
if checkpoint_during is not None:
|
|
1916
|
+
warnings.warn(
|
|
1917
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
1918
|
+
DeprecationWarning,
|
|
1919
|
+
stacklevel=2,
|
|
1920
|
+
)
|
|
1921
|
+
|
|
1800
1922
|
payload = {
|
|
1801
1923
|
"input": input,
|
|
1802
1924
|
"command": (
|
|
@@ -1821,6 +1943,7 @@ class RunsClient:
|
|
|
1821
1943
|
"on_disconnect": on_disconnect,
|
|
1822
1944
|
"on_completion": on_completion,
|
|
1823
1945
|
"after_seconds": after_seconds,
|
|
1946
|
+
"durability": durability,
|
|
1824
1947
|
}
|
|
1825
1948
|
endpoint = (
|
|
1826
1949
|
f"/threads/{thread_id}/runs/stream"
|
|
@@ -1911,7 +2034,7 @@ class RunsClient:
|
|
|
1911
2034
|
context: Context | None = None,
|
|
1912
2035
|
checkpoint: Checkpoint | None = None,
|
|
1913
2036
|
checkpoint_id: str | None = None,
|
|
1914
|
-
checkpoint_during: bool | None = None,
|
|
2037
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
1915
2038
|
interrupt_before: All | Sequence[str] | None = None,
|
|
1916
2039
|
interrupt_after: All | Sequence[str] | None = None,
|
|
1917
2040
|
webhook: str | None = None,
|
|
@@ -1922,6 +2045,7 @@ class RunsClient:
|
|
|
1922
2045
|
headers: Mapping[str, str] | None = None,
|
|
1923
2046
|
params: QueryParamTypes | None = None,
|
|
1924
2047
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
2048
|
+
durability: Durability | None = None,
|
|
1925
2049
|
) -> Run:
|
|
1926
2050
|
"""Create a background run.
|
|
1927
2051
|
|
|
@@ -1941,7 +2065,7 @@ class RunsClient:
|
|
|
1941
2065
|
context: Static context to add to the assistant.
|
|
1942
2066
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
1943
2067
|
checkpoint: The checkpoint to resume from.
|
|
1944
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
2068
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
1945
2069
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
1946
2070
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
1947
2071
|
webhook: Webhook to call after LangGraph API call is done.
|
|
@@ -1955,6 +2079,10 @@ class RunsClient:
|
|
|
1955
2079
|
Use to schedule future runs.
|
|
1956
2080
|
headers: Optional custom headers to include with the request.
|
|
1957
2081
|
on_run_created: Optional callback to call when a run is created.
|
|
2082
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
2083
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
2084
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
2085
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
1958
2086
|
|
|
1959
2087
|
Returns:
|
|
1960
2088
|
Run: The created background run.
|
|
@@ -2030,6 +2158,12 @@ class RunsClient:
|
|
|
2030
2158
|
}
|
|
2031
2159
|
```
|
|
2032
2160
|
""" # noqa: E501
|
|
2161
|
+
if checkpoint_during is not None:
|
|
2162
|
+
warnings.warn(
|
|
2163
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
2164
|
+
DeprecationWarning,
|
|
2165
|
+
stacklevel=2,
|
|
2166
|
+
)
|
|
2033
2167
|
payload = {
|
|
2034
2168
|
"input": input,
|
|
2035
2169
|
"command": (
|
|
@@ -2052,6 +2186,7 @@ class RunsClient:
|
|
|
2052
2186
|
"if_not_exists": if_not_exists,
|
|
2053
2187
|
"on_completion": on_completion,
|
|
2054
2188
|
"after_seconds": after_seconds,
|
|
2189
|
+
"durability": durability,
|
|
2055
2190
|
}
|
|
2056
2191
|
payload = {k: v for k, v in payload.items() if v is not None}
|
|
2057
2192
|
|
|
@@ -2149,7 +2284,7 @@ class RunsClient:
|
|
|
2149
2284
|
context: Context | None = None,
|
|
2150
2285
|
checkpoint: Checkpoint | None = None,
|
|
2151
2286
|
checkpoint_id: str | None = None,
|
|
2152
|
-
checkpoint_during: bool | None = None,
|
|
2287
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
2153
2288
|
interrupt_before: All | Sequence[str] | None = None,
|
|
2154
2289
|
interrupt_after: All | Sequence[str] | None = None,
|
|
2155
2290
|
webhook: str | None = None,
|
|
@@ -2162,6 +2297,7 @@ class RunsClient:
|
|
|
2162
2297
|
headers: Mapping[str, str] | None = None,
|
|
2163
2298
|
params: QueryParamTypes | None = None,
|
|
2164
2299
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
2300
|
+
durability: Durability | None = None,
|
|
2165
2301
|
) -> list[dict] | dict[str, Any]:
|
|
2166
2302
|
"""Create a run, wait until it finishes and return the final state.
|
|
2167
2303
|
|
|
@@ -2177,7 +2313,7 @@ class RunsClient:
|
|
|
2177
2313
|
context: Static context to add to the assistant.
|
|
2178
2314
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
2179
2315
|
checkpoint: The checkpoint to resume from.
|
|
2180
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
2316
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
2181
2317
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
2182
2318
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
2183
2319
|
webhook: Webhook to call after LangGraph API call is done.
|
|
@@ -2193,6 +2329,10 @@ class RunsClient:
|
|
|
2193
2329
|
Use to schedule future runs.
|
|
2194
2330
|
headers: Optional custom headers to include with the request.
|
|
2195
2331
|
on_run_created: Optional callback to call when a run is created.
|
|
2332
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
2333
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
2334
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
2335
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
2196
2336
|
|
|
2197
2337
|
Returns:
|
|
2198
2338
|
Union[list[dict], dict[str, Any]]: The output of the run.
|
|
@@ -2246,6 +2386,12 @@ class RunsClient:
|
|
|
2246
2386
|
```
|
|
2247
2387
|
|
|
2248
2388
|
""" # noqa: E501
|
|
2389
|
+
if checkpoint_during is not None:
|
|
2390
|
+
warnings.warn(
|
|
2391
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
2392
|
+
DeprecationWarning,
|
|
2393
|
+
stacklevel=2,
|
|
2394
|
+
)
|
|
2249
2395
|
payload = {
|
|
2250
2396
|
"input": input,
|
|
2251
2397
|
"command": (
|
|
@@ -2266,6 +2412,7 @@ class RunsClient:
|
|
|
2266
2412
|
"on_disconnect": on_disconnect,
|
|
2267
2413
|
"on_completion": on_completion,
|
|
2268
2414
|
"after_seconds": after_seconds,
|
|
2415
|
+
"durability": durability,
|
|
2269
2416
|
}
|
|
2270
2417
|
endpoint = (
|
|
2271
2418
|
f"/threads/{thread_id}/runs/wait" if thread_id is not None else "/runs/wait"
|
|
@@ -2855,6 +3002,34 @@ class CronClient:
|
|
|
2855
3002
|
"/runs/crons/search", json=payload, headers=headers, params=params
|
|
2856
3003
|
)
|
|
2857
3004
|
|
|
3005
|
+
async def count(
|
|
3006
|
+
self,
|
|
3007
|
+
*,
|
|
3008
|
+
assistant_id: str | None = None,
|
|
3009
|
+
thread_id: str | None = None,
|
|
3010
|
+
headers: Mapping[str, str] | None = None,
|
|
3011
|
+
params: QueryParamTypes | None = None,
|
|
3012
|
+
) -> int:
|
|
3013
|
+
"""Count cron jobs matching filters.
|
|
3014
|
+
|
|
3015
|
+
Args:
|
|
3016
|
+
assistant_id: Assistant ID to filter by.
|
|
3017
|
+
thread_id: Thread ID to filter by.
|
|
3018
|
+
headers: Optional custom headers to include with the request.
|
|
3019
|
+
params: Optional query parameters to include with the request.
|
|
3020
|
+
|
|
3021
|
+
Returns:
|
|
3022
|
+
int: Number of crons matching the criteria.
|
|
3023
|
+
"""
|
|
3024
|
+
payload: dict[str, Any] = {}
|
|
3025
|
+
if assistant_id:
|
|
3026
|
+
payload["assistant_id"] = assistant_id
|
|
3027
|
+
if thread_id:
|
|
3028
|
+
payload["thread_id"] = thread_id
|
|
3029
|
+
return await self.http.post(
|
|
3030
|
+
"/runs/crons/count", json=payload, headers=headers, params=params
|
|
3031
|
+
)
|
|
3032
|
+
|
|
2858
3033
|
|
|
2859
3034
|
class StoreClient:
|
|
2860
3035
|
"""Client for interacting with the graph's shared storage.
|
|
@@ -3974,6 +4149,34 @@ class SyncAssistantsClient:
|
|
|
3974
4149
|
params=params,
|
|
3975
4150
|
)
|
|
3976
4151
|
|
|
4152
|
+
def count(
|
|
4153
|
+
self,
|
|
4154
|
+
*,
|
|
4155
|
+
metadata: Json = None,
|
|
4156
|
+
graph_id: str | None = None,
|
|
4157
|
+
headers: Mapping[str, str] | None = None,
|
|
4158
|
+
params: QueryParamTypes | None = None,
|
|
4159
|
+
) -> int:
|
|
4160
|
+
"""Count assistants matching filters.
|
|
4161
|
+
|
|
4162
|
+
Args:
|
|
4163
|
+
metadata: Metadata to filter by. Exact match for each key/value.
|
|
4164
|
+
graph_id: Optional graph id to filter by.
|
|
4165
|
+
headers: Optional custom headers to include with the request.
|
|
4166
|
+
params: Optional query parameters to include with the request.
|
|
4167
|
+
|
|
4168
|
+
Returns:
|
|
4169
|
+
int: Number of assistants matching the criteria.
|
|
4170
|
+
"""
|
|
4171
|
+
payload: dict[str, Any] = {}
|
|
4172
|
+
if metadata:
|
|
4173
|
+
payload["metadata"] = metadata
|
|
4174
|
+
if graph_id:
|
|
4175
|
+
payload["graph_id"] = graph_id
|
|
4176
|
+
return self.http.post(
|
|
4177
|
+
"/assistants/count", json=payload, headers=headers, params=params
|
|
4178
|
+
)
|
|
4179
|
+
|
|
3977
4180
|
def get_versions(
|
|
3978
4181
|
self,
|
|
3979
4182
|
assistant_id: str,
|
|
@@ -4306,6 +4509,38 @@ class SyncThreadsClient:
|
|
|
4306
4509
|
"/threads/search", json=payload, headers=headers, params=params
|
|
4307
4510
|
)
|
|
4308
4511
|
|
|
4512
|
+
def count(
|
|
4513
|
+
self,
|
|
4514
|
+
*,
|
|
4515
|
+
metadata: Json = None,
|
|
4516
|
+
values: Json = None,
|
|
4517
|
+
status: ThreadStatus | None = None,
|
|
4518
|
+
headers: Mapping[str, str] | None = None,
|
|
4519
|
+
params: QueryParamTypes | None = None,
|
|
4520
|
+
) -> int:
|
|
4521
|
+
"""Count threads matching filters.
|
|
4522
|
+
|
|
4523
|
+
Args:
|
|
4524
|
+
metadata: Thread metadata to filter on.
|
|
4525
|
+
values: State values to filter on.
|
|
4526
|
+
status: Thread status to filter on.
|
|
4527
|
+
headers: Optional custom headers to include with the request.
|
|
4528
|
+
params: Optional query parameters to include with the request.
|
|
4529
|
+
|
|
4530
|
+
Returns:
|
|
4531
|
+
int: Number of threads matching the criteria.
|
|
4532
|
+
"""
|
|
4533
|
+
payload: dict[str, Any] = {}
|
|
4534
|
+
if metadata:
|
|
4535
|
+
payload["metadata"] = metadata
|
|
4536
|
+
if values:
|
|
4537
|
+
payload["values"] = values
|
|
4538
|
+
if status:
|
|
4539
|
+
payload["status"] = status
|
|
4540
|
+
return self.http.post(
|
|
4541
|
+
"/threads/count", json=payload, headers=headers, params=params
|
|
4542
|
+
)
|
|
4543
|
+
|
|
4309
4544
|
def copy(
|
|
4310
4545
|
self,
|
|
4311
4546
|
thread_id: str,
|
|
@@ -4585,6 +4820,54 @@ class SyncThreadsClient:
|
|
|
4585
4820
|
params=params,
|
|
4586
4821
|
)
|
|
4587
4822
|
|
|
4823
|
+
def join_stream(
|
|
4824
|
+
self,
|
|
4825
|
+
thread_id: str,
|
|
4826
|
+
*,
|
|
4827
|
+
stream_mode: ThreadStreamMode | Sequence[ThreadStreamMode] = "run_modes",
|
|
4828
|
+
last_event_id: str | None = None,
|
|
4829
|
+
headers: Mapping[str, str] | None = None,
|
|
4830
|
+
params: QueryParamTypes | None = None,
|
|
4831
|
+
) -> Iterator[StreamPart]:
|
|
4832
|
+
"""Get a stream of events for a thread.
|
|
4833
|
+
|
|
4834
|
+
Args:
|
|
4835
|
+
thread_id: The ID of the thread to get the stream for.
|
|
4836
|
+
last_event_id: The ID of the last event to get.
|
|
4837
|
+
headers: Optional custom headers to include with the request.
|
|
4838
|
+
params: Optional query parameters to include with the request.
|
|
4839
|
+
|
|
4840
|
+
Returns:
|
|
4841
|
+
Iterator[StreamPart]: An iterator of stream parts.
|
|
4842
|
+
|
|
4843
|
+
???+ example "Example Usage"
|
|
4844
|
+
|
|
4845
|
+
```python
|
|
4846
|
+
|
|
4847
|
+
for chunk in client.threads.join_stream(
|
|
4848
|
+
thread_id="my_thread_id",
|
|
4849
|
+
last_event_id="my_event_id",
|
|
4850
|
+
stream_mode="run_modes",
|
|
4851
|
+
):
|
|
4852
|
+
print(chunk)
|
|
4853
|
+
```
|
|
4854
|
+
|
|
4855
|
+
""" # noqa: E501
|
|
4856
|
+
query_params = {
|
|
4857
|
+
"stream_mode": stream_mode,
|
|
4858
|
+
}
|
|
4859
|
+
if params:
|
|
4860
|
+
query_params.update(params)
|
|
4861
|
+
return self.http.stream(
|
|
4862
|
+
f"/threads/{thread_id}/stream",
|
|
4863
|
+
"GET",
|
|
4864
|
+
headers={
|
|
4865
|
+
**({"Last-Event-ID": last_event_id} if last_event_id else {}),
|
|
4866
|
+
**(headers or {}),
|
|
4867
|
+
},
|
|
4868
|
+
params=query_params,
|
|
4869
|
+
)
|
|
4870
|
+
|
|
4588
4871
|
|
|
4589
4872
|
class SyncRunsClient:
|
|
4590
4873
|
"""Synchronous client for managing runs in LangGraph.
|
|
@@ -4675,7 +4958,7 @@ class SyncRunsClient:
|
|
|
4675
4958
|
context: Context | None = None,
|
|
4676
4959
|
checkpoint: Checkpoint | None = None,
|
|
4677
4960
|
checkpoint_id: str | None = None,
|
|
4678
|
-
checkpoint_during: bool | None = None,
|
|
4961
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
4679
4962
|
interrupt_before: All | Sequence[str] | None = None,
|
|
4680
4963
|
interrupt_after: All | Sequence[str] | None = None,
|
|
4681
4964
|
feedback_keys: Sequence[str] | None = None,
|
|
@@ -4688,6 +4971,7 @@ class SyncRunsClient:
|
|
|
4688
4971
|
headers: Mapping[str, str] | None = None,
|
|
4689
4972
|
params: QueryParamTypes | None = None,
|
|
4690
4973
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
4974
|
+
durability: Durability | None = None,
|
|
4691
4975
|
) -> Iterator[StreamPart]:
|
|
4692
4976
|
"""Create a run and stream the results.
|
|
4693
4977
|
|
|
@@ -4707,7 +4991,7 @@ class SyncRunsClient:
|
|
|
4707
4991
|
context: Static context to add to the assistant.
|
|
4708
4992
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
4709
4993
|
checkpoint: The checkpoint to resume from.
|
|
4710
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
4994
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
4711
4995
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
4712
4996
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
4713
4997
|
feedback_keys: Feedback keys to assign to run.
|
|
@@ -4724,6 +5008,11 @@ class SyncRunsClient:
|
|
|
4724
5008
|
Use to schedule future runs.
|
|
4725
5009
|
headers: Optional custom headers to include with the request.
|
|
4726
5010
|
on_run_created: Optional callback to call when a run is created.
|
|
5011
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
5012
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
5013
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
5014
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
5015
|
+
|
|
4727
5016
|
|
|
4728
5017
|
Returns:
|
|
4729
5018
|
Iterator[StreamPart]: Iterator of stream results.
|
|
@@ -4756,6 +5045,12 @@ class SyncRunsClient:
|
|
|
4756
5045
|
StreamPart(event='end', data=None)
|
|
4757
5046
|
```
|
|
4758
5047
|
""" # noqa: E501
|
|
5048
|
+
if checkpoint_during is not None:
|
|
5049
|
+
warnings.warn(
|
|
5050
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
5051
|
+
DeprecationWarning,
|
|
5052
|
+
stacklevel=2,
|
|
5053
|
+
)
|
|
4759
5054
|
payload = {
|
|
4760
5055
|
"input": input,
|
|
4761
5056
|
"command": (
|
|
@@ -4780,6 +5075,7 @@ class SyncRunsClient:
|
|
|
4780
5075
|
"on_disconnect": on_disconnect,
|
|
4781
5076
|
"on_completion": on_completion,
|
|
4782
5077
|
"after_seconds": after_seconds,
|
|
5078
|
+
"durability": durability,
|
|
4783
5079
|
}
|
|
4784
5080
|
endpoint = (
|
|
4785
5081
|
f"/threads/{thread_id}/runs/stream"
|
|
@@ -4870,7 +5166,7 @@ class SyncRunsClient:
|
|
|
4870
5166
|
context: Context | None = None,
|
|
4871
5167
|
checkpoint: Checkpoint | None = None,
|
|
4872
5168
|
checkpoint_id: str | None = None,
|
|
4873
|
-
checkpoint_during: bool | None = None,
|
|
5169
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
4874
5170
|
interrupt_before: All | Sequence[str] | None = None,
|
|
4875
5171
|
interrupt_after: All | Sequence[str] | None = None,
|
|
4876
5172
|
webhook: str | None = None,
|
|
@@ -4881,6 +5177,7 @@ class SyncRunsClient:
|
|
|
4881
5177
|
headers: Mapping[str, str] | None = None,
|
|
4882
5178
|
params: QueryParamTypes | None = None,
|
|
4883
5179
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
5180
|
+
durability: Durability | None = None,
|
|
4884
5181
|
) -> Run:
|
|
4885
5182
|
"""Create a background run.
|
|
4886
5183
|
|
|
@@ -4900,7 +5197,7 @@ class SyncRunsClient:
|
|
|
4900
5197
|
context: Static context to add to the assistant.
|
|
4901
5198
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
4902
5199
|
checkpoint: The checkpoint to resume from.
|
|
4903
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
5200
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
4904
5201
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
4905
5202
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
4906
5203
|
webhook: Webhook to call after LangGraph API call is done.
|
|
@@ -4914,6 +5211,10 @@ class SyncRunsClient:
|
|
|
4914
5211
|
Use to schedule future runs.
|
|
4915
5212
|
headers: Optional custom headers to include with the request.
|
|
4916
5213
|
on_run_created: Optional callback to call when a run is created.
|
|
5214
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
5215
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
5216
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
5217
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
4917
5218
|
|
|
4918
5219
|
Returns:
|
|
4919
5220
|
Run: The created background run.
|
|
@@ -4989,6 +5290,12 @@ class SyncRunsClient:
|
|
|
4989
5290
|
}
|
|
4990
5291
|
```
|
|
4991
5292
|
""" # noqa: E501
|
|
5293
|
+
if checkpoint_during is not None:
|
|
5294
|
+
warnings.warn(
|
|
5295
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
5296
|
+
DeprecationWarning,
|
|
5297
|
+
stacklevel=2,
|
|
5298
|
+
)
|
|
4992
5299
|
payload = {
|
|
4993
5300
|
"input": input,
|
|
4994
5301
|
"command": (
|
|
@@ -5011,6 +5318,7 @@ class SyncRunsClient:
|
|
|
5011
5318
|
"if_not_exists": if_not_exists,
|
|
5012
5319
|
"on_completion": on_completion,
|
|
5013
5320
|
"after_seconds": after_seconds,
|
|
5321
|
+
"durability": durability,
|
|
5014
5322
|
}
|
|
5015
5323
|
payload = {k: v for k, v in payload.items() if v is not None}
|
|
5016
5324
|
|
|
@@ -5106,7 +5414,7 @@ class SyncRunsClient:
|
|
|
5106
5414
|
metadata: Mapping[str, Any] | None = None,
|
|
5107
5415
|
config: Config | None = None,
|
|
5108
5416
|
context: Context | None = None,
|
|
5109
|
-
checkpoint_during: bool | None = None,
|
|
5417
|
+
checkpoint_during: bool | None = None, # deprecated
|
|
5110
5418
|
checkpoint: Checkpoint | None = None,
|
|
5111
5419
|
checkpoint_id: str | None = None,
|
|
5112
5420
|
interrupt_before: All | Sequence[str] | None = None,
|
|
@@ -5121,6 +5429,7 @@ class SyncRunsClient:
|
|
|
5121
5429
|
headers: Mapping[str, str] | None = None,
|
|
5122
5430
|
params: QueryParamTypes | None = None,
|
|
5123
5431
|
on_run_created: Callable[[RunCreateMetadata], None] | None = None,
|
|
5432
|
+
durability: Durability | None = None,
|
|
5124
5433
|
) -> list[dict] | dict[str, Any]:
|
|
5125
5434
|
"""Create a run, wait until it finishes and return the final state.
|
|
5126
5435
|
|
|
@@ -5136,7 +5445,7 @@ class SyncRunsClient:
|
|
|
5136
5445
|
context: Static context to add to the assistant.
|
|
5137
5446
|
!!! version-added "Supported with langgraph>=0.6.0"
|
|
5138
5447
|
checkpoint: The checkpoint to resume from.
|
|
5139
|
-
checkpoint_during: Whether to checkpoint during the run (or only at the end/interruption).
|
|
5448
|
+
checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
|
|
5140
5449
|
interrupt_before: Nodes to interrupt immediately before they get executed.
|
|
5141
5450
|
interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
|
|
5142
5451
|
webhook: Webhook to call after LangGraph API call is done.
|
|
@@ -5153,6 +5462,10 @@ class SyncRunsClient:
|
|
|
5153
5462
|
raise_error: Whether to raise an error if the run fails.
|
|
5154
5463
|
headers: Optional custom headers to include with the request.
|
|
5155
5464
|
on_run_created: Optional callback to call when a run is created.
|
|
5465
|
+
durability: The durability to use for the run. Values are "sync", "async", or "exit".
|
|
5466
|
+
"async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
|
|
5467
|
+
"sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
|
|
5468
|
+
"exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
|
|
5156
5469
|
|
|
5157
5470
|
Returns:
|
|
5158
5471
|
Union[list[dict], dict[str, Any]]: The output of the run.
|
|
@@ -5207,6 +5520,12 @@ class SyncRunsClient:
|
|
|
5207
5520
|
```
|
|
5208
5521
|
|
|
5209
5522
|
""" # noqa: E501
|
|
5523
|
+
if checkpoint_during is not None:
|
|
5524
|
+
warnings.warn(
|
|
5525
|
+
"`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.",
|
|
5526
|
+
DeprecationWarning,
|
|
5527
|
+
stacklevel=2,
|
|
5528
|
+
)
|
|
5210
5529
|
payload = {
|
|
5211
5530
|
"input": input,
|
|
5212
5531
|
"command": (
|
|
@@ -5228,6 +5547,7 @@ class SyncRunsClient:
|
|
|
5228
5547
|
"on_completion": on_completion,
|
|
5229
5548
|
"after_seconds": after_seconds,
|
|
5230
5549
|
"raise_error": raise_error,
|
|
5550
|
+
"durability": durability,
|
|
5231
5551
|
}
|
|
5232
5552
|
|
|
5233
5553
|
def on_response(res: httpx.Response):
|
|
@@ -5781,6 +6101,34 @@ class SyncCronClient:
|
|
|
5781
6101
|
"/runs/crons/search", json=payload, headers=headers, params=params
|
|
5782
6102
|
)
|
|
5783
6103
|
|
|
6104
|
+
def count(
|
|
6105
|
+
self,
|
|
6106
|
+
*,
|
|
6107
|
+
assistant_id: str | None = None,
|
|
6108
|
+
thread_id: str | None = None,
|
|
6109
|
+
headers: Mapping[str, str] | None = None,
|
|
6110
|
+
params: QueryParamTypes | None = None,
|
|
6111
|
+
) -> int:
|
|
6112
|
+
"""Count cron jobs matching filters.
|
|
6113
|
+
|
|
6114
|
+
Args:
|
|
6115
|
+
assistant_id: Assistant ID to filter by.
|
|
6116
|
+
thread_id: Thread ID to filter by.
|
|
6117
|
+
headers: Optional custom headers to include with the request.
|
|
6118
|
+
params: Optional query parameters to include with the request.
|
|
6119
|
+
|
|
6120
|
+
Returns:
|
|
6121
|
+
int: Number of crons matching the criteria.
|
|
6122
|
+
"""
|
|
6123
|
+
payload: dict[str, Any] = {}
|
|
6124
|
+
if assistant_id:
|
|
6125
|
+
payload["assistant_id"] = assistant_id
|
|
6126
|
+
if thread_id:
|
|
6127
|
+
payload["thread_id"] = thread_id
|
|
6128
|
+
return self.http.post(
|
|
6129
|
+
"/runs/crons/count", json=payload, headers=headers, params=params
|
|
6130
|
+
)
|
|
6131
|
+
|
|
5784
6132
|
|
|
5785
6133
|
class SyncStoreClient:
|
|
5786
6134
|
"""A client for synchronous operations on a key-value store.
|
|
@@ -38,6 +38,14 @@ Represents the status of a thread:
|
|
|
38
38
|
- "error": An exception occurred during task processing.
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
|
+
ThreadStreamMode = Literal["run_modes", "lifecycle", "state_update"]
|
|
42
|
+
"""
|
|
43
|
+
Defines the mode of streaming:
|
|
44
|
+
- "run_modes": Stream the same events as the runs on thread, as well as run_done events.
|
|
45
|
+
- "lifecycle": Stream only run start/end events.
|
|
46
|
+
- "state_update": Stream state updates on the thread.
|
|
47
|
+
"""
|
|
48
|
+
|
|
41
49
|
StreamMode = Literal[
|
|
42
50
|
"values",
|
|
43
51
|
"messages",
|
|
@@ -91,6 +99,12 @@ Defines action after completion:
|
|
|
91
99
|
- "keep": Retain resources after completion.
|
|
92
100
|
"""
|
|
93
101
|
|
|
102
|
+
Durability = Literal["sync", "async", "exit"]
|
|
103
|
+
"""Durability mode for the graph execution.
|
|
104
|
+
- `"sync"`: Changes are persisted synchronously before the next step starts.
|
|
105
|
+
- `"async"`: Changes are persisted asynchronously while the next step executes.
|
|
106
|
+
- `"exit"`: Changes are persisted only when the graph exits."""
|
|
107
|
+
|
|
94
108
|
All = Literal["*"]
|
|
95
109
|
"""Represents a wildcard or 'all' selector."""
|
|
96
110
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|