Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI Agent Constructor For Specialists

From Leeroopedia

Overview

Concrete Agent class configured for specialist roles in hierarchical crews, emphasizing domain-specific tools and capabilities provided by the CrewAI framework.

Source

src/crewai/agent/core.py:L128-267

Import

from crewai import Agent

Signature

The Agent class is the same class used in all CrewAI workflows, but when used as a specialist in a hierarchical crew, specific parameters take on particular significance:

Parameter Type Default Description
role str required Unique identifier that the manager uses to find and delegate to this specialist. Must be descriptive and unambiguous within the crew.
goal str required The specialist's focused objective, scoping its domain of expertise.
backstory str required Narrative establishing the agent's authority and experience in its domain.
tools list[BaseTool] [] Domain-specific tools available to this specialist for accomplishing delegated work.
llm str or LLM None The language model to use. If None, uses the default model.
allow_delegation bool False Should be False for specialists. Specialists sit at the leaf level of the hierarchy and should not delegate further.
verbose bool False Whether to log detailed execution information.
memory bool True Whether the agent retains memory across interactions within the crew run.
max_iter int 25 Maximum number of reasoning iterations the agent can perform per task.
max_rpm int or None None Rate limit for LLM requests per minute.

Key Behaviors

  • Role as identifier -- In hierarchical mode, the manager agent identifies specialists by their role field. When the manager calls DelegateWorkTool with coworker="Senior Research Analyst", the framework matches this string against each agent's role to find the target specialist.
  • No delegation -- Specialists typically have allow_delegation=False. This prevents them from spawning sub-delegations and keeps the hierarchy flat with the manager as the sole coordinator.
  • Scoped tools -- Each specialist carries only the tools relevant to its domain. The manager does not need these tools directly; it accesses specialist capabilities through delegation.
  • Backstory guidance -- The backstory primes the LLM to respond as a domain expert, producing higher-quality outputs for delegated tasks.

Example

from crewai import Agent
from crewai_tools import SerperDevTool, FileWriterTool

# Specialist 1: Research analyst with search capabilities
research_analyst = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive and accurate information on any given topic",
    backstory=(
        "You are a seasoned research analyst with over 15 years of experience "
        "in data gathering and synthesis. You excel at finding relevant sources, "
        "cross-referencing information, and identifying key insights from large "
        "volumes of data."
    ),
    tools=[SerperDevTool()],
    allow_delegation=False,
    verbose=True,
)

# Specialist 2: Content writer with file writing capabilities
content_writer = Agent(
    role="Expert Content Writer",
    goal="Produce clear, engaging, and well-structured written content",
    backstory=(
        "You are an accomplished content writer with expertise in technical "
        "writing, blog posts, and reports. You transform raw research findings "
        "into polished, readable documents that effectively communicate key "
        "messages to the target audience."
    ),
    tools=[FileWriterTool()],
    allow_delegation=False,
    verbose=True,
)

# Specialist 3: Quality reviewer with no additional tools
quality_reviewer = Agent(
    role="Quality Assurance Reviewer",
    goal="Ensure all content meets high standards of accuracy, clarity, and completeness",
    backstory=(
        "You are a meticulous quality assurance specialist with a keen eye for "
        "detail. You review documents for factual accuracy, logical consistency, "
        "grammatical correctness, and adherence to style guidelines."
    ),
    tools=[],
    allow_delegation=False,
    verbose=True,
)

In this example, three specialist agents are created with distinct roles, goals, backstories, and tool sets. The manager agent (configured separately) will delegate research tasks to the "Senior Research Analyst", writing tasks to the "Expert Content Writer", and review tasks to the "Quality Assurance Reviewer" based on each task's requirements.

Notes

  • The role string matching performed by the delegation tools is case-insensitive and uses fuzzy matching, but clear and distinct role names are strongly recommended to avoid ambiguity.
  • If two specialists have similar role names, the manager may delegate to the wrong one. Ensure role names are unique and descriptive.
  • Specialists do not need to know about each other -- all coordination flows through the manager agent.

Principle:CrewAIInc_CrewAI_Specialist_Agent_Definition

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment