Implementation:CrewAIInc CrewAI Task Constructor
| Knowledge Sources | |
|---|---|
| Domains | Task_Management, Multi_Agent_Systems |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete class for defining task specifications with descriptions, expected outputs, agent assignment, and structured output schemas provided by the CrewAI framework.
Description
The Task class is a Pydantic model representing a discrete unit of work. It requires a description (supporting {variable} interpolation) and expected_output. Optional fields include the assigned agent, output format (Pydantic model, JSON, or file), task context dependencies, tools, guardrails, human review flags, and async execution mode.
Usage
Import and instantiate Task for each work item in a crew. At minimum, provide description and expected_output. Assign an agent for sequential workflows, or leave unassigned for hierarchical manager routing.
Code Reference
Source Location
- Repository: crewAI
- File: lib/crewai/src/crewai/task.py
- Lines: L84-230
Signature
class Task(BaseModel):
"""Class that represents a task to be executed."""
name: str | None = Field(default=None)
description: str = Field(description="Description of the actual task.")
expected_output: str = Field(description="Clear definition of expected output.")
agent: BaseAgent | None = Field(default=None)
context: list[Task] | None = Field(default=NOT_SPECIFIED)
async_execution: bool | None = Field(default=False)
output_json: type[BaseModel] | None = Field(default=None)
output_pydantic: type[BaseModel] | None = Field(default=None)
response_model: type[BaseModel] | None = Field(default=None)
output_file: str | None = Field(default=None)
create_directory: bool | None = Field(default=True)
tools: list[BaseTool] | None = Field(default_factory=list)
human_input: bool | None = Field(default=False)
markdown: bool | None = Field(default=False)
callback: Any | None = Field(default=None)
guardrail: GuardrailType | None = Field(default=None)
guardrails: GuardrailsType | None = Field(default=None)
guardrail_max_retries: int = Field(default=3)
Import
from crewai import Task
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| description | str | Yes | Task description with optional {variable} interpolation |
| expected_output | str | Yes | Clear specification of expected output |
| agent | None | No | Agent assigned to execute (default: None) |
| output_pydantic | None | No | Pydantic model for structured output |
| output_json | None | No | Pydantic model for JSON output |
| context | None | No | Tasks whose output provides context |
| tools | None | No | Task-specific tools |
| human_input | bool | No | Require human review (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| Task instance | Task | Configured task ready for crew execution |
| output (after execution) | TaskOutput | Contains raw, pydantic, json_dict, agent fields |
Usage Examples
Basic Task
from crewai import Task
research_task = Task(
description="Research the latest developments in {topic}",
expected_output="A comprehensive summary of findings with sources",
agent=researcher,
)
Task with Structured Output
from crewai import Task
from pydantic import BaseModel
class ResearchReport(BaseModel):
title: str
findings: list[str]
recommendations: list[str]
report_task = Task(
description="Analyze {topic} and produce a structured report",
expected_output="A structured research report",
agent=researcher,
output_pydantic=ResearchReport,
)