diff --git a/libs/langgraph/bench/__main__.py b/libs/langgraph/bench/__main__.py index 677e79440..9b191f68d 100644 --- a/libs/langgraph/bench/__main__.py +++ b/libs/langgraph/bench/__main__.py @@ -7,6 +7,7 @@ from uvloop import new_event_loop from bench.fanout_to_subgraph import fanout_to_subgraph, fanout_to_subgraph_sync from bench.react_agent import react_agent +from bench.sequential import create_sequential from bench.wide_state import wide_state from langgraph.checkpoint.memory import MemorySaver from langgraph.pregel import Pregel @@ -203,6 +204,12 @@ benchmarks = ( ] }, ), + ( + "sequential_graph_200_nodes", + create_sequential(200).compile(), + create_sequential(200).compile(), + {"messages": []}, # Empty list of messages + ), ) diff --git a/libs/langgraph/bench/sequential.py b/libs/langgraph/bench/sequential.py new file mode 100644 index 000000000..1565c2044 --- /dev/null +++ b/libs/langgraph/bench/sequential.py @@ -0,0 +1,39 @@ +"""Create a sequential no-op graph consisting of a few hundred nodes.""" + +from langgraph.graph import MessagesState, StateGraph + + +def create_sequential(number_nodes) -> StateGraph: + """Create a sequential no-op graph consisting of a few hundred nodes.""" + builder = StateGraph(MessagesState) + + async def noop(state: MessagesState) -> None: + """No-op function.""" + pass + + prev_node = "__start__" + + for i in range(number_nodes): + name = f"node_{i}" + builder.add_node(name, noop) + builder.add_edge(prev_node, name) + prev_node = name + + builder.add_edge(prev_node, "__end__") + return builder + + +if __name__ == "__main__": + import asyncio + + import uvloop + + graph = create_sequential(200).compile() + input = {"messages": []} # Empty list of messages + config = {"recursion_limit": 20000000000} + + async def run(): + len([c async for c in graph.astream(input, config=config)]) + + uvloop.install() + asyncio.run(run())