Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

feat: add docstring (#1819)

Marco Vinciguerraa548463faebd
diff --git a/src/crewai/flow/flow.py b/src/crewai/flow/flow.py
index 806d9ec84..dc46aa6d8 100644
--- a/src/crewai/flow/flow.py
+++ b/src/crewai/flow/flow.py
@@ -95,7 +95,6 @@ def start(condition: Optional[Union[str, dict, Callable]] = None) -> Callable:
return decorator
-
def listen(condition: Union[str, dict, Callable]) -> Callable:
"""
Creates a listener that executes when specified conditions are met.
@@ -198,7 +197,6 @@ def router(condition: Union[str, dict, Callable]) -> Callable:
"""
def decorator(func):
func.__is_router__ = True
- # Handle conditions like listen/start
if isinstance(condition, str):
func.__trigger_methods__ = [condition]
func.__condition_type__ = "OR"
@@ -220,7 +218,6 @@ def router(condition: Union[str, dict, Callable]) -> Callable:
return decorator
-
def or_(*conditions: Union[str, dict, Callable]) -> dict:
"""
Combines multiple conditions with OR logic for flow control.
diff --git a/src/crewai/flow/flow_visualizer.py b/src/crewai/flow/flow_visualizer.py
index ceacee91f..a70e91a18 100644
--- a/src/crewai/flow/flow_visualizer.py
+++ b/src/crewai/flow/flow_visualizer.py
@@ -18,6 +18,8 @@ from crewai.flow.visualization_utils import (
class FlowPlot:
+ """Handles the creation and rendering of flow visualization diagrams."""
+
def __init__(self, flow):
"""
Initialize FlowPlot with a flow object.
diff --git a/src/crewai/flow/html_template_handler.py b/src/crewai/flow/html_template_handler.py
index 396af5546..f0d2d89ad 100644
--- a/src/crewai/flow/html_template_handler.py
+++ b/src/crewai/flow/html_template_handler.py
@@ -6,6 +6,8 @@ from crewai.flow.path_utils import safe_path_join, validate_path_exists
class HTMLTemplateHandler:
+ """Handles HTML template processing and generation for flow visualization diagrams."""
+
def __init__(self, template_path, logo_path):
"""
Initialize HTMLTemplateHandler with validated template and logo paths.
@@ -29,19 +31,23 @@ class HTMLTemplateHandler:
raise ValueError(f"Invalid template or logo path: {e}")
def read_template(self):
+ """Read and return the HTML template file contents."""
with open(self.template_path, "r", encoding="utf-8") as f:
return f.read()
def encode_logo(self):
+ """Convert the logo SVG file to base64 encoded string."""
with open(self.logo_path, "rb") as logo_file:
logo_svg_data = logo_file.read()
return base64.b64encode(logo_svg_data).decode("utf-8")
def extract_body_content(self, html):
+ """Extract and return content between body tags from HTML string."""
match = re.search("<body.*?>(.*?)</body>", html, re.DOTALL)
return match.group(1) if match else ""
def generate_legend_items_html(self, legend_items):
+ """Generate HTML markup for the legend items."""
legend_items_html = ""
for item in legend_items:
if "border" in item:
@@ -69,6 +75,7 @@ class HTMLTemplateHandler:
return legend_items_html
def generate_final_html(self, network_body, legend_items_html, title="Flow Plot"):
+ """Combine all components into final HTML document with network visualization."""
html_template = self.read_template()
logo_svg_base64 = self.encode_logo()
diff --git a/src/crewai/flow/legend_generator.py b/src/crewai/flow/legend_generator.py
index fb3d5cfd6..f250dec20 100644
--- a/src/crewai/flow/legend_generator.py
+++ b/src/crewai/flow/legend_generator.py
@@ -1,3 +1,4 @@
+
def get_legend_items(colors):
return [
{"label": "Start Method", "color": colors["start"]},
diff --git a/src/crewai/flow/visualization_utils.py b/src/crewai/flow/visualization_utils.py
index 70f527f1a..781677276 100644
--- a/src/crewai/flow/visualization_utils.py
+++ b/src/crewai/flow/visualization_utils.py
@@ -55,6 +55,7 @@ def method_calls_crew(method: Any) -> bool:
return False
class CrewCallVisitor(ast.NodeVisitor):
+ """AST visitor to detect .crew() method calls."""
def __init__(self):
self.found = False