diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 4289bd5a3..d121191b1 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -708,12 +708,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( @@ -833,6 +827,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)) @@ -976,12 +976,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( @@ -1112,6 +1106,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))