Skip to main content

Overview

A crew in crewAI represents a collaborative group of agents working together to achieve a set of tasks. Each crew defines the strategy for task execution, agent collaboration, and the overall workflow.

Crew Attributes

Crew Max RPM: The max_rpm attribute sets the maximum number of requests per minute the crew can perform to avoid rate limits and will override individual agents’ max_rpm settings if you set it.

Creating Crews

There are two common ways to create crews in CrewAI: using JSONC project configuration (recommended for new crews) or defining them directly in code. New projects created with crewai create crew <name> use crew.jsonc for crew-level settings and tasks, plus one file per agent in agents/. crewai run automatically detects crew.jsonc or crew.json, loads the referenced agents, prompts for missing placeholders, and kicks off the crew.

Example crew.jsonc

crew.jsonc
Each string in agents resolves to agents/<name>.jsonc first, then agents/<name>.json.
agents/researcher.jsonc
Tasks run in the order they appear in tasks when process is "sequential".
For hierarchical crews, set "process": "hierarchical" and provide either manager_llm or manager_agent. A manager_agent can reference an agents/<name>.jsonc file that is not included in the top-level agents list. JSON crew definitions support crew-level fields such as process, verbose, memory, cache, max_rpm, planning, planning_llm, manager_llm, manager_agent, function_calling_llm, output_log_file, stream, tracing, before_kickoff_callbacks, and after_kickoff_callbacks. Python callbacks and custom classes use {"python": "module.attribute"}. Custom tools use "custom:<name>" and load tools/<name>.py at runtime.
Only run JSON crew projects from sources you trust. custom:<name> tools and {"python": "module.attribute"} references execute local Python code when the crew loads.

Classic Python/YAML Configuration

Classic projects created with crewai create crew <name> --classic use crew.py, config/agents.yaml, config/tasks.yaml, and the @CrewBase, @agent, @task, and @crew decorators. That pattern remains supported and is documented in Using Annotations.

Direct Code Definition (Alternative)

Alternatively, you can define the crew directly in code without using YAML configuration files.
code
How to run the above code:
code
In this example:
  • Agents and tasks are defined directly within the class without decorators.
  • We manually create and manage the list of agents and tasks.
  • This approach provides more control but can be less maintainable for larger projects.

Crew Output

The output of a crew in the CrewAI framework is encapsulated within the CrewOutput class. This class provides a structured way to access results of the crew’s execution, including various formats such as raw strings, JSON, and Pydantic models. The CrewOutput includes the results from the final task output, token usage, and individual task outputs.

Crew Output Attributes

Crew Output Methods and Properties

Accessing Crew Outputs

Once a crew has been executed, its output can be accessed through the output attribute of the Crew object. The CrewOutput class provides various ways to interact with and present this output.

Example

Code

Accessing Crew Logs

You can see real time log of the crew execution, by setting output_log_file as a True(Boolean) or a file_name(str). Supports logging of events as both file_name.txt and file_name.json. In case of True(Boolean) will save as logs.txt. In case of output_log_file is set as False(Boolean) or None, the logs will not be populated.
Code

Checkpointing

Checkpointing lets a crew automatically save its state after key events (e.g. task completion) so that long-running or interrupted runs can be resumed exactly where they left off without re-executing completed tasks.

Quick Start

Pass checkpoint=True to enable checkpointing with sensible defaults (saves to .checkpoints/ after every task):
Code

Full Control with CheckpointConfig

Use CheckpointConfig for fine-grained control over location, trigger events, storage backend, and retention:
Code

Resuming from a Checkpoint

Use Crew.from_checkpoint() to restore a crew from a saved checkpoint file, then call kickoff() to resume:
Code
When restoring from a checkpoint, checkpoint_inputs, checkpoint_train, and checkpoint_kickoff_event_id are automatically reconstructed — you do not need to set these manually.

CheckpointConfig Attributes

Memory Utilization

Crews can utilize memory (short-term, long-term, and entity memory) to enhance their execution and learning over time. This feature allows crews to store and recall execution memories, aiding in decision-making and task execution strategies.

Cache Utilization

Caches can be employed to store the results of tools’ execution, making the process more efficient by reducing the need to re-execute identical tasks.

Crew Usage Metrics

After the crew execution, you can access the usage_metrics attribute to view the language model (LLM) usage metrics for all tasks executed by the crew. This provides insights into operational efficiency and areas for improvement.
Code

Crew Execution Process

  • Sequential Process: Tasks are executed one after another, allowing for a linear flow of work.
  • Hierarchical Process: A manager agent coordinates the crew, delegating tasks and validating outcomes before proceeding. Note: A manager_llm or manager_agent is required for this process and it’s essential for validating the process flow.

Kicking Off a Crew

Once your crew is assembled, initiate the workflow with the kickoff() method. This starts the execution process according to the defined process flow.
Code

Different Ways to Kick Off a Crew

Once your crew is assembled, initiate the workflow with the appropriate kickoff method. CrewAI provides several methods for better control over the kickoff process.

Synchronous Methods

  • kickoff(): Starts the execution process according to the defined process flow.
  • kickoff_for_each(): Executes tasks sequentially for each provided input event or item in the collection.

Asynchronous Methods

CrewAI offers two approaches for async execution:
For high-concurrency workloads, akickoff() and akickoff_for_each() are recommended as they use native async for task execution, memory operations, and knowledge retrieval.
Code
These methods provide flexibility in how you manage and execute tasks within your crew, allowing for both synchronous and asynchronous workflows tailored to your needs. For detailed async examples, see the Kickoff Crew Asynchronously guide.

Streaming Crew Execution

For real-time visibility into crew execution, you can enable streaming to receive output as it’s generated:
Code
Learn more about streaming in the Streaming Crew Execution guide.

Replaying from a Specific Task

You can now replay from a specific task using our CLI command replay. The replay feature in CrewAI allows you to replay from a specific task using the command-line interface (CLI). By running the command crewai replay -t <task_id>, you can specify the task_id for the replay process. Kickoffs will now save the latest kickoffs returned task outputs locally for you to be able to replay from.

Replaying from a Specific Task Using the CLI

To use the replay feature, follow these steps:
  1. Open your terminal or command prompt.
  2. Navigate to the directory where your CrewAI project is located.
  3. Run the following command:
To view the latest kickoff task IDs, use:
Then, to replay from a specific task, use:
These commands let you replay from your latest kickoff tasks, still retaining context from previously executed tasks.