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

StreamMode in Join [sdk] #3584

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion libs/sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

Check notice on line 1 in libs/sdk-js/package.json

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 63.6 ms +- 1.2 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 55.2 ms +- 0.8 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 81.6 ms +- 1.3 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 99.0 ms +- 2.3 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 630 ms +- 10 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 544 ms +- 14 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 820 ms +- 25 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 1.01 sec +- 0.02 sec ......................................... react_agent_10x: Mean +- std dev: 30.6 ms +- 0.6 ms ......................................... react_agent_10x_sync: Mean +- std dev: 23.1 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 39.8 ms +- 0.8 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.5 ms +- 0.5 ms ......................................... react_agent_100x: Mean +- std dev: 342 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 272 ms +- 2 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 698 ms +- 10 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 712 ms +- 19 ms ......................................... wide_state_25x300: Mean +- std dev: 24.1 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 15.9 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 243 ms +- 3 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 243 ms +- 5 ms ......................................... wide_state_15x600: Mean +- std dev: 27.9 ms +- 0.6 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 18.3 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 426 ms +- 5 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 426 ms +- 11 ms ......................................... wide_state_9x1200: Mean +- std dev: 27.9 ms +- 0.5 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 18.3 ms +- 0.4 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 273 ms +- 2 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 271 ms +- 4 ms

