mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-23 08:02:23 +02:00
sdk: Add support to filter threads by status (#842)
This commit is contained in:
@@ -22,6 +22,7 @@ from langgraph_sdk.schema import (
|
||||
StreamMode,
|
||||
Thread,
|
||||
ThreadState,
|
||||
ThreadStatus,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -319,7 +320,12 @@ class ThreadsClient:
|
||||
await self.http.delete(f"/threads/{thread_id}")
|
||||
|
||||
async def search(
|
||||
self, *, metadata: Metadata = None, limit: int = 10, offset: int = 0
|
||||
self,
|
||||
*,
|
||||
metadata: Metadata = None,
|
||||
status: Optional[ThreadStatus] = None,
|
||||
limit: int = 10,
|
||||
offset: int = 0,
|
||||
) -> list[Thread]:
|
||||
"""Search for threads."""
|
||||
payload: Dict[str, Any] = {
|
||||
@@ -328,6 +334,8 @@ class ThreadsClient:
|
||||
}
|
||||
if metadata:
|
||||
payload["metadata"] = metadata
|
||||
if status:
|
||||
payload["status"] = status
|
||||
return await self.http.post(
|
||||
"/threads/search",
|
||||
json=payload,
|
||||
|
||||
@@ -5,6 +5,8 @@ Metadata = Optional[dict[str, Any]]
|
||||
|
||||
RunStatus = Literal["pending", "running", "error", "success", "timeout", "interrupted"]
|
||||
|
||||
ThreadStatus = Literal["idle", "busy", "interrupted"]
|
||||
|
||||
StreamMode = Literal["values", "messages", "updates", "events", "debug"]
|
||||
|
||||
MultitaskStrategy = Literal["reject", "interrupt", "rollback", "enqueue"]
|
||||
@@ -70,8 +72,8 @@ class Thread(TypedDict):
|
||||
"""The last time the thread was updated."""
|
||||
metadata: Metadata
|
||||
"""The thread metadata."""
|
||||
multitask_strategy: MultitaskStrategy
|
||||
"""The multitask strategy for this thread."""
|
||||
status: ThreadStatus
|
||||
"""The status of the thread, one of 'idle', 'busy', 'interrupted'."""
|
||||
|
||||
|
||||
class ThreadState(TypedDict):
|
||||
@@ -102,6 +104,8 @@ class Run(TypedDict):
|
||||
updated_at: datetime
|
||||
"""The last time the run was updated."""
|
||||
status: RunStatus
|
||||
"""The status of the run. One of 'pending', 'running', 'error', 'success'."""
|
||||
"""The status of the run. One of 'pending', 'running', "error", 'success', "timeout", "interrupted"."""
|
||||
metadata: Metadata
|
||||
"""The run metadata."""
|
||||
multitask_strategy: MultitaskStrategy
|
||||
"""Strategy to handle concurrent runs on the same thread."""
|
||||
|
||||
Reference in New Issue
Block a user