diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 75321bf46..88754e1fe 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -712,12 +712,6 @@ class Pregel( raise ValueError("No tasks to run in graph.") else: break - elif step == config["recursion_limit"]: - raise GraphRecursionError( - f"Recursion limit of {config['recursion_limit']} reached" - "without hitting a stop condition. You can increase the " - "limit by setting the `recursion_limit` config key." - ) # before execution, check if we should interrupt if _should_interrupt( @@ -837,6 +831,12 @@ class Pregel( next_tasks, ): break + else: + raise GraphRecursionError( + f"Recursion limit of {config['recursion_limit']} reached" + "without hitting a stop condition. You can increase the " + "limit by setting the `recursion_limit` config key." + ) # set final channel values as run output run_manager.on_chain_end(read_channels(channels, output_keys)) @@ -980,12 +980,6 @@ class Pregel( raise ValueError("No tasks to run in graph.") else: break - elif step == config["recursion_limit"]: - raise GraphRecursionError( - f"Recursion limit of {config['recursion_limit']} reached" - "without hitting a stop condition. You can increase the limit" - "by setting the `recursion_limit` config key." - ) # before execution, check if we should interrupt if _should_interrupt( @@ -1116,6 +1110,12 @@ class Pregel( next_tasks, ): break + else: + raise GraphRecursionError( + f"Recursion limit of {config['recursion_limit']} reached" + "without hitting a stop condition. You can increase the limit" + "by setting the `recursion_limit` config key." + ) # set final channel values as run output await run_manager.on_chain_end(read_channels(channels, output_keys))