Update - Functional Version of the Code
Folks, dealing with hierarchical processes requires some care, especially ensuring that your prompts don’t create an infinite loop. Try to clearly define the responses to facilitate the manager’s work.
I corrected and adapted the code presented above. I removed the task that was assigned to the manager, as it already assumes this responsibility internally. In my code, I’m using Gemini as the LLM, but you can certainly adapt it to your needs. The code below was executed successfully, hope it helps:
import os
from crewai import Agent, Task, Crew, LLM, Process
os.environ["GEMINI_API_KEY"] = "<YOUR_KEY>"
# LLM
gemini_flash_llm = LLM(
model="gemini/gemini-2.0-flash",
temperature=0.6,
timeout=90,
max_tokens=500
)
# Agents
technical_support_agent = Agent(
role="Technical Support Specialist",
goal="Resolve technical issues reported by customers promptly and "
"effectively",
backstory=(
"You are a highly skilled technical support specialist with a "
"strong background in troubleshooting software and hardware "
"issues. Your primary responsibility is to assist customers "
"in resolving technical problems, ensuring their satisfaction "
"and the smooth operation of their products."
),
llm=gemini_flash_llm,
allow_delegation=False,
verbose=True
)
billing_support_agent = Agent(
role="Billing Support Specialist",
goal="Address customer inquiries related to billing, payments, "
"and account management",
backstory=(
"You are an experienced billing support specialist with "
"expertise in handling customer billing inquiries. Your main "
"objective is to provide clear and accurate information "
"regarding billing processes, resolve payment issues, and "
"assist with account management to ensure customer "
"satisfaction."
),
llm=gemini_flash_llm,
allow_delegation=False,
verbose=True
)
# Tasks
resolve_technical_issues = Task(
description="Resolve only technical issues described in the "
"ticket: {ticket}",
expected_output="Provide a solution in up to 400 characters if "
"it is something technical, otherwise state that it is not "
"something technical.",
agent=technical_support_agent
)
resolve_billing_issues = Task(
description="Resolve only billing issues described in the ticket: "
"{ticket}",
expected_output="Provide a solution in up to 400 characters if "
"it is something related to billing, otherwise inform that it "
"is not something related to billing.",
agent=billing_support_agent
)
# Manager
manager = Agent(
role="Customer Support Manager",
goal="Oversee the support team to ensure timely and effective "
"resolution of customer inquiries",
backstory=(
"You are a seasoned customer support manager with extensive "
"experience in leading support teams. Your primary "
"responsibility is to coordinate the efforts of support "
"agents, ensuring that customer issues are addressed "
"promptly and satisfactorily. You excel in task delegation, "
"performance monitoring, and maintaining high standards of "
"customer service."
),
llm=gemini_flash_llm,
allow_delegation=True,
verbose=True
)
# Crew
crew = Crew(
agents=[technical_support_agent, billing_support_agent],
tasks=[resolve_technical_issues, resolve_billing_issues],
manager_agent=manager,
process=Process.hierarchical
)
When executed with:
# Start the crew's work
result = crew.kickoff(
inputs={
'ticket': "My modem is not working. No LEDs are on either."
}
)
print(f'\n[🤖 Final Answer]\n{result.raw}\n')
The result was:
[🤖 Final Answer]
Not a billing issue. Check power outlet, adapter, and cord. Power cycle the modem. If still no LEDs, the modem likely failed and needs replacement.
When executed with:
# Start the crew's work
result = crew.kickoff(
inputs={
'ticket': "My modem isn't working. My bill was due 1 week ago."
}
)
print(f'\n[🤖 Final Answer]\n{result.raw}\n')
The result was:
[🤖 Final Answer]
Your modem service is suspended due to a past-due bill. Please make a payment to restore service. Service should resume within an hour after payment.