sdk: Add support to filter threads by status (#842)

This commit is contained in:
Nuno Campos
2024-06-26 14:44:27 -07:00
committed by GitHub
parent 2657ebb57c
commit 8d103667c8
2 changed files with 16 additions and 4 deletions
+9 -1
View File
@@ -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,
+7 -3
View File
@@ -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."""