fix: wire _extract_tool_name into codebase and add regression tests for #5244#5245
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
fix: wire _extract_tool_name into codebase and add regression tests for #5244#5245devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
#5244 - Add _resolve_original_tool() to centralize tool lookup via _tool_name_mapping - Refactor _should_parallelize_native_tool_calls() to use _extract_tool_name() - Refactor _execute_single_native_tool_call() to use _resolve_original_tool() - Add 20 regression tests covering: - Tool name extraction (OpenAI, Gemini, Anthropic, dict formats) - Tool name collision resolution with _tool_name_mapping - _resolve_original_tool() with mapping, fallback, and unknown tools - Error handling with collision-renamed tools - result_as_answer and max_usage_count with renamed tools - _should_parallelize_native_tool_calls integration with _extract_tool_name Closes #5244 Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Addresses Cursor Bugbot feedback: the string 'unknown' could collide with a tool legitimately named 'unknown'. Now _extract_tool_name returns None for unrecognised formats, and _should_parallelize checks 'is None' instead of '== "unknown"'. Co-Authored-By: João <joao@crewai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Addresses issue #5244 by ensuring
_extract_tool_name()andcheck_native_todo_completion()(restored in #5243) cannot be silently removed as "dead code" again. The key changes:Production code (
agent_executor.py):_resolve_original_tool()method — centralizes the duplicated tool-lookup logic (check_tool_name_mappingfirst, fall back to scanningoriginal_tools) that was previously copy-pasted in two places._should_parallelize_native_tool_calls()now routes through_extract_tool_name()instead of the standaloneextract_tool_call_info(). This is the critical wiring that makes_extract_tool_namea live call site rather than dead code._execute_single_native_tool_call()now calls_resolve_original_tool()instead of repeating the 10-line inline lookup, reducing duplication.Tests (
test_agent_executor.py): 20 new regression tests across 5 classes:TestExtractToolName— all provider formats (OpenAI, Gemini, Anthropic, dict, unknown)TestToolNameCollisionResolution—convert_tools_to_openai_schemadeduplicationTestResolveOriginalTool— mapping lookup, fallback, collision-renamed, unknownTestToolErrorHandlingRegression— error injection,result_as_answer,max_usage_countwith renamed toolsTestShouldParallelizeUsesExtractToolName— verifies_extract_tool_nameis called andresult_as_answerblocks parallelizationReview & Testing Checklist for Human
_should_parallelizerefactor: the old code usedextract_tool_call_info()which returns(id, name, args)orNone; the new code uses_extract_tool_name()which returns the name or"unknown". Verify these are equivalent for the parallelization decision (only the name was used before)._resolve_original_tooledge cases: usesgetattr(self, "_tool_name_mapping", None)defensively. Confirm this is safe across all code paths where the method might be called before_setup_native_tools()populates the mapping.result_as_answer/max_usage_countwork on the renamed variants.Notes
uv.lockonmainhas a parse error (missingversionfield at line 1126); this is a pre-existing issue unrelated to this PR. Tests were run after regenerating the lock locally.Link to Devin session: https://app.devin.ai/sessions/99afc2d07f9743aebb44a9c547f8db25
Note
Medium Risk
Touches native tool execution/parallelization decisions and tool lookup, which can affect runtime behavior for function-calling providers and collision-renamed tools; mitigated by extensive new regression tests.
Overview
Fixes native tool-call handling to avoid tool-name collisions and "unknown" name ambiguity by adding
_resolve_original_tool()(centralized lookup via_tool_name_mappingwith fallback), wiring_should_parallelize_native_tool_calls()through_extract_tool_name(), and updating_extract_tool_name()to returnNonefor unrecognized formats.Adds a large regression test suite covering tool-name extraction across provider formats, collision deduplication in
convert_tools_to_openai_schema, original-tool resolution, native-tool error handling/usage limits/result-as-answer with collision-renamed tools, and ensuring parallelization logic calls_extract_tool_name().Written by Cursor Bugbot for commit e40b29b. This will update automatically on new commits. Configure here.