From b197dcd950dc31ab960f8307e62b91c4f9b94d62 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Sun, 9 Feb 2025 17:03:22 -0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Aseem Saxena --- src/crewai/flow/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/crewai/flow/utils.py b/src/crewai/flow/utils.py index 7e15c60f6..34abd5498 100644 --- a/src/crewai/flow/utils.py +++ b/src/crewai/flow/utils.py @@ -97,6 +97,8 @@ def get_possible_return_constants(function: Any) -> Optional[List[str]]: def calculate_node_levels(flow: Any) -> Dict[str, int]: """ Calculate the hierarchical level of each node in the flow. + Performs a breadth-first traversal of the flow graph to assign levels + to nodes, starting with start methods at level 0. Parameters ---------- @@ -107,6 +109,13 @@ def calculate_node_levels(flow: Any) -> Dict[str, int]: ------- Dict[str, int] Dictionary mapping method names to their hierarchical levels. + Notes + ----- + - Start methods are assigned level 0 + - Each subsequent connected node is assigned level = parent_level + 1 + - Handles both OR and AND conditions for listeners + - Processes router paths separately + """ levels: Dict[str, int] = {} queue: Deque[str] = deque()