joaomdmoura / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
16.96k stars 2.29k forks source link

[Query] Multi-agent with human in loop at every step #853

Open arunbaby0 opened 4 days ago

arunbaby0 commented 4 days ago

I am trying to create a hierarchical crew with 3 agents for chatbot, the main agent should route the interaction of the human to the other 2 agents based on the human inputs (chat messages). Also, the other 2 agents should take human input at each step of the process to find out what the human wants.

front = Agent(
    role='Front Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

second = Agent(
    role='Second Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

third = Agent(
    role='Third Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

front_task = Task(
    description=(
        "Interact with the customer to determine if their request"
    ),
    expected_output=(
        "A decision on whether the customer's request is for first agent or second,"
        "and delegation to the respective agent."
    ),
    agent=front,
    human_input_required=True,
    human_input_instructions="..."
)

second_task = Task(
    description=(
        "Ask the customer relevant questions to understand their"
    ),
    expected_output=(
        "A detailed list of the customer's requirements and preferences"
    ),
    agent=second,
    human_input_required=True,
    human_input_instructions="..."
)

third_task = Task(
    description=(
        "Ask the customer relevant questions to understand"
    ),
    expected_output=(
        "A detailed list of the customer's service requirements"
    ),
    agent=third,
    human_input_required=True,
    human_input_instructions="..."
)

# Create Crew
my_crew = Crew(
    agents=[front, second, third],
    tasks=[front_task, second_task, third_task],
    process=Process.sequential,
    human_input=True
)

# Kick off the crew with a sample input
result = my_crew.kickoff()
print(result)

In this, the agent is not stopping to get any inputs from the user. What I am missing here?

theCyberTech commented 3 days ago

3 immediate issues Im seeing.

  1. You say you are trying to create a hierarchical crew but you have configured the crew process as sequential
  2. You are using the following parameters in your tasks: human_input_required human_input_instructions

These are not valid parameters for the task class, you need human_input= True

  1. You are defining human_input=True on your crew instance, this is not correct and should only be on your tasks, see the docs - https://docs.crewai.com/how-to/Human-Input-on-Execution/
arunbaby0 commented 3 days ago

Thanks for the quick response, @theCyberTech. However, I am still facing issues. PFB the changed code. I want the front agent to ask the human to select either second or third agent. And for second and third agent also, I want human interaction to finally decide what the human wants. And at every step I am expecting the human input.

front = Agent(
    role='Front Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

second = Agent(
    role='Second Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

third = Agent(
    role='Third Agent',
    goal='...',
    verbose=True,
    memory=True,
    backstory=(
        "..."
    ),
    tools=[]
)

front_task = Task(
    description=(
        "Interact with the customer to determine if their request"
    ),
    expected_output=(
        "A decision on whether the customer's request is for first agent or second,"
        "and delegation to the respective agent."
    ),
    agent=front,
    human_input=True
)

second_task = Task(
    description=(
        "Ask the customer relevant questions to understand their"
    ),
    expected_output=(
        "A detailed list of the customer's requirements and preferences"
    ),
    agent=second,
    human_input=True
)

third_task = Task(
    description=(
        "Ask the customer relevant questions to understand"
    ),
    expected_output=(
        "A detailed list of the customer's service requirements"
    ),
    agent=third,
    human_input=True
)

# Create Crew
my_crew = Crew(
    agents=[front_desk_agent, sales_agent, service_agent],
    tasks=[front_desk_task, sales_task, service_task],
    manager_llm=ChatOpenAI(temperature=0, model="gpt-4"),  # Mandatory if manager_agent is not set
    process=Process.hierarchical,  # Specifies the hierarchical management approach
    memory=True,  # Enable memory usage for enhanced task execution
    manager_agent=None,  # Optional: explicitly set a specific agent as manager instead of the manager_llm

)

# Kick off the crew with a sample input
result = my_crew.kickoff()
print(result)
theCyberTech commented 2 days ago

Ok, I have some suggestions but we are better off taking this to discord if that's ok?

IF you could raise a support post I can respond there in detail

arunbaby0 commented 2 days ago

Sure. I will post it there. Thanks, @theCyberTech