Fixing manager_agent_support

This commit is contained in:
João Moura
2024-05-05 00:51:18 -03:00
parent 30438410d6
commit d341cb3d5c
3 changed files with 73 additions and 2836 deletions

View File

@@ -171,14 +171,23 @@ class Crew(BaseModel):
@model_validator(mode="after") @model_validator(mode="after")
def check_manager_llm(self): def check_manager_llm(self):
"""Validates that the language model is set when using hierarchical process.""" """Validates that the language model is set when using hierarchical process."""
if self.process == Process.hierarchical and ( if self.process == Process.hierarchical:
not self.manager_llm and not self.manager_agent if not self.manager_llm and not self.manager_agent:
): raise PydanticCustomError(
raise PydanticCustomError( "missing_manager_llm_or_manager_agent",
"missing_manager_llm_or_manager_agent", "Attribute `manager_llm` or `manager_agent` is required when using hierarchical process.",
"Attribute `manager_llm` or `manager_agent` is required when using hierarchical process.", {},
{}, )
)
if (self.manager_agent is not None) and (
self.agents.count(self.manager_agent) > 0
):
raise PydanticCustomError(
"manager_agent_in_agents",
"Manager agent should not be included in agents list.",
{},
)
return self return self
@model_validator(mode="after") @model_validator(mode="after")
@@ -310,12 +319,13 @@ class Crew(BaseModel):
"""Creates and assigns a manager agent to make sure the crew completes the tasks.""" """Creates and assigns a manager agent to make sure the crew completes the tasks."""
i18n = I18N(prompt_file=self.prompt_file) i18n = I18N(prompt_file=self.prompt_file)
try: if self.manager_agent is not None:
self.manager_agent.allow_delegation = ( self.manager_agent.allow_delegation = True
True # Forcing Allow delegation to the manager
)
manager = self.manager_agent manager = self.manager_agent
except: if len(manager.tools) > 0:
raise Exception("Manager agent should not have tools")
manager.tools = (AgentTools(agents=self.agents).tools(),)
else:
manager = Agent( manager = Agent(
role=i18n.retrieve("hierarchical_manager_agent", "role"), role=i18n.retrieve("hierarchical_manager_agent", "role"),
goal=i18n.retrieve("hierarchical_manager_agent", "goal"), goal=i18n.retrieve("hierarchical_manager_agent", "goal"),

File diff suppressed because it is too large Load Diff

View File

@@ -941,3 +941,53 @@ def test_manager_agent():
crew.kickoff() crew.kickoff()
assert manager.allow_delegation == True assert manager.allow_delegation == True
execute.assert_called() execute.assert_called()
def test_manager_agent_in_agents_raises_exception():
pass
task = Task(
description="Come up with a list of 5 interesting ideas to explore for an article, then write one amazing paragraph highlight for each idea that showcases how good an article about this topic could be. Return the list of ideas with their paragraph and your notes.",
expected_output="5 bullet points with a paragraph for each idea.",
)
manager = Agent(
role="Manager",
goal="Manage the crew and ensure the tasks are completed efficiently.",
backstory="You're an experienced manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
allow_delegation=False,
)
with pytest.raises(pydantic_core._pydantic_core.ValidationError):
crew = Crew(
agents=[researcher, writer, manager],
process=Process.hierarchical,
manager_agent=manager,
tasks=[task],
)
def test_manager_agent_with_tools_raises_exception():
pass
task = Task(
description="Come up with a list of 5 interesting ideas to explore for an article, then write one amazing paragraph highlight for each idea that showcases how good an article about this topic could be. Return the list of ideas with their paragraph and your notes.",
expected_output="5 bullet points with a paragraph for each idea.",
)
manager = Agent(
role="Manager",
goal="Manage the crew and ensure the tasks are completed efficiently.",
backstory="You're an experienced manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
allow_delegation=False,
)
crew = Crew(
agents=[researcher, writer],
process=Process.hierarchical,
manager_agent=manager,
tasks=[task],
)
with pytest.raises(Exception):
crew.kickoff()