Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:CrewAIInc CrewAI Manager Agent Setup

From Leeroopedia

Overview

Concrete configuration for creating manager agents with delegation tools, either auto-generated or custom-defined, provided by the CrewAI framework.

Source

Import

from crewai import Crew, Agent, Process

Signature

Crew Fields for Manager Configuration

Parameter Type Default Description
manager_llm str or LLM or None None LLM to use for auto-creating a manager agent. Provide a model string (e.g., "openai/gpt-4o") or an LLM instance.
manager_agent Agent or None None A fully configured Agent instance to serve as the manager. Overrides manager_llm if both are provided.

Auto-Created Manager (_create_manager_agent)

When manager_llm is provided and manager_agent is not, the framework calls the internal _create_manager_agent method which creates an Agent with the following defaults:

Attribute Value
role "Crew Manager"
goal "Manage the team to complete the task in the best way possible."
backstory "You are a seasoned manager with a knack for getting the best out of your team..."
tools [DelegateWorkTool, AskQuestionTool] (auto-assigned)
allow_delegation True (forced)

Custom Manager Agent

When manager_agent is provided, the framework uses that Agent directly but ensures:

  • DelegateWorkTool and AskQuestionTool are added to the agent's tools if not already present.
  • allow_delegation is set to True, overriding any user-specified value.

Key Behaviors

  • Validation at initialization -- The check_manager_llm validator on the Crew class ensures that when process=Process.hierarchical, either manager_agent or manager_llm is provided. If neither is set, a pydantic.ValidationError is raised.
  • Tool injection -- Delegation tools are always injected into the manager, ensuring it can delegate work and ask questions regardless of how it was configured.
  • Delegation enforcement -- The allow_delegation flag is forced to True for the manager, even if the user explicitly sets it to False.

Example

Approach 1: Auto-Created Manager

from crewai import Crew, Agent, Task, Process

# Define specialist agents
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive information on given topics",
    backstory="You are a seasoned research analyst with deep expertise in data gathering.",
    tools=[],
    allow_delegation=False,
)

writer = Agent(
    role="Expert Content Writer",
    goal="Produce clear and engaging written content",
    backstory="You are an accomplished writer who excels at turning research into readable content.",
    tools=[],
    allow_delegation=False,
)

# Define tasks (no agent assignment needed for hierarchical)
research_task = Task(
    description="Research the latest trends in artificial intelligence for 2024.",
    expected_output="A detailed summary of AI trends with sources.",
)

writing_task = Task(
    description="Write a blog post based on the research findings.",
    expected_output="A well-structured 1000-word blog post.",
)

# Create crew with auto-generated manager
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.hierarchical,
    manager_llm="openai/gpt-4o",  # Framework auto-creates the manager agent
    verbose=True,
)

result = crew.kickoff()

Approach 2: Custom Manager Agent

from crewai import Crew, Agent, Task, Process

# Define specialist agents (same as above)
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive information on given topics",
    backstory="You are a seasoned research analyst with deep expertise in data gathering.",
    tools=[],
    allow_delegation=False,
)

writer = Agent(
    role="Expert Content Writer",
    goal="Produce clear and engaging written content",
    backstory="You are an accomplished writer who excels at turning research into readable content.",
    tools=[],
    allow_delegation=False,
)

# Define a custom manager with specific instructions
project_manager = Agent(
    role="Technical Project Manager",
    goal=(
        "Coordinate the research and writing team to produce high-quality content. "
        "Always start with research before writing. Review all outputs for quality."
    ),
    backstory=(
        "You are a technical project manager with 10 years of experience leading "
        "content teams. You understand both the research process and editorial "
        "standards, and you know how to get the best work from your team."
    ),
    allow_delegation=True,
    verbose=True,
)

# Define tasks
research_task = Task(
    description="Research the latest trends in artificial intelligence for 2024.",
    expected_output="A detailed summary of AI trends with sources.",
)

writing_task = Task(
    description="Write a blog post based on the research findings.",
    expected_output="A well-structured 1000-word blog post.",
)

# Create crew with custom manager
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.hierarchical,
    manager_agent=project_manager,  # Custom manager with specific instructions
    verbose=True,
)

result = crew.kickoff()

Notes

  • When using manager_llm, the auto-created manager has a generic personality. For more control over how the manager reasons about delegation, use manager_agent with a detailed backstory.
  • The manager agent is not included in the agents list passed to the Crew. The agents list contains only the specialist workers. The manager is specified separately via manager_agent or manager_llm.
  • If both manager_agent and manager_llm are provided, manager_agent takes precedence and manager_llm is ignored.

Principle:CrewAIInc_CrewAI_Manager_Agent_Configuration

Related Pages

Page Connections

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