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.12k stars 2.64k forks source link

I have two projects both are stuck with just a pydantic issue | pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `base_directory = #651

Closed steelliberty closed 3 weeks ago

steelliberty commented 3 months ago

Traceback (most recent call last): File "", line 1, in File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/Users/jm/jmautogpt/news_agency_1/main.py", line 7, in from crew import NewsSourceResearcher File "/Users/jm/jmautogpt/news_agency_1/crew.py", line 12, in @CrewBase ^^^^^^^^ File "/Users/jm/jmautogpt/news_agency_1/.venv/lib/python3.11/site-packages/crewai/project/crew_base.py", line 13, in CrewBase class WrappedClass(cls): File "/Users/jm/jmautogpt/news_agency_1/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 93, in new private_attributes = inspect_namespace( ^^^^^^^^^^^^^^^^^^ File "/Users/jm/jmautogpt/news_agency_1/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 406, in inspect_namespace raise PydanticUserError( pydantic.errors.PydanticUserError: A non-annotated attribute was detected: base_directory = PosixPath('/Users/jm/jmautogpt/news_agency_1'). All model fields require a type annotation; if base_directory is not meant to be a field, you may be able to resolve this error by annotating it as a ClassVar or updating model_config['ignored_types'].

-- the Code causing the error above is here:

import os from crewai import Agent, Crew, Process, Task from crewai.project import CrewBase, agent, crew, task from crewai_tools import WebsiteSearchTool from langchain_community.tools import DuckDuckGoSearchRun# Initialize the tool search_tool = DuckDuckGoSearchRun() from langchain_groq import ChatGroq import sqlite3

@CrewBase class NewsSourceResearcher(Agent):

def __init__(self) -> None:

    # add other models here
    self.groq_llm = ChatGroq(temperature=0, model='llama3-8b-8192')
    self.agents_config = 'config/agents.yaml'
    self.tasks_config = 'config/tasks.yaml'

@agent
def source_manager(self) -> Agent:
    return Agent(config=self.agents_config['source_manager'],
                 llm=self.groq_llm,)
@task
def source_manager_task(self) -> Task:
    return Task(
        config=self.tasks_config['source_manager_task'],
        agent=self.source_manager(),
        tools=[search_tool,WebsiteSearchTool(),sqlite3]
    )

@crew
def crew(self) -> Crew:
    return Crew(
        agents=self.agents,
        tasks=self.tasks,
        process=Process.sequential,
        verbose=2

        )
pythonbyte commented 3 months ago

Hi @steelliberty

Thanks for opening this Issue, but after some tests on your code, some problems were identified.

  1. You are inheriting the Agent class on your Crew, which is causing the main issue for the crew to run.
  2. You are using the "sqlite3" as a Tool but that is a library, you'll probably have to look for some tool available that will use sqlite3 as you intend to.

The version of your code working is like this

from crewai_tools import WebsiteSearchTool
from langchain_community.tools import DuckDuckGoSearchRun  # Initialize the tool
from langchain_groq import ChatGroq

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

search_tool = DuckDuckGoSearchRun()
website_tool = WebsiteSearchTool()

@CrewBase
class <YouCrewName>:
    def __init__(self) -> None:
        # add other models here
        self.groq_llm = ChatGroq(temperature=0, model="llama3-8b-8192")
        self.agents_config = "config/agents.yaml"
        self.tasks_config = "config/tasks.yaml"

    @agent
    def source_manager(self) -> Agent:
        return Agent(
            config=self.agents_config["source_manager"],
            llm=self.groq_llm,
        )

    @task
    def source_manager_task(self) -> Task:
        return Task(
            config=self.tasks_config["source_manager_task"],
            agent=self.source_manager(),
            tools=[search_tool, website_tool],
        )

    @crew
    def crew(self) -> Crew:
        return Crew(
            agents=self.agents, tasks=self.tasks, process=Process.sequential, verbose=2
        )
github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been stalled for 5 days with no activity.