diff --git a/libs/langgraph/bench/__main__.py b/libs/langgraph/bench/__main__.py index f45ffd5e0..0841282bf 100644 --- a/libs/langgraph/bench/__main__.py +++ b/libs/langgraph/bench/__main__.py @@ -29,6 +29,21 @@ async def arun(graph: Pregel, input: dict): ) +async def arun_first_event_latency(graph: Pregel, input: dict) -> None: + """Latency for the first event. + + Run the graph until the first event is processed and then stop. + """ + async for _ in graph.astream( + input, + { + "configurable": {"thread_id": str(uuid4())}, + "recursion_limit": 1000000000, + }, + ): + break + + def run(graph: Pregel, input: dict): len( [ @@ -44,6 +59,21 @@ def run(graph: Pregel, input: dict): ) +def run_first_event_latency(graph: Pregel, input: dict) -> None: + """Latency for the first event. + + Run the graph until the first event is processed and then stop. + """ + for _ in graph.stream( + input, + { + "configurable": {"thread_id": str(uuid4())}, + "recursion_limit": 1000000000, + }, + ): + break + + benchmarks = ( ( "fanout_to_subgraph_10x", @@ -330,7 +360,23 @@ benchmarks = ( r = Runner() +# Full graph run time for name, agraph, graph, input in benchmarks: r.bench_async_func(name, arun, agraph, input, loop_factory=new_event_loop) if graph is not None: r.bench_func(name + "_sync", run, graph, input) + + +# First event latency +for name, agraph, graph, input in benchmarks: + r.bench_async_func( + name + "_first_event_latency", + arun_first_event_latency, + agraph, + input, + loop_factory=new_event_loop, + ) + if graph is not None: + r.bench_func( + name + "_first_event_latency_sync", run_first_event_latency, graph, input + ) diff --git a/libs/langgraph/bench/sequential.py b/libs/langgraph/bench/sequential.py index 3ab92912f..ef3ce6329 100644 --- a/libs/langgraph/bench/sequential.py +++ b/libs/langgraph/bench/sequential.py @@ -4,7 +4,7 @@ from langgraph.graph import MessagesState, StateGraph from langgraph.utils.runnable import RunnableCallable -def create_sequential(number_nodes) -> StateGraph: +def create_sequential(number_nodes: int) -> StateGraph: """Create a sequential no-op graph consisting of a few hundred nodes.""" builder = StateGraph(MessagesState)