fix: ensure task-bound tools propagate in hierarchical mode #4178
+4
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When kicking off a crew run in hierarchical mode, any MCP tools owned by agents are ignored even if they are required for successful task completion. The cause is simple: in hierarchical mode, the agent_to_use for prepare_tools is always the manager agent.
From
prepare_task_executionin utils.py:Effectively, this function is checking the manager agent against tasks assigned to subordinate agents to see if any tools should be made available for the upcoming agent activation. As a result, subordinate agents never have the necessary tools for task execution in hierarchical mode.
Fix:
In the
_prepare_toolsfunction in crew.py, check to see if there is an agent assigned to the task:Then, when preparing mcp and platform tools, use that task's agent instead of the manager agent to retrieve the relevant tools for the activation:
Note
Fixes tool resolution in hierarchical mode by selecting the task’s agent when preparing tools.
Crew._prepare_tools, introducetask_agent = task.agent or agentand use it to addplatformandmcptools via_add_platform_toolsand_add_mcp_toolsWritten by Cursor Bugbot for commit 1c245af. This will update automatically on new commits. Configure here.