Skip to content

Commit

Permalink
feat: add cli to run the crew (crewAIInc#1080)
Browse files Browse the repository at this point in the history
* feat: add cli to run the crew

* feat: change command to run_crew

* feat: change pyprojet to run_Crew

* docs: change docs to address crewai run
  • Loading branch information
pythonbyte authored Aug 8, 2024
1 parent 86c6760 commit 297dc93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def run():

To run your project, use the following command:

```shell
$ crewai run
```
or
```shell
$ poetry run my_project
```
Expand Down
8 changes: 8 additions & 0 deletions src/crewai/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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


Expand Down Expand Up @@ -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()
23 changes: 23 additions & 0 deletions src/crewai/cli/run_crew.py
Original file line number Diff line number Diff line change
@@ -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", "run_crew"]

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)
4 changes: 4 additions & 0 deletions src/crewai/cli/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ poetry install

To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project:

```bash
$ crewai run
```
or
```bash
poetry run {{folder_name}}
```
Expand Down
1 change: 1 addition & 0 deletions src/crewai/cli/templates/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crewai = { extras = ["tools"], version = "^0.46.0" }

[tool.poetry.scripts]
{{folder_name}} = "{{folder_name}}.main:run"
run_crew = "{{folder_name}}.main:run"
train = "{{folder_name}}.main:train"
replay = "{{folder_name}}.main:replay"
test = "{{folder_name}}.main:test"
Expand Down

0 comments on commit 297dc93

Please sign in to comment.