4
Defining Tasks
João Moura edited this page 2024-01-21 13:42:37 -03:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Overview of a Task

In the CrewAI framework, tasks are the individual assignments that agents are responsible for completing. They are the fundamental units of work that your AI crew will undertake. Understanding how to define and manage tasks is key to leveraging the full potential of CrewAI.

A task in CrewAI encapsulates all the information needed for an agent to execute it, including a description, the agent assigned to it, and any specific tools required. Tasks are designed to be flexible, allowing for both simple and complex actions depending on your needs.

Properties of a Task

Every task in CrewAI has several properties:

  • Description: A clear and concise statement of what needs to be done.
  • Agent: The agent assigned to the task (optional). If no agent is specified, the task can be picked up by any agent based on the process defined.
  • Tools: A list of tools (optional) that the agent can use to complete the task. These can override the agent's default tools if necessary.

Creating a Task

Creating a task is straightforward. You define what needs to be done and, optionally, who should do it and what tools they should use. Heres a conceptual guide:

from crewai import Task

# Define a task with a designated agent and specific tools
task = Task(description='Generate monthly sales report', agent=sales_agent, tools=[reporting_tool])

Task Assignment

Tasks can be assigned to agents in several ways:

  • Directly, by specifying the agent when creating the task.
  • [WIP] Through the Crew's process, which can assign tasks based on agent roles, availability, or other criteria.

Task Execution

Once a task has been defined and assigned, it's ready to be executed. Execution is typically handled by the Crew object, which manages the workflow and ensures that tasks are completed according to the defined process.

Task Collaboration

Tasks in CrewAI can be designed to require collaboration between agents. For example, one agent might gather data while another analyzes it. This collaborative approach can be defined within the task properties and managed by the Crew's process.

Conclusion

Tasks are the driving force behind the actions of agents in CrewAI. By properly defining tasks, you set the stage for your AI agents to work effectively, either independently or as a collaborative unit. In the following sections, we will explore how tasks fit into the larger picture of processes and crew management.