CrewAI Command Guide

This document provides a comprehensive guide to running and using CrewAI, including setting up the environment, using CLI commands, and executing synchronous and asynchronous tasks.


1. Starting a CrewAI Environment

Install CrewAI

To install CrewAI, use the following command:

pip install 'crewai[tools]'

Activate Virtual Environment

Ensure you are in the correct environment before running CrewAI commands:

source /path/to/crewai-env/bin/activate

Update CrewAI

To update CrewAI to the latest version:

crewai update

Check CrewAI Version

To confirm the installed version of CrewAI:

crewai version

2. CrewAI CLI Commands

General Help

To view all available commands:

crewai --help

Initialize a New CrewAI Project

To start a new CrewAI project:

crewai init <project_name>

Run a CrewAI Project

Start the CrewAI environment:

crewai start

Train a Crew

To train a crew:

crewai train

Add Tools

To add a tool to your CrewAI project:

crewai tool add <tool_name>

List Tools

To list all available tools:

crewai tool list

Update Project Configuration

To update the project configuration:

crewai update

3. Synchronous and Asynchronous Commands

Synchronous Commands

These commands run immediately and block further input until completed.

Run a Task

Execute a specific task in a synchronous manner:

crewai task run <task_name>

Test a Crew

Test a specific crew synchronously:

crewai crew test <crew_name>

Asynchronous Commands

These commands allow other tasks to continue while running.

Start a Background Task

Run a task in the background:

crewai task async-run <task_name>

Check Task Status

Monitor the status of an asynchronous task:

crewai task status <task_id>

Stop a Background Task

Terminate a running asynchronous task:

crewai task stop <task_id>

4. File and Configuration Management

YAML Configuration Files

Organize YAML files in folders for better management. Examples include:

  • agents.yaml: Define agents and their behaviors.
  • tasks.yaml: Define tasks and workflows.
  • *_tool.py: Custom tool definitions.

Example Directory Structure

project_name/
├── agents.yaml
├── tasks.yaml
├── tools/
│   ├── my_tool.py
│   ├── another_tool.py

5. Debugging and Logs

View Logs

To view logs of running tasks:

crewai logs

Debug Mode

Run CrewAI in debug mode to get detailed output:

crewai start --debug

6. API Integration

Create a FastAPI Integration

Generate a basic API structure for agents:

crewai api init

Launch API

Run the FastAPI server:

crewai api start

7. Task Management

List Tasks

To list all tasks defined in the project:

crewai task list

Delete a Task

To delete a specific task:

crewai task delete <task_name>

8. Tool Management

Create a New Tool

To create a custom tool:

crewai tool create <tool_name>

Update a Tool

To update an existing tool:

crewai tool update <tool_name>

9. Best Practices

Use Virtual Environments

Always use virtual environments to isolate dependencies.

Modular Configuration

Keep configurations modular by using separate YAML files for agents, tasks, and tools.

Regular Updates

Regularly update CrewAI and dependencies to ensure access to the latest features.


10. Further Resources

For detailed documentation and advanced usage, visit the CrewAI Official Documentation.