refactor: optimize agent lookup and improve error handling

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-09 20:08:45 +00:00
parent 72bc12c536
commit 86b57d9b99
6 changed files with 136 additions and 28 deletions

View File

@@ -126,6 +126,65 @@ def test_ask_question_to_wrong_agent():
)
@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_null_allowed_agents():
"""Test delegation when allowed_agents is None (unrestricted delegation)."""
executive = Agent(
role="Executive Director",
goal="Lead the team effectively",
backstory="You're an experienced executive",
allow_delegation=True,
allowed_agents=None
)
research_manager = Agent(
role="Research Manager",
goal="Manage research",
backstory="You're a research expert",
allow_delegation=False
)
tools = AgentTools(agents=[executive, research_manager]).tools()
delegate_tool = tools[0]
result = delegate_tool.run(
coworker="Research Manager",
task="Handle research",
context="Important research"
)
assert "Error" not in result
@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_empty_allowed_agents():
"""Test delegation when allowed_agents is an empty list (no delegation allowed)."""
executive = Agent(
role="Executive Director",
goal="Lead the team effectively",
backstory="You're an experienced executive",
allow_delegation=True,
allowed_agents=[]
)
research_manager = Agent(
role="Research Manager",
goal="Manage research",
backstory="You're a research expert",
allow_delegation=False
)
tools = AgentTools(agents=[executive, research_manager]).tools()
delegate_tool = tools[0]
result = delegate_tool.run(
coworker="Research Manager",
task="Handle research",
context="Important research"
)
assert "Error" in result
assert "Authorization Error" in result
@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_allowed_agents():
executive = Agent(