Check notice on line 1 in libs/sdk-js/package.json

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +====================================+=========+=======================+ | fanout_to_subgraph_100x | 646 ms | 630 ms: 1.02x faster | +------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 838 ms | 820 ms: 1.02x faster | +------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 36.8 ms | 36.5 ms: 1.01x faster | +------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 272 ms | 271 ms: 1.01x faster | +------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 428 ms | 426 ms: 1.00x faster | +------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 18.3 ms | 18.3 ms: 1.00x faster | +------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 274 ms | 273 ms: 1.00x faster | +------------------------------------+---------+-----------------------+ | react_agent_100x_sync | 271 ms | 272 ms: 1.00x slower | +------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 81.3 ms | 81.6 ms: 1.00x slower | +------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 27.7 ms | 27.9 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint | 691 ms | 698 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | wide_state_15x600 | 27.6 ms | 27.9 ms: 1.01x slower | +------------------------------------+---------+-----------------------+ | wide_state_25x300 | 23.7 ms | 24.1 ms: 1.02x slower | +------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 689 ms | 712 ms: 1.03x slower | +------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x slower | +------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (14): fanout_to_subgraph_100x_sync, fanout_to_subgraph_10x_sync, fanout_to_subgraph_100x_checkpoint_sync, fanout_to_subgraph_10x_checkpoint_sync, wide_state_9x1200_sync, wide_state_25x300_sync, react_agent_10x_sync, wide_state_15x600_checkpoint_sync, wide_state_25x300_checkpoint_sync, fanout_to_subgraph_10x, wide_state_25x300_checkpoint, react_agent_100x, react_agent_10x, react_agent_10x_checkpoint
"name": "@langchain/langgraph-sdk",
"version": "0.0.45",
"version": "0.0.46",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "[email protected]",
Expand Down
12 changes: 10 additions & 2 deletions libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,18 @@ export class RunsClient<
*
* @param threadId The ID of the thread.
* @param runId The ID of the run.
* @param options Additional options like signal, cancelOnDisconnect, and streamMode
* @returns An async generator yielding stream parts.
*/
async *joinStream(
threadId: string,
runId: string,
options?:
| { signal?: AbortSignal; cancelOnDisconnect?: boolean }
| {
signal?: AbortSignal;
cancelOnDisconnect?: boolean;
streamMode?: StreamMode | StreamMode[];
}
| AbortSignal,
): AsyncGenerator<{ event: StreamEvent; data: any }> {
const opts =
Expand All @@ -1043,7 +1048,10 @@ export class RunsClient<
method: "GET",
timeoutMs: null,
signal: opts?.signal,
params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
params: {
cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0",
stream_mode: opts?.streamMode,
},
}),
);

Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-js/src/react/stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function getBranchView<StateType extends Record<string, unknown>>(
branchByCheckpoint[item.value.checkpoint.checkpoint_id!] = {
branch: item.path.join(PATH_SEP),
branchOptions: (item.path.length > 0
? pathMap[item.path.at(-2) ?? ROOT_ID] ?? []
? (pathMap[item.path.at(-2) ?? ROOT_ID] ?? [])
: []
).map((p) => p.join(PATH_SEP)),
};
Expand Down
1,671 changes: 891 additions & 780 deletions libs/sdk-js/yarn.lock

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,12 @@ async def join(self, thread_id: str, run_id: str) -> dict:
return await self.http.get(f"/threads/{thread_id}/runs/{run_id}/join")

def join_stream(
self, thread_id: str, run_id: str, *, cancel_on_disconnect: bool = False
self,
thread_id: str,
run_id: str,
*,
cancel_on_disconnect: bool = False,
stream_mode: Optional[Union[StreamMode, Sequence[StreamMode]]] = None,
) -> AsyncIterator[StreamPart]:
"""Stream output from a run in real-time, until the run is done.
Output is not buffered, so any output produced before this call will
Expand All @@ -1839,6 +1844,9 @@ def join_stream(
thread_id: The thread ID to join.
run_id: The run ID to join.
cancel_on_disconnect: Whether to cancel the run when the stream is disconnected.
stream_mode: The stream mode(s) to use. Must be a subset of the stream modes passed
when creating the run. Background runs default to having the union of all
stream modes.

Returns:
None
Expand All @@ -1847,14 +1855,18 @@ def join_stream(

await client.runs.join_stream(
thread_id="thread_id_to_join",
run_id="run_id_to_join"
run_id="run_id_to_join",
stream_mode=["values", "debug"]
)

""" # noqa: E501
return self.http.stream(
f"/threads/{thread_id}/runs/{run_id}/stream",
"GET",
params={"cancel_on_disconnect": cancel_on_disconnect},
params={
"cancel_on_disconnect": cancel_on_disconnect,
"stream_mode": stream_mode,
},
)

async def delete(self, thread_id: str, run_id: str) -> None:
Expand Down Expand Up @@ -3966,14 +3978,25 @@ def join(self, thread_id: str, run_id: str) -> dict:
""" # noqa: E501
return self.http.get(f"/threads/{thread_id}/runs/{run_id}/join")

def join_stream(self, thread_id: str, run_id: str) -> Iterator[StreamPart]:
def join_stream(
self,
thread_id: str,
run_id: str,
*,
stream_mode: Optional[Union[StreamMode, Sequence[StreamMode]]] = None,
cancel_on_disconnect: bool = False,
) -> Iterator[StreamPart]:
"""Stream output from a run in real-time, until the run is done.
Output is not buffered, so any output produced before this call will
not be received here.

Args:
thread_id: The thread ID to join.
run_id: The run ID to join.
stream_mode: The stream mode(s) to use. Must be a subset of the stream modes passed
when creating the run. Background runs default to having the union of all
stream modes.
cancel_on_disconnect: Whether to cancel the run when the stream is disconnected.

Returns:
None
Expand All @@ -3982,11 +4005,19 @@ def join_stream(self, thread_id: str, run_id: str) -> Iterator[StreamPart]:

client.runs.join_stream(
thread_id="thread_id_to_join",
run_id="run_id_to_join"
run_id="run_id_to_join",
stream_mode=["values", "debug"]
)

""" # noqa: E501
return self.http.stream(f"/threads/{thread_id}/runs/{run_id}/stream", "GET")
return self.http.stream(
f"/threads/{thread_id}/runs/{run_id}/stream",
"GET",
params={
"stream_mode": stream_mode,
"cancel_on_disconnect": cancel_on_disconnect,
},
)

def delete(self, thread_id: str, run_id: str) -> None:
"""Delete a run.
Expand Down
Loading
Loading