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: By default raise errors in /wait endpoint #2204

Merged
merged 2 commits into from
Oct 28, 2024
Merged
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
17 changes: 16 additions & 1 deletion libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {

Check notice on line 1 in libs/sdk-js/src/client.ts

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... WARNING: the benchmark result may be unstable * the standard deviation (6.58 ms) is 12% of the mean (54.9 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: Mean +- std dev: 54.9 ms +- 6.6 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 46.9 ms +- 3.5 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 77.2 ms +- 1.6 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 85.6 ms +- 0.8 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 474 ms +- 9 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 430 ms +- 6 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 814 ms +- 44 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 840 ms +- 18 ms ......................................... react_agent_10x: Mean +- std dev: 29.0 ms +- 0.6 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.5 ms +- 1.8 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 48.0 ms +- 3.5 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 37.8 ms +- 3.6 ms ......................................... react_agent_100x: Mean +- std dev: 330 ms +- 14 ms ......................................... react_agent_100x_sync: Mean +- std dev: 263 ms +- 14 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 917 ms +- 10 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 818 ms +- 10 ms ......................................... wide_state_25x300: Mean +- std dev: 18.4 ms +- 0.4 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 10.9 ms +- 0.2 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 272 ms +- 3 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 262 ms +- 5 ms ......................................... wide_state_15x600: Mean +- std dev: 21.3 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 12.5 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 472 ms +- 7 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 470 ms +- 14 ms ......................................... wide_state_9x1200: Mean +- std dev: 21.3 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 12.5 ms +- 0.1 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 307 ms +- 6 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 302 ms +- 13 ms

Check notice on line 1 in libs/sdk-js/src/client.ts

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +=========================================+=========+=======================+ | fanout_to_subgraph_100x | 491 ms | 474 ms: 1.04x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 835 ms | 814 ms: 1.03x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 836 ms | 818 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 335 ms | 330 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 18.5 ms | 18.4 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 12.6 ms | 12.5 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 847 ms | 840 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 86.1 ms | 85.6 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 474 ms | 472 ms: 1.00x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x | 48.5 ms | 54.9 ms: 1.13x slower | +-----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x faster | +-----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (18): wide_state_9x1200_checkpoint_sync, react_agent_10x_checkpoint_sync, react_agent_100x_sync, wide_state_15x600, wide_state_25x300_checkpoint, wide_state_9x1200, react_agent_100x_checkpoint, react_agent_10x_sync, wide_state_9x1200_checkpoint, wide_state_9x1200_sync, react_agent_10x, fanout_to_subgraph_10x_checkpoint, react_agent_10x_checkpoint, wide_state_25x300_sync, wide_state_25x300_checkpoint_sync, wide_state_15x600_checkpoint_sync, fanout_to_subgraph_100x_sync, fanout_to_subgraph_10x_sync
Assistant,
AssistantGraph,
Config,
Expand Down Expand Up @@ -852,12 +852,27 @@
};
const endpoint =
threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
return this.fetch<ThreadState["values"]>(endpoint, {
const response = await this.fetch<ThreadState["values"]>(endpoint, {
method: "POST",
json,
timeoutMs: null,
signal: payload?.signal,
});
const raiseError =
payload?.raiseError !== undefined ? payload.raiseError : true;
if (
raiseError &&
"__error__" in response &&
typeof response.__error__ === "object" &&
response.__error__ &&
"error" in response.__error__ &&
"message" in response.__error__
) {
throw new Error(
`${response.__error__?.error}: ${response.__error__?.message}`,
);
}
return response;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion libs/sdk-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ export interface CronsCreatePayload extends RunsCreatePayload {
schedule: string;
}

export type RunsWaitPayload = RunsStreamPayload;
export interface RunsWaitPayload extends RunsStreamPayload {
/**
* Raise errors returned by the run. Default is `true`.
*/
raiseError?: boolean;
}
19 changes: 16 additions & 3 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_client(
client = httpx.AsyncClient(
base_url=url,
transport=transport,
timeout=httpx.Timeout(connect=5, read=60, write=60, pool=5),
timeout=httpx.Timeout(connect=5, read=300, write=300, pool=5),
nfcampos marked this conversation as resolved.
Show resolved Hide resolved
headers=get_headers(api_key, headers),
)
return LangGraphClient(client)
Expand Down Expand Up @@ -1515,6 +1515,7 @@ async def wait(
multitask_strategy: Optional[MultitaskStrategy] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]: ...

@overload
Expand All @@ -1533,6 +1534,7 @@ async def wait(
on_completion: Optional[OnCompletionBehavior] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]: ...

async def wait(
Expand All @@ -1553,6 +1555,7 @@ async def wait(
multitask_strategy: Optional[MultitaskStrategy] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]:
"""Create a run, wait until it finishes and return the final state.

Expand Down Expand Up @@ -1645,9 +1648,19 @@ async def wait(
endpoint = (
f"/threads/{thread_id}/runs/wait" if thread_id is not None else "/runs/wait"
)
return await self.http.post(
response = await self.http.post(
endpoint, json={k: v for k, v in payload.items() if v is not None}
)
if (
raise_error
and isinstance(response, dict)
and "__error__" in response
and isinstance(response["__error__"], dict)
):
raise Exception(
f"{response['__error__'].get('error')}: {response['__error__'].get('message')}"
)
return response

async def list(
self, thread_id: str, *, limit: int = 10, offset: int = 0
Expand Down Expand Up @@ -2260,7 +2273,7 @@ def get_sync_client(
client = httpx.Client(
base_url=url,
transport=transport,
timeout=httpx.Timeout(connect=5, read=60, write=60, pool=5),
timeout=httpx.Timeout(connect=5, read=300, write=300, pool=5),
headers=get_headers(api_key, headers),
)
return SyncLangGraphClient(client)
Expand Down
Loading