diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index 52d2bc75c..5ae9feb03 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -9,6 +9,7 @@ from .create_crew import create_crew from .evaluate_crew import evaluate_crew from .replay_from_task import replay_task_command from .reset_memories_command import reset_memories_command +from .run_crew import run_crew from .train_crew import train_crew @@ -147,5 +148,12 @@ def test(n_iterations: int, model: str): evaluate_crew(n_iterations, model) +@crewai.command() +def run(): + """Run the crew.""" + click.echo("Running the crew") + run_crew() + + if __name__ == "__main__": crewai() diff --git a/src/crewai/cli/run_crew.py b/src/crewai/cli/run_crew.py new file mode 100644 index 000000000..51ed48f3a --- /dev/null +++ b/src/crewai/cli/run_crew.py @@ -0,0 +1,23 @@ +import subprocess + +import click + + +def run_crew() -> None: + """ + Run the crew by running a command in the Poetry environment. + """ + command = ["poetry", "run"] + + try: + result = subprocess.run(command, capture_output=False, text=True, check=True) + + if result.stderr: + click.echo(result.stderr, err=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) + + except Exception as e: + click.echo(f"An unexpected error occurred: {e}", err=True) diff --git a/src/crewai/cli/templates/pyproject.toml b/src/crewai/cli/templates/pyproject.toml index 048782d1c..54700657c 100644 --- a/src/crewai/cli/templates/pyproject.toml +++ b/src/crewai/cli/templates/pyproject.toml @@ -10,6 +10,7 @@ crewai = { extras = ["tools"], version = "^0.46.0" } [tool.poetry.scripts] {{folder_name}} = "{{folder_name}}.main:run" +run = "{{folder_name}}.main:run" train = "{{folder_name}}.main:train" replay = "{{folder_name}}.main:replay" test = "{{folder_name}}.main:test"