feat: implement hierarchical agent delegation with allowed_agents parameter

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-09 20:02:19 +00:00
parent 409892d65f
commit 74173cc35a
4 changed files with 102 additions and 24 deletions

View File

@@ -124,3 +124,60 @@ def test_ask_question_to_wrong_agent():
result
== "\nError executing tool. coworker mentioned not found, it must be one of the following options:\n- researcher\n"
)
@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_allowed_agents():
executive = Agent(
role="Executive Director",
goal="Lead the team effectively",
backstory="You're an experienced executive",
allow_delegation=True,
allowed_agents=["Communications Manager"]
)
comms_manager = Agent(
role="Communications Manager",
goal="Manage communications",
backstory="You're a communications expert",
allow_delegation=False
)
tools = AgentTools(agents=[executive, comms_manager]).tools()
delegate_tool = tools[0]
result = delegate_tool.run(
coworker="Communications Manager",
task="Handle PR",
context="Important announcement"
)
assert "Error" not in result
@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_unauthorized_agent():
executive = Agent(
role="Executive Director",
goal="Lead the team effectively",
backstory="You're an experienced executive",
allow_delegation=True,
allowed_agents=["Communications Manager"]
)
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 "not authorized to delegate" in result