Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alvarod91100 opened this issue Apr 25, 2024 · 0 comments

Comments

@alvarod91100
Copy link

alvarod91100 commented Apr 25, 2024

Trying to use the hierarchical process with a crew while using Langchain's implementation of OpenAI Chat (langchain_openai.ChatOpenAI) but keep encountering the following error:

  File ".../.../.../lib/python3.12/site-packages/crewai/agent.py", line 131, in __init__
    super().__init__(**config, **data)
  File ".../.../.../lib/python3.12/site-packages/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
  File ".../.../.../lib/python3.12/site-packages/crewai/agent.py", line 172, in set_agent_executor
    self.set_cache_handler(self.cache_handler)
  File ".../.../.../lib/python3.12/site-packages/crewai/agent.py", line 244, in set_cache_handler
    self.create_agent_executor()
  File ".../.../.../lib/python3.12/site-packages/crewai/agent.py", line 303, in create_agent_executor
    bind = self.llm.bind(stop=[self.i18n.slice("observation")])
           ^^^^^^^^^^^^^
  File ".../.../.../lib/python3.12/site-packages/pydantic/main.py", line 767, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'Agent' object has no attribute 'bind'

Double-checked and ChatOpenAI does have attribute defined, as mentioned in langchain's documentation and manually checking the library's code locally.

Code used is the following:

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI

connectionLLM = ChatOpenAI(
    api_key="------"
)

manager = Agent(
    role='Project Manager',
    goal='Coordinate the project to ensure a seamless integration of research findings into compelling narratives',
    verbose=True,
    backstory="""With a strategic mindset and a knack for leadership, you excel at guiding teams towards
    their goals, ensuring projects not only meet but exceed expectations.""",
    allow_delegation=True,
    llm = connectionLLM
)

researcher = Agent(
    role='Senior Researcher',
    goal=f'Uncover groundbreaking technologies around {topic}',
    verbose=True,
    backstory="""Driven by curiosity, you're at the forefront of innovation, eager to explore and share
    knowledge that could change the world.""", 
    llm = connectionLLM
)

# Define the writer agent
writer = Agent(
    role='Writer',
    goal=f'Narrate compelling tech stories around {topic}',
    verbose=True,
    backstory="""With a flair for simplifying complex topics, you craft engaging narratives that captivate
    and educate, bringing new discoveries to light in an accessible manner.""", 
    llm = connectionLLM
)

list_ideas = Task(
    description="List of 5 interesting ideas to explore for an article about {topic}.",
    expected_output="Bullet point list of 5 ideas for an article.",
    tools=[search_tool],  
    agent=researcher,
    async_execution=True
)

list_important_history = Task(
    description="Research the history of {topic} and identify the 5 most important events.",
    expected_output="Bullet point list of 5 important events.",
    tools=[search_tool],
    agent=researcher,
    async_execution=True
)

write_article = Task(
    description=f"Compose an insightful article on {topic}, including its history and the latest interesting ideas.",
    expected_output="A 4 paragraph article about AI in healthcare.",
    tools=[search_tool],  
    agent=writer,
    context=[list_ideas, list_important_history],  # Depends on the completion of the two asynchronous tasks
)

manager_task = Task(
    description=f"""Oversee the integration of research findings and narrative development to produce a final comprehensive
    report on {topic}. Ensure the research is accurately represented and the narrative is engaging and informative.""",
    expected_output=f'A final comprehensive report that combines the research findings and narrative on {topic}.',
    agent=manager
)

crew = Crew(
    agents=[manager, researcher, writer],
    tasks=[list_ideas, list_important_history, write_article, manager_task],
    process=Process.hierarchical, 
    manager_llm= manager
)

results = crew.kickoff()

error persists in Python version is 3.11.0 and 3.12 with the following langchain and crewai versions:

crewai==0.28.8
langchain==0.1.16      
langchain-community==0.0.34
langchain-core==0.1.45
langchain-experimental==0.0.57
langchain-openai==0.1.3

Using sequential process does not throw the error.

@alvarod91100 alvarod91100 changed the title 'Agent' getting error when using 'bind' with Langchain's Chat Model when using Hierarchical Process 'Agent' getting error when using 'bind' with Langchain's Chat Model using Hierarchical Process Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant