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.34k stars 2.68k forks source link

cannot import name 'InstanceOf' from 'pydantic' #226

Closed dhnanjay closed 7 months ago

dhnanjay commented 7 months ago

I upgraded the crewai to 0.5.2 and it gives me following error :

ImportError: cannot import name 'InstanceOf' from 'pydantic' (/usr/local/lib/python3.10/dist-packages/pydantic/init.cpython-310-x86_64-linux-gnu.so)

from crewai import Agent, Task, Crew, Process `---------------------------------------------------------------------------

ImportError Traceback (most recent call last)

in <cell line: 1>() ----> 1 from crewai import Agent, Task, Crew, Process

1 frames

/usr/local/lib/python3.10/dist-packages/crewai/agent.py in 8 from langchain_core.runnables.config import RunnableConfig 9 from langchain_openai import ChatOpenAI ---> 10 from pydantic import ( 11 UUID4, 12 BaseModel,

ImportError: cannot import name 'InstanceOf' from 'pydantic' (/usr/local/lib/python3.10/dist-packages/pydantic/init.cpython-310-x86_64-linux-gnu.so)`

!pip show crewai

Name: crewai Version: 0.5.2 Summary: Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks. Home-page: Author: Joao Moura Author-email: joao@crewai.com License: Location: /usr/local/lib/python3.10/dist-packages Requires: langchain, langchain-openai, openai, pydantic Required-by:

!pip show pydantic

Name: pydantic Version: 2.6.1 Summary: Data validation using Python type hints Home-page: Author: Author-email: Samuel Colvin [s@muelcolvin.com](mailto:s@muelcolvin.com), Eric Jolibois [em.jolibois@gmail.com](mailto:em.jolibois@gmail.com), Hasan Ramezani [hasan.r67@gmail.com](mailto:hasan.r67@gmail.com), Adrian Garcia Badaracco [1755071+adriangb@users.noreply.github.com](mailto:1755071+adriangb@users.noreply.github.com), Terrence Dorsey terry@pydantic.dev, David Montague david@pydantic.dev, Serge Matveenko [lig@countzero.co](mailto:lig@countzero.co), Marcelo Trylesinski [marcelotryle@gmail.com](mailto:marcelotryle@gmail.com), Sydney Runkle [sydneymarierunkle@gmail.com](mailto:sydneymarierunkle@gmail.com), David Hewitt [mail@davidhewitt.io](mailto:mail@davidhewitt.io) License: Location: /usr/local/lib/python3.10/dist-packages Requires: annotated-types, pydantic-core, typing-extensions Required-by: chromadb, confection, crewai, fastapi, inflect, langchain, langchain-core, langsmith, lida, llmx, openai

dhnanjay commented 7 months ago

I updated the langchain from 1.0 to 1.5.0 and the above problem was resolved, but now I see another issue using Process.hierarchical :


# Forming the crew with a hierarchical process including the manager

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

ValidationError Traceback (most recent call last)

in <cell line: 103>() 101 102 # Forming the crew with a hierarchical process including the manager --> 103 crew = Crew( 104 agents=[manager, researcher, writer], 105 tasks=[list_ideas, list_important_history, write_article, manager_task],

/usr/local/lib/python3.10/dist-packages/pydantic/main.py in init(self, **data) 169 # __tracebackhide__ tells pytest and some other tools to omit this function from tracebacks 170 tracebackhide = True --> 171 self.__pydantic_validator.validate_python(data, self_instance=self) 172 173 # The following line sets a flag that we use to determine when `init__` gets overridden by the user

ValidationError: 1 validation error for Crew Attribute manager_llm is required when using hierarchical process. [type=missing_manager_llm, input_value={'agents': [Agent(id=UUID...chical: 'hierarchical'>}, input_type=dict]

raulduke9119 commented 7 months ago

You habe to Set manager_llm=ChatOpenAI(model="gpt-4", Temperatur = 9.1)

In the Crew class

Sparsh Kumbhare @.***> schrieb am Mi., 7. Feb. 2024, 16:43:

I am facing the same issue Were you able to solve it

— Reply to this email directly, view it on GitHub https://github.com/joaomdmoura/crewAI/issues/226#issuecomment-1932322202, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTFTIBA6F23FIVPJ32R3A3YSOOLZAVCNFSM6AAAAABC4RLARWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGMZDEMRQGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

raulduke9119 commented 7 months ago

(Look at documentation)

Dominik Andritsch @.***> schrieb am Do., 8. Feb. 2024, 01:06:

You habe to Set manager_llm=ChatOpenAI(model="gpt-4", Temperatur = 9.1)

In the Crew class

Sparsh Kumbhare @.***> schrieb am Mi., 7. Feb. 2024, 16:43:

I am facing the same issue Were you able to solve it

— Reply to this email directly, view it on GitHub https://github.com/joaomdmoura/crewAI/issues/226#issuecomment-1932322202, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTFTIBA6F23FIVPJ32R3A3YSOOLZAVCNFSM6AAAAABC4RLARWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGMZDEMRQGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

joaomdmoura commented 7 months ago

Hey @dhnanjay thanks for the issue, indeed as @raulduke9119 mentioned and on the message error:

ValidationError: 1 validation error for Crew Attribute manager_llm is required when using hierarchical process. [type=missing_manager_llm, input_value={'agents': [Agent(id=UUID...chical: 'hierarchical'>}, input_type=dict]

We for now decide to force people to set the manager's llm, we have been considering making gpt-4 a default for that as well but not sure yet.