Fix hierarchical delegation with language-agnostic tool matching #3926
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.
Fix hierarchical delegation with language-agnostic tool matching (Issue #3925)
Summary
Fixes issue #3925 where the hierarchical process behaves differently depending on the language used. When using non-English prompts, the manager agent would repeatedly delegate to itself instead of using specialized coworkers because tool names were hardcoded in English.
Root Cause: Tool name matching relied on exact English strings ("Delegate work to coworker", "Ask question to coworker"), which failed when LLMs generated tool calls in other languages or used variations of the names.
Solution: Added language-agnostic tool matching using stable short identifiers:
delegate_work/delegate_work_to_coworker→ "Delegate work to coworker"ask_question/ask_question_to_coworker→ "Ask question to coworker"Changes:
Tool Selection (
tool_usage.py): Added_normalize_tool_name(),_get_tool_aliases(), and enhanced_select_tool()to support:Delegation Detection (
tool_usage.py): Updated delegation counting logic to recognize short identifiers in addition to English namesMemory Filter (
base_agent_executor_mixin.py): Updated short-term memory filter to exclude delegation actions using both English names and short identifiersTests (
test_tool_usage.py): Added 7 unit tests covering normalization, alias generation, tool selection with various inputs, and memory filteringReview & Testing Checklist for Human
_create_short_term_memory()to ensure they're not too broad (could exclude legitimate actions from memory) or too narrow (could include delegation actions in memory).Recommended Test Plan
Notes
Link to Devin run: https://app.devin.ai/sessions/8edde7b0966342a09a28a2c9bb976301
Requested by: João (joao@crewai.com)