mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
* Improving tool calling to pass dictionaries instead of strings * Fix issues with parsing none/null * remove prints and unnecessary comments * Fix crew_test issues with function calling * improve prompting * add back in support for add_image * add tests for tool validation * revert back to figure out why tests are timing out * Update cassette * trying to find what is timing out * add back in guardrails * add back in manager delegation tests * Trying to fix tests * Force test to pass * Trying to fix tests * add in more role tests * add back old tool validation * updating tests * vcr * Fix tests * improve function llm logic * vcr 2 * drop llm * Failing test * add more tests back in * Revert tool validation
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import pytest
|
|
|
|
from crewai import Agent
|
|
from crewai.tools.agent_tools.base_agent_tools import BaseAgentTool
|
|
|
|
|
|
class InternalAgentTool(BaseAgentTool):
|
|
"""Concrete implementation of BaseAgentTool for testing."""
|
|
|
|
def _run(self, *args, **kwargs):
|
|
"""Implement required _run method."""
|
|
return "Test response"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"role_name,should_match",
|
|
[
|
|
("Futel Official Infopoint", True), # exact match
|
|
(' "Futel Official Infopoint" ', True), # extra quotes and spaces
|
|
("Futel Official Infopoint\n", True), # trailing newline
|
|
('"Futel Official Infopoint"', True), # embedded quotes
|
|
(" FUTEL\nOFFICIAL INFOPOINT ", True), # multiple whitespace and newline
|
|
],
|
|
)
|
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
|
def test_agent_tool_role_matching(role_name, should_match):
|
|
"""Test that agent tools can match roles regardless of case, whitespace, and special characters."""
|
|
# Create test agent
|
|
test_agent = Agent(
|
|
role="Futel Official Infopoint",
|
|
goal="Answer questions about Futel",
|
|
backstory="Futel Football Club info",
|
|
allow_delegation=False,
|
|
)
|
|
|
|
# Create test agent tool
|
|
agent_tool = InternalAgentTool(
|
|
name="test_tool", description="Test tool", agents=[test_agent]
|
|
)
|
|
|
|
# Test role matching
|
|
result = agent_tool._execute(agent_name=role_name, task="Test task", context=None)
|
|
|
|
if should_match:
|
|
assert (
|
|
"coworker mentioned not found" not in result.lower()
|
|
), f"Should find agent with role name: {role_name}"
|
|
else:
|
|
assert (
|
|
"coworker mentioned not found" in result.lower()
|
|
), f"Should not find agent with role name: {role_name}"
|