Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Fix hierarchical delegation bug where manager couldn't delegate to all crew agents (#3887)

Summary

Fixes a bug in hierarchical process where the manager agent's delegation tools were incorrectly limited to only the task's assigned agent instead of all crew agents. This caused delegation errors when the manager tried to delegate to other agents in the crew.

The Fix: Changed one line in crew.py (_update_manager_tools method) to pass self.agents instead of [task.agent] when injecting delegation tools for hierarchical crews with assigned tasks.

Changes:

  • lib/crewai/src/crewai/crew.py: Updated line 1125 to pass all crew agents to delegation tools
  • lib/crewai/tests/test_crew.py: Added 2 comprehensive tests reproducing the bug scenario and updated 1 existing test to reflect correct behavior
  • lib/crewai/tests/cassettes/*.yaml: Updated VCR cassette from test run

Review & Testing Checklist for Human

This is a YELLOW RISK change - small code change but affects core delegation logic.

  • CRITICAL: Test with a real hierarchical crew setup matching issue [BUG] #3887 scenario (custom manager_agent with tasks assigned to it, trying to delegate to crew agents). Verify the manager can now successfully delegate to all crew agents, not just the task's assigned agent.
  • Verify this doesn't break any existing hierarchical crew workflows in production or examples. The behavior change is: manager can now delegate to ALL crew agents instead of just the task's assigned agent.
  • Review the VCR cassette update in test_hierarchical_crew_creation_tasks_with_async_execution.yaml - it's a new HTTP interaction recording from my test run. Ensure it looks legitimate (it's a tracing API call).

Test Plan Recommendation

  1. Create a hierarchical crew with:
    • Custom manager_agent (e.g., "Coordinator")
    • Multiple agents in crew.agents list (e.g., ["Planner", "Developer"])
    • Task assigned to the manager agent
  2. In the task execution, have the manager try to delegate to one of the crew agents
  3. Before fix: Would get error "coworker mentioned not found, it must be one of the following options: - coordinator"
  4. After fix: Should successfully delegate to any crew agent

Notes

…l crew agents

Fixes #3887

In hierarchical process, when a task was assigned to a specific agent,
the manager's delegation tools were only given access to that task's
assigned agent instead of all crew agents. This caused delegation
errors when trying to delegate to other agents in the crew.

Changes:
- Updated _update_manager_tools in crew.py to pass self.agents instead
  of [task.agent] to _inject_delegation_tools
- Added comprehensive tests reproducing the bug scenario
- Updated existing test to reflect correct behavior where manager can
  delegate to all crew agents

The fix ensures that in hierarchical mode, the manager agent can
delegate to any agent in the crew's agents list, not just the task's
assigned agent.

Co-Authored-By: João <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant