Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: Add support for scheduled runs #1782

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

Check notice on line 1 in libs/sdk-py/langgraph_sdk/client.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 59.3 ms +- 1.2 ms ......................................... WARNING: the benchmark result may be unstable * the standard deviation (5.84 ms) is 10% of the mean (56.2 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. fanout_to_subgraph_10x_sync: Mean +- std dev: 56.2 ms +- 5.8 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 76.9 ms +- 1.2 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 81.0 ms +- 0.5 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 544 ms +- 6 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 500 ms +- 5 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 747 ms +- 16 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 784 ms +- 6 ms ......................................... react_agent_10x: Mean +- std dev: 39.1 ms +- 0.8 ms ......................................... react_agent_10x_sync: Mean +- std dev: 29.6 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 52.6 ms +- 1.3 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 42.1 ms +- 3.1 ms ......................................... react_agent_100x: Mean +- std dev: 417 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 340 ms +- 12 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 916 ms +- 11 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 812 ms +- 8 ms ......................................... wide_state_25x300: Mean +- std dev: 20.6 ms +- 0.3 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 12.7 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 237 ms +- 7 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 227 ms +- 7 ms ......................................... wide_state_15x600: Mean +- std dev: 23.7 ms +- 0.4 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 14.6 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 416 ms +- 12 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 407 ms +- 11 ms ......................................... wide_state_9x1200: Mean +- std dev: 23.8 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 14.6 ms +- 0.2 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 268 ms +- 8 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 257 ms +- 9 ms

Check notice on line 1 in libs/sdk-py/langgraph_sdk/client.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +=========================================+=========+=======================+ | fanout_to_subgraph_100x | 599 ms | 544 ms: 1.10x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 44.2 ms | 42.1 ms: 1.05x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 782 ms | 747 ms: 1.05x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_sync | 523 ms | 500 ms: 1.05x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 54.4 ms | 52.6 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 30.6 ms | 29.6 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600 | 24.4 ms | 23.7 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_10x | 40.0 ms | 39.1 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 14.9 ms | 14.6 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 24.2 ms | 23.8 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint | 241 ms | 237 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 424 ms | 417 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 272 ms | 268 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 14.8 ms | 14.6 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 12.8 ms | 12.7 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 794 ms | 784 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 77.8 ms | 76.9 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 411 ms | 407 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 81.9 ms | 81.0 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 821 ms | 812 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x | 59.9 ms | 59.3 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint_sync | 229 ms | 227 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 260 ms | 257 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 420 ms | 416 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 921 ms | 916 ms: 1.00x faster | +---------------------------------------

import asyncio
import logging
Expand Down Expand Up @@ -970,6 +970,7 @@
on_disconnect: Optional[DisconnectMode] = None,
webhook: Optional[str] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
after_seconds: Optional[int] = None,
) -> AsyncIterator[StreamPart]: ...

@overload
Expand All @@ -988,6 +989,7 @@
on_disconnect: Optional[DisconnectMode] = None,
webhook: Optional[str] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> AsyncIterator[StreamPart]: ...

def stream(
Expand All @@ -1007,6 +1009,7 @@
webhook: Optional[str] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> AsyncIterator[StreamPart]:
"""Create a run and stream the results.

Expand All @@ -1030,6 +1033,10 @@
Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
on_disconnect: The disconnect mode to use.
Must be one of 'cancel' or 'continue'.
on_completion: The on completion behavior to use.
Must be one of 'delete' or 'keep'.
after_seconds: The number of seconds to wait before starting the run.
Use to schedule future runs.

Returns:
AsyncIterator[StreamPart]: Asynchronous iterator of stream results.
Expand Down Expand Up @@ -1074,6 +1081,7 @@
"multitask_strategy": multitask_strategy,
"on_disconnect": on_disconnect,
"on_completion": on_completion,
"after_seconds": after_seconds,
}
endpoint = (
f"/threads/{thread_id}/runs/stream"
Expand All @@ -1097,6 +1105,7 @@
interrupt_after: Optional[list[str]] = None,
webhook: Optional[str] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> Run: ...

@overload
Expand All @@ -1113,6 +1122,7 @@
interrupt_after: Optional[list[str]] = None,
webhook: Optional[str] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
after_seconds: Optional[int] = None,
) -> Run: ...

async def create(
Expand All @@ -1129,6 +1139,7 @@
webhook: Optional[str] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> Run:
"""Create a background run.

Expand All @@ -1146,6 +1157,10 @@
webhook: Webhook to call after LangGraph API call is done.
multitask_strategy: Multitask strategy to use.
Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
on_completion: The on completion behavior to use.
Must be one of 'delete' or 'keep'.
after_seconds: The number of seconds to wait before starting the run.
Use to schedule future runs.

Returns:
Run: The created background run.
Expand Down Expand Up @@ -1226,6 +1241,7 @@
"checkpoint_id": checkpoint_id,
"multitask_strategy": multitask_strategy,
"on_completion": on_completion,
"after_seconds": after_seconds,
}
payload = {k: v for k, v in payload.items() if v is not None}
if thread_id:
Expand Down Expand Up @@ -1257,6 +1273,7 @@
webhook: Optional[str] = None,
on_disconnect: Optional[DisconnectMode] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
after_seconds: Optional[int] = None,
) -> Union[list[dict], dict[str, Any]]: ...

@overload
Expand All @@ -1273,6 +1290,7 @@
webhook: Optional[str] = None,
on_disconnect: Optional[DisconnectMode] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> Union[list[dict], dict[str, Any]]: ...

async def wait(
Expand All @@ -1290,6 +1308,7 @@
on_disconnect: Optional[DisconnectMode] = None,
multitask_strategy: Optional[MultitaskStrategy] = None,
on_completion: Optional[OnCompletionBehavior] = None,
after_seconds: Optional[int] = None,
) -> Union[list[dict], dict[str, Any]]:
"""Create a run, wait until it finishes and return the final state.

Expand All @@ -1309,6 +1328,10 @@
Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
on_disconnect: The disconnect mode to use.
Must be one of 'cancel' or 'continue'.
on_completion: The on completion behavior to use.
Must be one of 'delete' or 'keep'.
after_seconds: The number of seconds to wait before starting the run.
Use to schedule future runs.

Returns:
Union[list[dict], dict[str, Any]]: The output of the run.
Expand Down Expand Up @@ -1370,6 +1393,7 @@
"multitask_strategy": multitask_strategy,
"on_disconnect": on_disconnect,
"on_completion": on_completion,
"after_seconds": after_seconds,
}
endpoint = (
f"/threads/{thread_id}/runs/wait" if thread_id is not None else "/runs/wait"
Expand Down
Loading