fix(tools): prevent duplicate tool invocation on failure (#7449) - #7452
VimalN2005 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe synchronous and asynchronous tool usage paths now catch errors only while filtering arguments. Tool invocation failures propagate to the existing outer retry handling. New tests verify two invocations when the maximum attempts value is two. ChangesTool invocation retry handling
Sequence Diagram(s)sequenceDiagram
participant ToolUsage
participant CrewStructuredTool
participant OuterRetryLogic
ToolUsage->>CrewStructuredTool: invoke or ainvoke
CrewStructuredTool-->>OuterRetryLogic: invocation failure
OuterRetryLogic->>CrewStructuredTool: retry on next configured attempt
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The retry behavior now limits failing tools to one invocation per configured attempt in both execution modes, preventing the duplicate side effects addressed by this change. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Related issue
Fixes #7449
Summary
In
ToolUsage._useand_ause,tool.invoke(...)andtool.ainvoke(...)were executed inside the innertry...exceptblock intended solely for filteringcalling.argumentsagainsttool.args_schema.When a tool raised a runtime exception during invocation, the inner
except Exception:caught it and re-invokedtool.invoke()a second time with unfiltered arguments within the same outer attempt. This caused every failure to invoke the tool twice per attempt (up to 6 times under default_max_parsing_attempts=3).Solution
tool.invoke()andawait tool.ainvoke()outside the inner arguments schema filteringtry...exceptblock in both_useand_ause.try...exceptfallback tocalling.arguments.Verification
Tests added or updated for the changed behavior
Relevant tests and quality checks pass locally
Added
test_tool_usage_does_not_double_invoke_on_failureandtest_async_tool_usage_does_not_double_invoke_on_failureinlib/crewai/tests/tools/test_tool_usage.py.Ran
pytest lib/crewai/tests/tools/test_tool_usage.py(30 passed).Verified
mypytype check passes onlib/crewai/src/crewai/tools/tool_usage.py.Formatted with
ruff.Additional context
This PR was authored with AI assistance and should receive the
llm-generatedlabel per CONTRIBUTING.md.