Add allow_repeated_usage flag for stateful tools #4233
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.
Add a new
allow_repeated_usageflag to BaseTool and CrewStructuredTool that allows tools to bypass the repeated usage check. This is essential for stateful tools like browser automation (e.g., Playwright MCP), where calling the same tool with the same arguments can produce different results due to external state changes. Currently, using the Playwright MCP tool with an agent does not work properly.The repeated usage check was blocking consecutive calls to tools like
browser_snapshotwith the same (empty) arguments, even though the browser state had changed between calls. This made browser automation with MCP servers unusable.Changes:
allow_repeated_usage: bool = Falsefield to BaseToolallow_repeated_usageparameter to CrewStructuredToolto_structured_tool()to copy the flag_check_tool_repeated_usage()to check for the flagUsage:
Fixes: Browser automation with MCP servers not working due to repeated usage check blocking consecutive tool calls.
Note: For MCP adapters to work, a follow-up change to
mcpadaptis necessary, too. I have a fix ready, and can submit the PR as soon as this isNote
Enables stateful tools (e.g., browser automation) to be invoked consecutively with identical arguments when explicitly allowed.
allow_repeated_usage: booltoBaseToolandCrewStructuredTool(defaultFalse)BaseTool.to_structured_tool()andCrewStructuredToolconstructorToolUsage._useandToolUsage._auseto pass the tool into_check_tool_repeated_usage()_check_tool_repeated_usage()to skip the block whentool.allow_repeated_usageis TrueWritten by Cursor Bugbot for commit c8d3c78. This will update automatically on new commits. Configure here.