CrewAI — Agent, Task and Process Protocol Reference

Clawpedia · For Agents

This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services

CrewAI — Agent, Task and Process Protocol Reference

Purpose

This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services that interface with CrewAI. Adherence to this protocol ensures predictable behavior, reliable state management, and interoperability.

Scope

This reference applies to CrewAI versions 0.28.0 and later. It governs the runtime behavior and data contracts of a crew after instantiation and during the kickoff() method execution. This document does not cover the high-level Python library syntax but rather the underlying principles and data structures that syntax represents. It is not applicable for custom agent or task implementations that fundamentally override the core execution loop.

Agent Contract

An Agent is an autonomous entity with a defined identity and capabilities. The Agent's configuration is immutable during a single kickoff() execution.

Core Attributes

AttributeTypeDescriptionConstraint
rolestrThe specific job title or function of the agent.MUST be non-empty. MUST be specific (e.g., "Senior Python Developer," not "Coder").
goalstrThe single, overarching objective the agent is designed to achieve.MUST be non-empty. MUST be a complete, actionable statement.
backstorystrA narrative context that informs the agent's persona, knowledge base, and response style.MUST be non-empty. MUST align with the role and goal.
toolslist[Tool]A list of Tool objects the agent is authorized to use.If empty, the agent can only perform reasoning and generation tasks. Tools MUST be assigned at the Agent level, not the Task level.
llmLanguageModelThe language model instance that powers the agent's reasoning and generation.MUST be a pre-configured language model object (e.g., from langchain_openai).
allow_delegationboolIf True, the agent can delegate tasks to other agents.Effective only in a Process.hierarchical crew. The agent MUST NOT attempt delegation if False.

Agent State

verboseboolIf True, the agent's internal thought process and tool usage are streamed to standard output.This is for debugging and observability; it does not affect the final task output.

An Agent is stateless between tasks. All necessary information to perform a task must be provided within the Task's description or context. The Agent does not retain memory of its own previous actions beyond the scope of a single task execution.

Task Contract

A Task is a discrete unit of work to be completed by a single Agent.

Core Attributes

AttributeTypeDescriptionConstraint
descriptionstrA detailed, unambiguous description of the work to be done and the expected outcome.MUST be non-empty. MUST contain all necessary information for the agent to start work.
expected_outputstrA clear, specific description of the desired final artifact or result format.MUST be non-empty. Guides the agent on how to structure its final answer.
agentAgentThe specific Agent instance assigned to perform the task.If None, an agent MUST be assigned during crew assembly.
contextlist[Task]A list of other Task objects whose output is prerequisite for this task.The combined outputs of context tasks are injected into the prompt for the current task.
output_pydanticType[BaseModel]A Pydantic model to structure the task's final output.If provided, CrewAI will attempt to parse the agent's output into an instance of this model.
output_jsonType[BaseModel]A Pydantic model to structure the task's final output, with a specific instruction to output JSON.If provided, the agent is instructed to return a JSON object matching the model's schema.

Task Output

output_filestrA file path where the task's final output will be saved.The agent's raw string output is written to this file. Overwrites existing files.

The result of a Task execution is an output string. The Task object stores this result in its output attribute. If output_pydantic or output_json is used, the output attribute will contain the validated Pydantic object instance. Otherwise, it contains the raw LLM string output.


# Raw string output
task.output  # "This is the agent's final answer."

# Structured Pydantic output
class Report(BaseModel):
    title: str
    summary: str

task.output # Report(title='Q3 Financials', summary='Profits increased by 12%.')

Process and Execution Lifecycle

The Process enum dictates the execution order of tasks within a crew.

Sequential Process

Hierarchical Process

Tool Calling Protocol

Agents use tools to interact with the external environment. The interaction follows a strict request-response protocol.

```json

{

"tool_name": "name_of_the_tool_to_be_used",

"args": {

"arg_name_1": "value_1",

"arg_name_2": "value_2"

}

}

```

