Skip to content

Make name and desc optional #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

@dataclass
class SupervisorAgentOptions(AgentOptions):
lead_agent: Agent = None # The agent that leads the team coordination
name: Optional[str] = None # Inherited from lead agent
description: Optional[str] = None # Inherited from lead agent
lead_agent: Agent = None # The agent that leads the team coordination
team: list[Agent] = field(default_factory=list) # a team of agents that can help in resolving tasks
storage: Optional[ChatStorage] = None # memory storage for the team
trace: Optional[bool] = None # enable tracing/logging
Expand Down Expand Up @@ -284,4 +286,4 @@ async def process_request(

except Exception as e:
Logger.error(f"Error in process_request: {e}")
raise e
raise e
116 changes: 40 additions & 76 deletions python/src/tests/agents/test_supervisor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def supervisor_agent(mock_boto3_client):
description="Test team member"
))

return SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[team_member],
storage=mock_storage(),
trace=True
))
return SupervisorAgent(
SupervisorAgentOptions(
lead_agent=lead_agent,
team=[team_member],
storage=mock_storage(),
trace=True,
)
)

@pytest.mark.asyncio
async def test_supervisor_agent_initialization(mock_boto3_client):
Expand All @@ -89,12 +89,7 @@ async def test_supervisor_agent_initialization(mock_boto3_client):
description="Test team member"
))]

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=team
))
agent = SupervisorAgent(SupervisorAgentOptions(lead_agent=lead_agent, team=team))

assert agent.lead_agent == lead_agent
assert len(agent.team) == 1
Expand All @@ -106,12 +101,9 @@ async def test_supervisor_agent_initialization(mock_boto3_client):
async def test_supervisor_agent_validation(mock_boto3_client):
"""Test SupervisorAgent validation"""
with pytest.raises(ValueError, match="Supervisor must be BedrockLLMAgent or AnthropicAgent"):
SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=MagicMock(spec=Agent),
team=[]
))
SupervisorAgent(
SupervisorAgentOptions(lead_agent=MagicMock(spec=Agent), team=[])
)

lead_agent = MockBedrockLLMAgent(BedrockLLMAgentOptions(
name="Supervisor",
Expand All @@ -120,12 +112,7 @@ async def test_supervisor_agent_validation(mock_boto3_client):
lead_agent.tool_config = {'tool':{}}

with pytest.raises(ValueError, match="Supervisor tools are managed by SupervisorAgent"):
SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[]
))
SupervisorAgent(SupervisorAgentOptions(lead_agent=lead_agent, team=[]))

def test_send_message(supervisor_agent, mock_boto3_client):
"""Test send_message functionality"""
Expand Down Expand Up @@ -221,13 +208,11 @@ def mock_tool_function(*args, **kwargs):
description="Test lead_agent"
))

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[],
extra_tools=[custom_tool]
))
agent = SupervisorAgent(
SupervisorAgentOptions(
lead_agent=lead_agent, team=[], extra_tools=[custom_tool]
)
)

assert len(agent.supervisor_tools.tools) > 1
assert any(tool.name == "test_tool" for tool in agent.supervisor_tools.tools)
Expand Down Expand Up @@ -256,13 +241,11 @@ def mock_tool_function(*args, **kwargs):
description="Test lead_agent"
))

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[],
extra_tools=AgentTools(tools=[custom_tool])
))
agent = SupervisorAgent(
SupervisorAgentOptions(
lead_agent=lead_agent, team=[], extra_tools=AgentTools(tools=[custom_tool])
)
)

assert len(agent.supervisor_tools.tools) > 1
assert any(tool.name == "test_tool" for tool in agent.supervisor_tools.tools)
Expand All @@ -276,26 +259,21 @@ async def test_supervisor_agent_with_extra_tools(mock_boto3_client):
description="Test lead_agent"
))


with pytest.raises(Exception, match="extra_tools must be Tools object or list of Tool objects"):
agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[],
extra_tools=[{'tool':'here is my tool'}]
))
agent = SupervisorAgent(
SupervisorAgentOptions(
lead_agent=lead_agent,
team=[],
extra_tools=[{"tool": "here is my tool"}],
)
)

with pytest.raises(Exception, match="extra_tools must be Tools object or list of Tool objects"):
agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[],
extra_tools="here is my tool"
))


agent = SupervisorAgent(
SupervisorAgentOptions(
lead_agent=lead_agent, team=[], extra_tools="here is my tool"
)
)


@pytest.mark.asyncio
Expand All @@ -310,12 +288,7 @@ async def process_request(self, *args, **kwargs):
description="Test failing lead_agent"
))

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[]
))
agent = SupervisorAgent(SupervisorAgentOptions(lead_agent=lead_agent, team=[]))

with pytest.raises(Exception, match="Test error"):
await agent.process_request(
Expand Down Expand Up @@ -343,12 +316,7 @@ async def process_request(self, *args, **kwargs):
description="Test lead_agent"
))

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=team
))
agent = SupervisorAgent(SupervisorAgentOptions(lead_agent=lead_agent, team=team))

messages = [
{"recipient": f"Agent{i}", "content": f"Test message {i}"}
Expand All @@ -371,13 +339,9 @@ async def test_supervisor_agent_memory_management(mock_boto3_client):
description="Test lead_agent"
))

agent = SupervisorAgent(SupervisorAgentOptions(
name="SupervisorAgent",
description="My Supervisor agent description",
lead_agent=lead_agent,
team=[],
storage=mock_storage()
))
agent = SupervisorAgent(
SupervisorAgentOptions(lead_agent=lead_agent, team=[], storage=mock_storage())
)

# Test message storage
user_id = "test_user"
Expand Down