Skip to content

Commit

Permalink
Merge pull request #2592 from langchain-ai/dqbd/sdk-list-runs-by-status
Browse files Browse the repository at this point in the history
feat(sdk): add ability to search runs via status
  • Loading branch information
dqbd authored Dec 3, 2024
2 parents 7848217 + 46dd424 commit 63f5f15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GraphSchema,
Metadata,
Run,
RunStatus,
Thread,
ThreadState,
Cron,
Expand Down Expand Up @@ -944,12 +945,18 @@ export class RunsClient extends BaseClient {
* Defaults to 0.
*/
offset?: number;

/**
* Status of the run to filter by.
*/
status?: RunStatus;
},
): Promise<Run[]> {
return this.fetch<Run[]>(`/threads/${threadId}/runs`, {
params: {
limit: options?.limit ?? 10,
offset: options?.offset ?? 0,
status: options?.status ?? undefined,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-js/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { JSONSchema7 } from "json-schema";

type Optional<T> = T | null | undefined;

type RunStatus =
export type RunStatus =
| "pending"
| "running"
| "error"
Expand Down
19 changes: 15 additions & 4 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
OnConflictBehavior,
Run,
RunCreate,
RunStatus,
SearchItemsResponse,
StreamMode,
StreamPart,
Expand Down Expand Up @@ -1684,14 +1685,20 @@ async def wait(
return response

async def list(
self, thread_id: str, *, limit: int = 10, offset: int = 0
self,
thread_id: str,
*,
limit: int = 10,
offset: int = 0,
status: Optional[RunStatus] = None,
) -> List[Run]:
"""List runs.
Args:
thread_id: The thread ID to list runs for.
limit: The maximum number of results to return.
offset: The number of results to skip.
status: The status of the run to filter by.
Returns:
List[Run]: The runs for the thread.
Expand All @@ -1705,9 +1712,13 @@ async def list(
)
""" # noqa: E501
return await self.http.get(
f"/threads/{thread_id}/runs?limit={limit}&offset={offset}"
)
params = {
"limit": limit,
"offset": offset,
}
if status is not None:
params["status"] = status
return await self.http.get(f"/threads/{thread_id}/runs", params=params)

async def get(self, thread_id: str, run_id: str) -> Run:
"""Get a run.
Expand Down

0 comments on commit 63f5f15

Please sign in to comment.