Skip to content

[BUG] compatibility error with pydantic #1551

Closed as not planned
Closed as not planned
@JoseiltonMota

Description

@JoseiltonMota

Description

Im getting this erro:
AttributeError: type object 'YoutubeVideoDetailsToolInput' has no attribute 'model_fields'

Steps to Reproduce

when I run the crew, it shows the error in the agents

Expected behavior

Screenshots/Code snippets

def research_manager(self, youtube_video_search_tool, youtube_video_details_tool):
    return Agent(
        role="YouTube Research Manager",
        goal="""For a given topic and description for a new YouTube video, find a minimum of 15 high-performing videos 
            on the same topic with the ultimate goal of populating the research table which will be used by 
            other agents to help them generate titles  and other aspects of the new YouTube video 
            that we are planning to create.""",
        backstory="""As a methodical and detailed research managar, you are responsible for overseeing researchers who 
            actively search YouTube to find high-performing YouTube videos on the same topic.""",
        verbose=True,
        allow_delegation=True,
        tools=[youtube_video_search_tool, youtube_video_details_tool]
    )

Operating System

Windows 11

Python Version

3.11

crewAI Version

crewai==0.76.9

crewAI Tools Version

crewai-tools==0.13.4

Virtual Environment

Venv

Evidence

Traceback (most recent call last):
File "D:\Documentos\codigos\youtube_helper\main.py", line 25, in
research_manager = agents.research_manager(youtube_video_search_tool, youtube_video_details_tool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\agents.py", line 29, in research_manager
return Agent(
^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\pydantic\main.py", line 212, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 179, in post_init_setup
self._setup_agent_executor()
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 189, in _setup_agent_executor
self.set_cache_handler(self.cache_handler)
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agents\agent_builder\base_agent.py", line 262, in set_cache_handler
self.create_agent_executor()
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 300, in create_agent_executor
tools_description=self._render_text_description_and_args(parsed_tools),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 412, in _render_text_description_and_args
for name, field in tool.args_schema.model_fields.items()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'YoutubeVideoDetailsToolInput' has no attribute 'model_fields'

Possible Solution

None

Additional context

from typing import List, Type
from pydantic import BaseModel, Field
from crewai_tools import BaseTool
import os
import requests
from datetime import datetime, timezone

class VideoSearchResult(BaseModel):
video_id: str
title: str
channel_id: str
channel_title: str
days_since_published: int

class YoutubeVideoSearchToolInput(BaseModel):
"""Input for YoutubeVideoSearchTool."""
keyword: str = Field(..., description="The search keyword.")
max_results: int = Field(10, description="The maximum number of results to return.")

class YoutubeVideoSearchTool(BaseTool):
name: str = "Search YouTube Videos"
description: str = "Searches YouTube videos based on a keyword and returns a list of video search results."
#args_schema: Type[BaseModel] = YoutubeVideoSearchToolInput

def _run(self, keyword: str, max_results: int = 10) -> list:
    api_key = os.getenv("YOUTUBE_API_KEY")
    url = "https://www.googleapis.com/youtube/v3/search"
    params = {
        "part": "snippet",
        "q": keyword,
        "maxResults": max_results,
        "type": "video",
        "key": api_key
    }
    response = requests.get(url, params=params)
    response.raise_for_status()
    items = response.json().get("items", [])

    results = []
    for item in items:
        video_id = item["id"]["videoId"]
        title = item["snippet"]["title"]
        channel_id = item["snippet"]["channelId"]
        channel_title = item["snippet"]["channelTitle"]
        publish_date = datetime.fromisoformat(
            item["snippet"]["publishedAt"].replace('Z', '+00:00')).astimezone(timezone.utc)
        days_since_published = (datetime.now(
            timezone.utc) - publish_date).days
        results.append(
            video_id=video_id,
            title=title,
            channel_id=channel_id,
            channel_title=channel_title,
            days_since_published=days_since_published
        )

    return results

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions