crewAIInc / 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
19.72k stars 2.73k forks source link

[BUG]: 'AzureOpenAI' object has no attribute 'bind' - CrewAI support requirement #1314

Closed tushitdave closed 3 weeks ago

tushitdave commented 3 weeks ago

Description

I am not sure, This issue is from crewai or AzureOpenAI side,also not sure if it's a bug or feature requirement. However while creating an agent I have received below error- "" 'AzureOpenAI' object has no attribute 'bind' "" It seems , either AzureOpenAI is not calling the function or CrewAI doesn't support AzureOpenAI in his agentic approach.

Steps to Reproduce

llm = AzureOpenAI(api_key=openai_api_key, api_version="xxxx-xx-xx-preview", azure_endpoint="https://xxxxx-xxxxxxxx.xxxxxx.xxxxx.com/")

load crewai tools

serper_search_tool = SerperDevTool()

load custom tools

kaggle_tool = KaggleDatasetDownloader()

data_collection_agent = Agent( role='Data Acquisition Specialist', goal='Find and download appropriate datasets on a given topic', backstory='Expert in acquiring datasets from various sources, specializing in climate data', tools=[serper_search_tool, kaggle_tool], llm=llm, verbose=True )

I have noticed some other person also opened the ticket similar to this however closed. Hence not able to raise queries there.

Expected behavior

It shouldn't throw "bind" error considering the AzureOpenAI if crewAI is fully supoorted

Screenshots/Code snippets

Error:


AttributeError Traceback (most recent call last) Cell In[15], line 8 4 # load custom tools 5 kaggle_tool = KaggleDatasetDownloader() ----> 8 data_collection_agent = Agent( 9 role='Data Acquisition Specialist', 10 goal='Find and download appropriate datasets on a given topic', 11 backstory='Expert in acquiring datasets from various sources, specializing in climate data', 12 tools=[serper_search_tool, kaggle_tool], 13 llm=llm, 14 verbose=True 15 )

[... skipping hidden 1 frame]

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:129, in Agent.post_init_setup(self) 126 self._setup_llm_callbacks(model_name) 128 if not self.agent_executor: --> 129 self._setup_agent_executor() 131 return self

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:154, in Agent._setup_agent_executor(self) 152 if not self.cache_handler: 153 self.cache_handler = CacheHandler() --> 154 self.set_cache_handler(self.cache_handler)

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agents\agent_builder\base_agent.py:259, in BaseAgent.set_cache_handler(self, cache_handler) 257 self.cache_handler = cache_handler 258 self.tools_handler.cache = cache_handler --> 259 self.create_agent_executor()

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:308, in Agent.create_agent_executor(self, tools) 303 if self.response_template: 304 stop_words.append( 305 self.response_template.split("{{ .Response }}")[1].strip() 306 ) --> 308 bind = self.llm.bind(stop=stop_words) 310 inner_agent = agent_args | execution_prompt | bind | CrewAgentParser(agent=self) 311 self.agent_executor = CrewAgentExecutor( 312 agent=RunnableAgent(runnable=inner_agent), **executor_args 313 )

AttributeError: 'AzureOpenAI' object has no attribute 'bind'

Operating System

Windows 10

Python Version

3.10

crewAI Version

0.55.2

crewAI Tools Version

0.12.0

Virtual Environment

Conda

Evidence


AttributeError Traceback (most recent call last) Cell In[15], line 8 4 # load custom tools 5 kaggle_tool = KaggleDatasetDownloader() ----> 8 data_collection_agent = Agent( 9 role='Data Acquisition Specialist', 10 goal='Find and download appropriate datasets on a given topic', 11 backstory='Expert in acquiring datasets from various sources, specializing in climate data', 12 tools=[serper_search_tool, kaggle_tool], 13 llm=llm, 14 verbose=True 15 )

[... skipping hidden 1 frame]

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:129, in Agent.post_init_setup(self) 126 self._setup_llm_callbacks(model_name) 128 if not self.agent_executor: --> 129 self._setup_agent_executor() 131 return self

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:154, in Agent._setup_agent_executor(self) 152 if not self.cache_handler: 153 self.cache_handler = CacheHandler() --> 154 self.set_cache_handler(self.cache_handler)

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agents\agent_builder\base_agent.py:259, in BaseAgent.set_cache_handler(self, cache_handler) 257 self.cache_handler = cache_handler 258 self.tools_handler.cache = cache_handler --> 259 self.create_agent_executor()

File c:\Users\10742161\AppData\Local\anaconda3\envs\crewai\lib\site-packages\crewai\agent.py:308, in Agent.create_agent_executor(self, tools) 303 if self.response_template: 304 stop_words.append( 305 self.response_template.split("{{ .Response }}")[1].strip() 306 ) --> 308 bind = self.llm.bind(stop=stop_words) 310 inner_agent = agent_args | execution_prompt | bind | CrewAgentParser(agent=self) 311 self.agent_executor = CrewAgentExecutor( 312 agent=RunnableAgent(runnable=inner_agent), **executor_args 313 )

AttributeError: 'AzureOpenAI' object has no attribute 'bind'

Possible Solution

May be some module needs to make compatible with AzureOpenAI

Additional context

In creation of Agentic approach mostly use, AzureOpenAI services instead of OpenAI directly due to Azure's wider customer base

theCyberTech commented 3 weeks ago

You are using an older Azure constructor, you should use the below

from langchain_openai import AzureChatOpenAI

llm = AzureChatOpenAI