'Agent' getting error when using 'bind' with Langchain's Chat Model using Hierarchical Process

I am trying to create a crew of agents which includes a manager_llm (custom agent that I have created for my use case).
Upon using the below code -
crew = Crew(
agents=[query_length_checker, mathematical_calculator],
tasks=[query_enrichment, mathematical_calc],
manager_llm = manager, # Use your custom manager agent
process=Process.hierarchical,
planning=True,
)

I am getting the below error when trying to kickoff the crew -
AttributeError: ‘Agent’ object has no attribute ‘bind’

I am using - GPT-4o to run the crew.
My import is as below -
from langchain_openai import AzureChatOpenAI

Any help is highly appreciated!

Hey Samhati, first off, welcome aboard!

I’d suggest checking out this other thread and this related one that cover Process.hierarchical.

Quick tip: the manager_llm parameter takes an LLM instance, not an Agent instance. If you want to plug in your own custom agent to act as the manager, then you’ll use the manager_agent parameter for that.

Hi,
Thank you for responding.

Upon using manager_agent I am getting the below error -
ValidationError: 1 validation error for Crew
Attribute manager_llm is required when using hierarchical process. [type=missing_manager_llm, input_value={‘agents’: [Agent(role=En…bose’: 2, ‘max_iter’: 5}, input_type=dict]

Any help is appreciated! Thanks.

I just confirmed that this example I provided in the other thread is working perfectly.

This example uses a custom Crew.manager_agent, without using the manager_llm parameter, and everything runs smoothly. I strongly suggest you check out the code there and compare it with how you’re declaring things in your code.

Thanks! I am using GPT-4-turbo to run this and getting the error. Let me redo the exercise using the example mentioned in the thread. Appreciate your prompt response.

I am getting the same error using the example in the thread when using Gpt-4-turbo.
Is it possible for you to reconfirm once?
Any leads is highly appreciated! Thanks.

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=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=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=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
)

NOTE : I’m using gpt-4-turbo/gpt-4o with this import rom langchain_openai import AzureChatOpenAI
Error -

Alright, so here’s what I’m working with. The environment:

  • crewai version 0.118.0
  • crewai-tools version 0.43.0
  • GPT-4 Turbo running on the OpenRouter provider

Here’s the test code I’m running (this version uses manager_agent but leaves out the manager_llm parameter):

from crewai import Agent, Task, Crew, LLM, Process
import os

os.environ["OPENROUTER_API_KEY"] = "<YOUR_API_KEY>"

# LLM
gpt_4_turbo_llm = LLM(
    model="openrouter/openai/gpt-4-turbo",
    temperature=0.6,
    max_completion_tokens=200
)

# Worker 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=gpt_4_turbo_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=gpt_4_turbo_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 Agent
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=gpt_4_turbo_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
)

# Test 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')

Output:

Thank you! Let me re run and get back to you.
Appreciate your help and prompt response.