Learn how to use annotations to properly structure agents, tasks, and components in CrewAI
crew.py
file.
@CrewBase
: Used to decorate the main crew class.@agent
: Decorates methods that define and return Agent objects.@task
: Decorates methods that define and return Task objects.@crew
: Decorates the method that creates and returns the Crew object.@llm
: Decorates methods that initialize and return Language Model objects.@tool
: Decorates methods that initialize and return Tool objects.@callback
: Used for defining callback methods.@output_json
: Used for methods that output JSON data.@output_pydantic
: Used for methods that output Pydantic models.@cache_handler
: Used for defining cache handling methods.@CrewBase
annotation is used to decorate the main crew class. This class typically contains configurations and methods for creating agents, tasks, and the crew itself.
@tool
annotation is used to decorate methods that return tool objects. These tools can be used by agents to perform specific tasks.
@llm
annotation is used to decorate methods that initialize and return Language Model objects. These LLMs are used by agents for natural language processing tasks.
@agent
annotation is used to decorate methods that define and return Agent objects.
@task
annotation is used to decorate methods that define and return Task objects. These methods specify the task configuration and the agent responsible for the task.
@crew
annotation is used to decorate the method that creates and returns the Crew
object. This method assembles all the components (agents and tasks) into a functional crew.
agents.yaml
file might look for the researcher agent:
LinkedinProfileCrew
class. The configuration specifies the agent’s role, goal, backstory, and other properties such as the LLM and tools it uses.
Note how the llm
and tools
in the YAML file correspond to the methods decorated with @llm
and @tool
in the Python class.