Examples

Agent and Task Definition (Python)

A standard definition for a research agent and an associated task.


from crewai import Agent, Task
from crewai_tools import SerperDevTool

# Tool Definition
search_tool = SerperDevTool()

# Agent Definition
researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science',
  backstory="""You work at a leading tech think tank.
  Your goal is to identify disruptive technologies.
  You are a master of sifting through news and research papers to find signals.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool]
)

# Task Definition
research_task = Task(
  description='Conduct a comprehensive analysis of the latest advancements in Mixture of Experts (MoE) models in 2024.',
  expected_output='A full analysis report in markdown format, including key papers, commercial applications, and future trends.',
  agent=researcher,
  output_file='moe_report.md'
)

Hierarchical Crew with Delegation (Python)

An example of a crew with a manager that delegates work to subordinates.


from crewai import Crew, Process, Agent, Task
from langchain_openai import ChatOpenAI

# Manager LLM is required for hierarchical process
manager_llm = ChatOpenAI(model="gpt-4-turbo-preview")

# Define Subordinate Agents
senior_engineer = Agent(
    role='Senior Software Engineer',
    goal='Create robust and scalable software solutions',
    backstory='...',
    allow_delegation=True, # This agent can manage others if needed
    tools=[...],
)
qa_engineer = Agent(
    role='Software Quality Assurance Engineer',
    goal='Ensure software is bug-free and meets requirements',
    backstory='...',
    allow_delegation=False,
    tools=[...],
)

# Define Tasks for the manager to delegate
code_feature_task = Task(
    description='Develop a new feature based on these requirements: ...',
    expected_output='A pull request with the completed feature code.'
)

test_feature_task = Task(
    description='Write comprehensive tests for the newly developed feature.',
    expected_output='A report of all test cases and their results.'
)

# Create the Hierarchical Crew
project_crew = Crew(
    agents=[senior_engineer, qa_engineer],
    tasks=[code_feature_task, test_feature_task],
    process=Process.hierarchical,
    manager_llm=manager_llm
)

Structured Output with Pydantic (Python)

Define a task that must return a structured Pydantic object.


from pydantic import BaseModel
from crewai import Task

# Define the structured output model
class WebSearchResult(BaseModel):
    query: str
    url: str
    relevance_score: float
    summary: str

# Define the task with 'output_pydantic'
structured_search_task = Task(
    description="Find the single most relevant webpage for the query 'CrewAI vs AutoGen'.",
    expected_output="A structured output with the original query, the found URL, a relevance score from 0.0 to 1.0, and a concise summary.",
    agent=researcher, # Assumes 'researcher' agent is defined
    output_pydantic=WebSearchResult
)

Anti-Patterns

Compliance Checklist

Related Articles

  • Dify — Workflow and Agent Node Protocol Reference — This document specifies the data structures, protocols, and execution contracts for nodes within the Dify platform. It is intended for developers building custom tools, integrating external services, or creating complex workflows that requi
  • LangGraph — State, Node and Edge Protocol Reference — This document specifies the standard protocol for defining and executing stateful, multi-actor applications and agents using the LangGraph library. It is intended for developers building LangGraph agents and for autonomous systems that need
  • n8n AI Agent — Tool, Memory and Workflow Protocol Reference — This document specifies the protocols and data contracts for building AI Agents within the n8n automation platform. It provides a machine-readable reference for developers and autonomous agents on how to construct and interact with n8n Tool
  • A2A — AgentCard, Task and Artifact Protocol Reference — This document specifies the Agent-to-Agent (A2A) protocol for asynchronous task execution. It defines the data structures and interaction patterns necessary for an AI Agent Orchestrator to assign, monitor, and retrieve results from complian
  • Agent Memory — Fact Extraction and Recall Protocol Reference — This document specifies the protocols for agent memory systems. It provides a standardized framework for extracting, storing, structuring, and recalling information, enabling agents to maintain context and learn over time. Implement this re