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
21.2k stars 2.94k forks source link

[BUG] After attempting to use SerperDevTool, SerperDevTool and default MyCustomTool fail pydantic validation #1575

Open clayharris opened 5 days ago

clayharris commented 5 days ago

Description

I receive Agent/Tool validation errors whenever I try to use SerperDevTool or the default MyCustomTool, after attempting to use SerperDevTool the first time. MyCustomTool works fine beforehand, and fails afterwards. The crew runs fine if I remove the tools completely, either commenting out the tools param or providing an empty array [].

I've repeated this multiple times with new crews created via crewai create crew x, and I ensured I'm using the latest via pip install -U crewai

It appears some form of caching is occurring and causing tool errors to persist

Steps to Reproduce

  1. Create new crew project via crewai create crew projectx
  2. In crew.py uncomment the lines to import MyCustomTool and the researcher tools line to include it for the agent
  3. crewai run and verify success
  4. change the import to from crewai_tools import SerperDevTool and reference the tool in the agent's tools
  5. crewai run and see errors
  6. Revert changes and restore MyCustomTool setup
  7. re-run, observe continued failures

Expected behavior

Screenshots/Code snippets

pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent tools.0 Input should be a valid dictionary or instance of BaseTool [type=model_type, >input_value=SerperDevTool(name='Searc...lts=10, save_file=False), input_type=SerperDevTool] For further information visit https://errors.pydantic.dev/2.9/v/model_type An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

...
from crewai_tools import SerperDevTool

search_tool = SerperDevTool()
...

CrewBase
class SearchCrew():
    """Search crew"""

    @agent
    def researcher(self) -> Agent:
        return Agent(
            llm=ollama_llm,
            config=self.agents_config['researcher'],
            verbose=True,
            tools=[search_tool],
        )

Operating System

Other (specify in additional context)

Python Version

3.12

crewAI Version

0.79.0

crewAI Tools Version

0.79.0

Virtual Environment

Conda

Evidence

base ❯ crewai run Running the Crew Traceback (most recent call last): File "/Users/.../project/.venv/bin/run_crew", line 8, in sys.exit(run()) ^^^^^ File "/Users/.../project/src/search/main.py", line 17, in run SearchCrew().crew().kickoff(inputs=inputs) ^^^^^^^^^^^^ File "/Users/.../project/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 35, in init self.map_all_task_variables() File "/Users/.../project/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 145, in map_all_task_variables self._map_task_variables( File "/Users/.../project/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 178, in _map_task_variables self.tasks_config[task_name]["agent"] = agents[agent_name]() ^^^^^^^^^^^^^^^^^^^^ File "/Users/.../project/.venv/lib/python3.12/site-packages/crewai/project/utils.py", line 7, in memoized_func cache[key] = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/.../project/src/search/crew.py", line 40, in researcher return Agent( ^^^^^^ File "/Users/.../project/.venv/lib/python3.12/site-packages/pydantic/main.py", line 212, in init validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent tools.0 Input should be a valid dictionary or instance of BaseTool [type=model_type, >input_value=SerperDevTool(name='Searc...lts=10, save_file=False), input_type=SerperDevTool] For further information visit https://errors.pydantic.dev/2.9/v/model_type An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

Possible Solution

None

Additional context

M1 macOS list needs updating: Sequoia 15.1

danny-lowery commented 4 days ago

I see the same issue with https://python.langchain.com/docs/integrations/tools/ddg/

Exception: 1 validation error for Agent
tools.0
  Input should be a valid dictionary or instance of BaseTool [type=model_type, input_value=DuckDuckGoSearchResults(a...), output_format='json'), input_type=DuckDuckGoSearchResults]
    For further information visit https://errors.pydantic.dev/2.9/v/model_type