crewai - ✅(Solved) Fix [BUG] Hierarchical process delegation fails - manager agents cannot delegate to worker agents [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
crewAIInc/crewAI#4783Fetched 2026-04-08 00:40:22
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
referenced ×3commented ×2cross-referenced ×2labeled ×1

In CrewAI's hierarchical process, manager agents are unable to delegate tasks to worker agents, even when allow_delegation=True is set. This breaks the core functionality of hierarchical task coordination.

Error Message

except Exception as e: print(f"Error occurred: {e}") import traceback traceback.print_exc()

Root Cause

In CrewAI's hierarchical process, manager agents are unable to delegate tasks to worker agents, even when allow_delegation=True is set. This breaks the core functionality of hierarchical task coordination.

Fix Action

Fixed

PR fix notes

PR #4784: fix: hierarchical process delegation targets other agents instead of self (#4783)

Description (problem / solution / changelog)

Summary

Fixes a bug in Crew._update_manager_tools() where, in hierarchical process mode, delegation tools for a task with an assigned agent were configured to only allow delegation back to that same agent ([task.agent]), making delegation circular and ineffective.

The one-line fix changes the delegation target from [task.agent] to all other agents in the crew (excluding the assigned agent):

# Before (broken): agent can only "delegate" to itself
tools = self._inject_delegation_tools(tools, task.agent, [task.agent])

# After (fixed): agent can delegate to all OTHER crew members
other_agents = [agent for agent in self.agents if agent != task.agent]
tools = self._inject_delegation_tools(tools, task.agent, other_agents)

The else branch (task with no assigned agent) was already correct and is unchanged.

Fixes #4783

Review & Testing Checklist for Human

  • Verify the core logic change: Confirm that excluding task.agent from delegation targets is the correct behavior. The old code passed [task.agent] which meant the agent could only delegate to itself — clearly a bug, but verify the fix aligns with intended hierarchical delegation semantics.
  • Edge case — single agent crew: When task.agent is the only agent in self.agents, other_agents will be an empty list. Verify this is handled gracefully by _inject_delegation_tools (no delegation tools injected, which seems correct).
  • Updated existing test assertions: Two existing tests (test_manager_agent_delegating_to_assigned_task_agent and test_manager_agent_delegates_with_varied_role_cases) had their assertions changed from checking for the assigned agent's role to checking for the OTHER agent's role. Verify these assertions are correct.
  • End-to-end validation: The tests mock execute_sync so they validate tool injection but not actual delegation behavior at runtime. Consider running a real hierarchical crew to verify delegation works end-to-end.

Notes

<!-- CURSOR_SUMMARY -->

[!NOTE] Medium Risk Changes hierarchical delegation tool injection, which can alter how manager/agents route work across a crew and may impact existing workflows (including single-agent crews where the target list becomes empty). Coverage is improved with updated and new tests validating the new targeting behavior.

Overview Fixes hierarchical-mode delegation so when a task has an assigned agent, the injected delegation tools target all other crew agents (excluding the assigned agent) rather than creating a self-delegation loop.

Updates existing delegation tests to assert the new behavior and adds focused unit tests covering exclusion of the assigned agent, multi-task crews, and the no-assigned-agent case delegating to all agents.

<sup>Written by Cursor Bugbot for commit 9ba1ec03a86e7898dff52f2d905af3fa05779902. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/crew.py (modified, +2/-1)
  • lib/crewai/tests/test_crew.py (modified, +194/-13)
RAW_BUFFERClick to expand / collapse

Description

Description

In CrewAI's hierarchical process, manager agents are unable to delegate tasks to worker agents, even when allow_delegation=True is set. This breaks the core functionality of hierarchical task coordination.

Expected Behavior

In hierarchical process:

  1. Manager agent should analyze tasks and delegate subtasks to appropriate worker agents
  2. Worker agents should execute delegated tasks
  3. Manager should coordinate and combine results

Actual Behavior

Manager agents only execute tasks using their own tools and never delegate to other agents, effectively making the hierarchical process behave like a sequential process.

Steps to Reproduce

  1. Create a Crew with hierarchical process: from crewai import Crew, Process, Agent, Task

Create worker agents

worker1 = Agent( role="Data Analyst", goal="Analyze data and provide insights", tools=[some_data_analysis_tool], allow_delegation=False )

worker2 = Agent( role="Report Writer", goal="Write reports based on analysis", tools=[some_writing_tool], allow_delegation=False )

Create manager agent (no pre-defined manager agent)

manager_llm = some_llm_instance

Create crew

crew = Crew( agents=[worker1, worker2], tasks=[complex_analysis_task], process=Process.hierarchical, # This should enable delegation manager_llm=manager_llm, verbose=True )

Execute

result = crew.kickoff()

Steps to Reproduce

Steps to Reproduce

Step 1: Set up a simple test environment

Create a new Python file test_delegation_bug.py:

#!/usr/bin/env python3 """ Test script to reproduce CrewAI hierarchical delegation bug """

from crewai import Crew, Process, Agent, Task, LLM

def test_delegation_bug(): """Reproduce the delegation bug in hierarchical process"""

# Create a simple mock LLM for testing (replace with your actual LLM)
llm = LLM(model="gpt-4", temperature=0.1)  # Adjust based on your setup

# Step 2: Create worker agents with specialized tools
researcher = Agent(
    role="Research Specialist",
    goal="Conduct research and gather information",
    backstory="You are an expert researcher who can find and analyze information.",
    tools=[],  # No special tools for this test
    allow_delegation=False,  # Worker agents shouldn't delegate
    verbose=True,
    llm=llm
)

writer = Agent(
    role="Content Writer",
    goal="Write clear and engaging content based on research",
    backstory="You are a skilled writer who creates compelling content.",
    tools=[],  # No special tools for this test
    allow_delegation=False,  # Worker agents shouldn't delegate
    verbose=True,
    llm=llm
)

# Step 3: Create a complex task that should be delegated
research_task = Task(
    description="""
    Create a comprehensive article about artificial intelligence trends in 2024.
    
    This task requires:
    1. Research current AI trends and technologies
    2. Analyze market impacts and future predictions  
    3. Write a well-structured article
    
    Delegate the research work to the Research Specialist and writing to the Content Writer.
    """,
    expected_output="A complete article about AI trends in 2024",
    agent=None  # No specific agent assigned - should go to manager
)

# Step 4: Create crew with hierarchical process (THIS IS WHERE THE BUG OCCURS)
crew = Crew(
    agents=[researcher, writer],  # Only worker agents
    tasks=[research_task],
    process=Process.hierarchical,  # Manager should coordinate
    manager_llm=llm,  # Manager LLM provided, no pre-defined manager_agent
    verbose=True
)

print("=== CrewAI Hierarchical Delegation Test ===")
print(f"Process: {crew.process}")
print(f"Number of agents: {len(crew.agents)}")
print(f"Manager agent: {crew.manager_agent}")  # Should be None initially
print()

# Step 5: Execute and observe the bug
print("Executing crew.kickoff()...")
print("Expected: Manager delegates research to researcher, writing to writer")
print("Actual bug: Manager does all work itself, no delegation occurs")
print("-" * 60)

try:
    result = crew.kickoff()
    print(f"\nResult: {result}")
    
    # Check if delegation actually occurred
    print(f"\nDelegation tracking:")
    print(f"Manager agent after execution: {crew.manager_agent}")
    if hasattr(crew.manager_agent, 'tools'):
        print(f"Manager tools count: {len(crew.manager_agent.tools or [])}")
    
except Exception as e:
    print(f"Error occurred: {e}")
    import traceback
    traceback.print_exc()

if name == "main": test_delegation_bug()

Expected behavior

Expected behavior

When using CrewAI's hierarchical process with dynamically created manager agents, the manager should be able to properly delegate tasks to worker agents instead of performing all work itself.

Specific Expected Behaviors:

  1. Successful Delegation:

    • Manager agent calls "Delegate work to coworker" tool
    • Tool successfully finds and delegates to worker agents
    • No "No agent found" errors for valid coworkers
  2. Parallel Task Execution:

  • Manager Agent → Delegates to Worker A → Worker A executes
  • → Delegates to Worker B → Worker B executes
  • → Coordinates results
  1. Proper Tool Configuration:

    • Delegation tools should target other agents in the crew
    • Manager should not attempt to delegate to itself
    • Worker agents should receive delegated tasks
  2. Observable Results:

    • task.delegations counter should be > 0
    • Worker agents should show execution logs
    • Manager should coordinate rather than execute all subtasks
    • Tasks should complete through proper delegation chain

Example Expected Console Output:

[Manager Agent] Analyzing: "Create article about AI trends" [Manager Agent] Delegating research task to Research Specialist... [Research Specialist] Executing research on AI trends... [Manager Agent] Delegating writing task to Content Writer... [Content Writer] Writing article based on research... [Manager Agent] Coordinating final article... ✅ Task completed with proper delegation

Screenshots/Code snippets

Fixed Code (proposed): def _update_manager_tools( self, task: Task, tools: list[BaseTool] ) -> list[BaseTool]: if self.manager_agent: if task.agent: # FIX: Allow delegation to other agents (excluding self) other_agents = [agent for agent in self.agents if agent != task.agent] tools = self._inject_delegation_tools(tools, task.agent, other_agents) else: tools = self._inject_delegation_tools( tools, self.manager_agent, self.agents ) return tools

=== CrewAI Hierarchical Delegation Test === Process: Process.hierarchical Number of agents: 2 Manager agent: None

Executing crew.kickoff()... Expected: Manager delegates research to researcher, writing to writer Actual bug: Manager does all work itself, no delegation occurs

[Manager Agent] Starting task execution... [Manager Agent] Using tool: some_analysis_tool (manager doing research itself) [Manager Agent] Using tool: some_writing_tool (manager doing writing itself) [Manager Agent] Task completed - no delegation occurred!

Delegation tracking: Manager agent after execution: <Agent role='Manager' ...> Manager tools count: 2 # Has delegation tools but they don't work

Operating System

macOS Ventura

Python Version

3.10

crewAI Version

1.10.1

crewAI Tools Version

CrewAI Tools: Not installed / Not used

Virtual Environment

Venv

Evidence

Evidence

1. Debug Logs Showing the Bug

Console output from test script (run the reproduction script):

Possible Solution

https://github.com/crewAIInc/crewAI/pull/4782

<img width="896" height="218" alt="Image" src="https://github.com/user-attachments/assets/eadcb3bd-a374-4967-8335-c44ab0013e85" />

Additional context

None

extent analysis

Fix Plan

To fix the delegation issue in CrewAI's hierarchical process, we need to modify the _update_manager_tools method. The proposed fix involves allowing delegation to other agents (excluding self) when the task agent is specified or when the manager agent is executing the task.

Step-by-Step Solution:

  1. Update the _update_manager_tools method:

def _update_manager_tools( self, task: Task, tools: list[BaseTool] ) -> list[BaseTool]: if self.manager_agent: if task.agent: # Allow delegation to other agents (excluding self) other_agents = [agent for agent in self.agents if agent != task.agent] tools = self._inject_delegation_tools(tools, task.agent, other_agents) else: tools = self._inject_delegation_tools( tools, self.manager_agent, self.agents ) return tools

2. **Verify the fix** by running the test script `test_delegation_bug.py` and observing the console output for successful delegation and parallel task execution.

### Verification
To verify that the fix worked, check the following:
* The `task.delegations` counter should be greater than 0.
* Worker agents should show execution logs.
* The manager should coordinate rather than execute all subtasks.
* Tasks should complete through the proper delegation chain.

### Extra Tips
* Ensure that the `allow_delegation` flag is set to `True` for the manager agent.
* Verify that the delegation tools are correctly configured to target other agents in the crew.
* Test the fix with different task scenarios to ensure that delegation works as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When using CrewAI's hierarchical process with dynamically created manager agents, the manager should be able to properly delegate tasks to worker agents instead of performing all work itself.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING