mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 23:28:15 +00:00
Fix issue #2434: Allow tools to specify if they permit repeated usage
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -546,6 +546,47 @@ def test_agent_moved_on_after_max_iterations():
|
||||
assert output == "42"
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_agent_repeated_tool_usage_respects_allow_repeated_usage(capsys):
|
||||
@tool
|
||||
def repeatable_tool(anything: str) -> float:
|
||||
"""A tool that allows being used repeatedly with the same input."""
|
||||
return 42
|
||||
|
||||
# Patch the tool to set allow_repeated_usage to True
|
||||
repeatable_tool.allow_repeated_usage = True
|
||||
|
||||
agent = Agent(
|
||||
role="test role",
|
||||
goal="test goal",
|
||||
backstory="test backstory",
|
||||
max_iter=4,
|
||||
llm="gpt-4",
|
||||
allow_delegation=False,
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Use the repeatable tool with the same input multiple times.",
|
||||
expected_output="The result of using the repeatable tool",
|
||||
)
|
||||
|
||||
# force cleaning cache
|
||||
agent.tools_handler.cache = CacheHandler()
|
||||
agent.execute_task(
|
||||
task=task,
|
||||
tools=[repeatable_tool],
|
||||
)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
# Should NOT show the repeated usage error
|
||||
assert (
|
||||
"I tried reusing the same input, I must stop using this action input. I'll try something else instead."
|
||||
not in captured.out
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_agent_respect_the_max_rpm_set(capsys):
|
||||
@tool
|
||||
|
||||
Reference in New Issue
Block a user