Skip to content

Commit

Permalink
Merge branch 'main' into vb/validate-message-sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarda authored Nov 1, 2024
2 parents 46d1e82 + ecb584c commit 0f600cd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-cli"
version = "0.1.52"
version = "0.1.53"
description = "CLI for interacting with LangGraph API"
authors = []
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Assistant,
AssistantGraph,
CancelAction,
Config,
DefaultValues,
GraphSchema,
Expand Down Expand Up @@ -928,17 +929,20 @@ export class RunsClient extends BaseClient {
* @param threadId The ID of the thread.
* @param runId The ID of the run.
* @param wait Whether to block when canceling
* @param action Action to take when cancelling the run. Possible values are `interrupt` or `rollback`. Default is `interrupt`.
* @returns
*/
async cancel(
threadId: string,
runId: string,
wait: boolean = false,
action: CancelAction = "interrupt",
): Promise<void> {
return this.fetch<void>(`/threads/${threadId}/runs/${runId}/cancel`, {
method: "POST",
params: {
wait: wait ? "1" : "0",
action: action,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-js/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type ThreadStatus = "idle" | "busy" | "interrupted" | "error";

type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";

export type CancelAction = "interrupt" | "rollback";

export interface Config {
/**
* Tags for this call and any sub-calls (eg. a Chain calling an LLM).
Expand Down
33 changes: 27 additions & 6 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
All,
Assistant,
AssistantVersion,
CancelAction,
Checkpoint,
Config,
Cron,
Expand Down Expand Up @@ -1712,13 +1713,22 @@ async def get(self, thread_id: str, run_id: str) -> Run:

return await self.http.get(f"/threads/{thread_id}/runs/{run_id}")

async def cancel(self, thread_id: str, run_id: str, *, wait: bool = False) -> None:
async def cancel(
self,
thread_id: str,
run_id: str,
*,
wait: bool = False,
action: CancelAction = "interrupt",
) -> None:
"""Get a run.
Args:
thread_id: The thread ID to cancel.
run_id: The run ID to cancek.
wait: Whether to wait until run has completed.
action: Action to take when cancelling the run. Possible values
are `interrupt` or `rollback`. Default is `interrupt`.
Returns:
None
Expand All @@ -1728,12 +1738,13 @@ async def cancel(self, thread_id: str, run_id: str, *, wait: bool = False) -> No
await client.runs.cancel(
thread_id="thread_id_to_cancel",
run_id="run_id_to_cancel",
wait=True
wait=True,
action="interrupt"
)
""" # noqa: E501
return await self.http.post(
f"/threads/{thread_id}/runs/{run_id}/cancel?wait={1 if wait else 0}",
f"/threads/{thread_id}/runs/{run_id}/cancel?wait={1 if wait else 0}&action={action}",
json=None,
)

Expand Down Expand Up @@ -3792,13 +3803,22 @@ def get(self, thread_id: str, run_id: str) -> Run:

return self.http.get(f"/threads/{thread_id}/runs/{run_id}")

def cancel(self, thread_id: str, run_id: str, *, wait: bool = False) -> None:
def cancel(
self,
thread_id: str,
run_id: str,
*,
wait: bool = False,
action: CancelAction = "interrupt",
) -> None:
"""Get a run.
Args:
thread_id: The thread ID to cancel.
run_id: The run ID to cancek.
wait: Whether to wait until run has completed.
action: Action to take when cancelling the run. Possible values
are `interrupt` or `rollback`. Default is `interrupt`.
Returns:
None
Expand All @@ -3808,12 +3828,13 @@ def cancel(self, thread_id: str, run_id: str, *, wait: bool = False) -> None:
client.runs.cancel(
thread_id="thread_id_to_cancel",
run_id="run_id_to_cancel",
wait=True
wait=True,
action="interrupt"
)
""" # noqa: E501
return self.http.post(
f"/threads/{thread_id}/runs/{run_id}/cancel?wait={1 if wait else 0}",
f"/threads/{thread_id}/runs/{run_id}/cancel?wait={1 if wait else 0}&action={action}",
json=None,
)

Expand Down
7 changes: 7 additions & 0 deletions libs/sdk-py/langgraph_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
- "reject": Reject the operation if the thread doesn't exist.
"""

CancelAction = Literal["interrupt", "rollback"]
"""
Action to take when cancelling the run.
- "interrupt": Simply cancel the run.
- "rollback": Cancel the run. Then delete the run and associated checkpoints.
"""


class Config(TypedDict, total=False):
"""Configuration options for a call."""
Expand Down

0 comments on commit 0f600cd

Please sign in to comment.