How to do the second order or more using Crew AI agents? #6275
Replies: 1 comment
-
To implement a hierarchical structure with Crew AI agents, including multiple levels such as a director agent at the top, manager agents in the middle, and employee agents at the second level and beyond, you can use the Here's a brief outline of how you can set this up:
Here's a code snippet to illustrate the setup: from langflow.components.crewai.crewai import CrewAIAgentComponent
from langflow.components.crewai.hierarchical_crew import HierarchicalCrewComponent
from langflow.components.crewai.hierarchical_task import HierarchicalTaskComponent
from langflow.components.inputs import ChatInput
from langflow.components.models import OpenAIModelComponent
from langflow.components.prompts import PromptComponent
# Define language models
llm = OpenAIModelComponent(model_name="gpt-4o-mini")
manager_llm = OpenAIModelComponent(model_name="gpt-4o")
# Define prompts for role, goal, and backstory
role_prompt = PromptComponent(_display_name="Role Prompt")
role_prompt.set(template="Define a Role that could execute or answer well the user's query.")
goal_prompt = PromptComponent(_display_name="Goal Prompt")
goal_prompt.set(template="Define the Goal of this Role, given the User's Query.")
backstory_prompt = PromptComponent(_display_name="Backstory Prompt")
backstory_prompt.set(template="Define a Backstory of this Role and Goal, given the User's Query.")
# Define dynamic agent
dynamic_agent = CrewAIAgentComponent()
dynamic_agent.set(
llm=llm.build_model,
role=role_prompt.build_prompt,
goal=goal_prompt.build_prompt,
backstory=backstory_prompt.build_prompt,
)
# Define manager agent
manager_agent = CrewAIAgentComponent()
manager_agent.set(
llm=manager_llm.build_model,
role="Manager",
goal="You can answer general questions from the User and may call others for help if needed.",
backstory="You are polite and helpful. You've always been a beacon of politeness.",
)
# Define task
task = HierarchicalTaskComponent()
task.set(
task_description="Respond to the user's query with as much information as possible.",
expected_output="Succinct response that answers the User's query.",
)
# Build hierarchical crew
crew_component = HierarchicalCrewComponent()
crew_component.set(
tasks=task.build_task,
agents=[dynamic_agent.build_output],
manager_agent=manager_agent.build_output
)
# Example usage
crew = crew_component.build_crew() This setup will allow you to create a hierarchical structure where the director agent can oversee manager agents, who in turn manage employee agents. Adjust the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
I tried to do the Hierarchical crew like the director agent at the top level, manager agents at the middle , employee agents at the second level and so on. Right now, i can only do till the middle but cant do second level and so on. Does anybody know how to do that?
Beta Was this translation helpful? Give feedback.
All reactions