From 66c66e3d84fbd319f1d1a3a3bb3963e3aa95159a Mon Sep 17 00:00:00 2001
From: "Brandon Hancock (bhancock_ai)"
<109994880+bhancockio@users.noreply.github.com>
Date: Wed, 26 Feb 2025 15:21:36 -0500
Subject: [PATCH] Update docs (#2226)
---
docs/concepts/cli.mdx | 9 ++--
docs/concepts/flows.mdx | 35 ++++++++++++-
src/crewai/cli/cli.py | 1 -
src/crewai/cli/run_crew.py | 68 +++++++++++++++++++++----
src/crewai/cli/templates/flow/README.md | 4 +-
5 files changed, 98 insertions(+), 19 deletions(-)
diff --git a/docs/concepts/cli.mdx b/docs/concepts/cli.mdx
index 4c9f617ba..ecdcd0836 100644
--- a/docs/concepts/cli.mdx
+++ b/docs/concepts/cli.mdx
@@ -136,17 +136,21 @@ crewai test -n 5 -m gpt-3.5-turbo
### 8. Run
-Run the crew.
+Run the crew or flow.
```shell Terminal
crewai run
```
+
+
+Starting from version 0.103.0, the `crewai run` command can be used to run both standard crews and flows. For flows, it automatically detects the type from pyproject.toml and runs the appropriate command. This is now the recommended way to run both crews and flows.
+
+
Make sure to run these commands from the directory where your CrewAI project is set up.
Some commands may require additional configuration or setup within your project structure.
-
### 9. Chat
Starting in version `0.98.0`, when you run the `crewai chat` command, you start an interactive session with your crew. The AI assistant will guide you by asking for necessary inputs to execute the crew. Once all inputs are provided, the crew will execute its tasks.
@@ -175,7 +179,6 @@ def crew(self) -> Crew:
```
-
### 10. API Keys
When running ```crewai create crew``` command, the CLI will first show you the top 5 most common LLM providers and ask you to select one.
diff --git a/docs/concepts/flows.mdx b/docs/concepts/flows.mdx
index c22a619fe..8ab99ec01 100644
--- a/docs/concepts/flows.mdx
+++ b/docs/concepts/flows.mdx
@@ -150,12 +150,12 @@ final_output = flow.kickoff()
print("---- Final Output ----")
print(final_output)
-````
+```
```text Output
---- Final Output ----
Second method received: Output from first_method
-````
+```
@@ -738,3 +738,34 @@ Also, check out our YouTube video on how to use flows in CrewAI below!
referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen
>
+
+## Running Flows
+
+There are two ways to run a flow:
+
+### Using the Flow API
+
+You can run a flow programmatically by creating an instance of your flow class and calling the `kickoff()` method:
+
+```python
+flow = ExampleFlow()
+result = flow.kickoff()
+```
+
+### Using the CLI
+
+Starting from version 0.103.0, you can run flows using the `crewai run` command:
+
+```shell
+crewai run
+```
+
+This command automatically detects if your project is a flow (based on the `type = "flow"` setting in your pyproject.toml) and runs it accordingly. This is the recommended way to run flows from the command line.
+
+For backward compatibility, you can also use:
+
+```shell
+crewai flow kickoff
+```
+
+However, the `crewai run` command is now the preferred method as it works for both crews and flows.
diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py
index 761cc52ad..b2d59adbe 100644
--- a/src/crewai/cli/cli.py
+++ b/src/crewai/cli/cli.py
@@ -203,7 +203,6 @@ def install(context):
@crewai.command()
def run():
"""Run the Crew."""
- click.echo("Running the Crew")
run_crew()
diff --git a/src/crewai/cli/run_crew.py b/src/crewai/cli/run_crew.py
index 95b560109..62241a4b5 100644
--- a/src/crewai/cli/run_crew.py
+++ b/src/crewai/cli/run_crew.py
@@ -1,4 +1,6 @@
import subprocess
+from enum import Enum
+from typing import List, Optional
import click
from packaging import version
@@ -7,16 +9,24 @@ from crewai.cli.utils import read_toml
from crewai.cli.version import get_crewai_version
+class CrewType(Enum):
+ STANDARD = "standard"
+ FLOW = "flow"
+
+
def run_crew() -> None:
"""
- Run the crew by running a command in the UV environment.
+ Run the crew or flow by running a command in the UV environment.
+
+ Starting from version 0.103.0, this command can be used to run both
+ standard crews and flows. For flows, it detects the type from pyproject.toml
+ and automatically runs the appropriate command.
"""
- command = ["uv", "run", "run_crew"]
crewai_version = get_crewai_version()
min_required_version = "0.71.0"
-
pyproject_data = read_toml()
+ # Check for legacy poetry configuration
if pyproject_data.get("tool", {}).get("poetry") and (
version.parse(crewai_version) < version.parse(min_required_version)
):
@@ -26,18 +36,54 @@ def run_crew() -> None:
fg="red",
)
+ # Determine crew type
+ is_flow = pyproject_data.get("tool", {}).get("crewai", {}).get("type") == "flow"
+ crew_type = CrewType.FLOW if is_flow else CrewType.STANDARD
+
+ # Display appropriate message
+ click.echo(f"Running the {'Flow' if is_flow else 'Crew'}")
+
+ # Execute the appropriate command
+ execute_command(crew_type)
+
+
+def execute_command(crew_type: CrewType) -> None:
+ """
+ Execute the appropriate command based on crew type.
+
+ Args:
+ crew_type: The type of crew to run
+ """
+ command = ["uv", "run", "kickoff" if crew_type == CrewType.FLOW else "run_crew"]
+
try:
subprocess.run(command, capture_output=False, text=True, check=True)
except subprocess.CalledProcessError as e:
- click.echo(f"An error occurred while running the crew: {e}", err=True)
- click.echo(e.output, err=True, nl=True)
-
- if pyproject_data.get("tool", {}).get("poetry"):
- click.secho(
- "It's possible that you are using an old version of crewAI that uses poetry, please run `crewai update` to update your pyproject.toml to use uv.",
- fg="yellow",
- )
+ handle_error(e, crew_type)
except Exception as e:
click.echo(f"An unexpected error occurred: {e}", err=True)
+
+
+def handle_error(error: subprocess.CalledProcessError, crew_type: CrewType) -> None:
+ """
+ Handle subprocess errors with appropriate messaging.
+
+ Args:
+ error: The subprocess error that occurred
+ crew_type: The type of crew that was being run
+ """
+ entity_type = "flow" if crew_type == CrewType.FLOW else "crew"
+ click.echo(f"An error occurred while running the {entity_type}: {error}", err=True)
+
+ if error.output:
+ click.echo(error.output, err=True, nl=True)
+
+ pyproject_data = read_toml()
+ if pyproject_data.get("tool", {}).get("poetry"):
+ click.secho(
+ "It's possible that you are using an old version of crewAI that uses poetry, "
+ "please run `crewai update` to update your pyproject.toml to use uv.",
+ fg="yellow",
+ )
diff --git a/src/crewai/cli/templates/flow/README.md b/src/crewai/cli/templates/flow/README.md
index b6ce2da71..140834e62 100644
--- a/src/crewai/cli/templates/flow/README.md
+++ b/src/crewai/cli/templates/flow/README.md
@@ -30,13 +30,13 @@ crewai install
## Running the Project
-To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project:
+To kickstart your flow and begin execution, run this from the root folder of your project:
```bash
crewai run
```
-This command initializes the {{name}} Crew, assembling the agents and assigning them tasks as defined in your configuration.
+This command initializes the {{name}} Flow as defined in your configuration.
This example, unmodified, will run the create a `report.md` file with the output of a research on LLMs in the root folder.