joaomdmoura / 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
16.8k stars 2.27k forks source link

KeyError: 'tools' #574

Open windowshopr opened 1 month ago

windowshopr commented 1 month ago

Environment

Python 3.11
Windows 10
crew==0.9.2
crewai==0.28.8
crewai-tools==0.2.4
langchain==0.1.17
langchain-community==0.0.36
langchain-core==0.1.51
langchain-openai==0.0.5
langsmith==0.1.50

Code

import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import WebsiteSearchTool
from crewai_tools import GithubSearchTool
from crewai_tools import YoutubeVideoSearchTool
from crewai_tools import ScrapeWebsiteTool
from crewai_tools import CodeDocsSearchTool
from crewai_tools import EXASearchTool
from langchain_openai import ChatOpenAI
from langchain_community.document_loaders import DirectoryLoader

OPENAI_API_BASE='http://localhost:11434/v1' # Using Ollama for local models
OPENAI_API_KEY='NA'
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
OPENAI_GENERAL_MODEL_NAME='llama2'
OPENAI_CODING_MODEL_NAME='codellama:34b'

PROJECT_ASK = """
    I want to start with a simple test project to see how the team works together. Right now,
    there's only yourself and the Frontend Developer on the team.
    I'd like you to create a simple register/login page for a web application.
    I'd like it to be programmed in Svelte, and I'd like it to have the following features:
    - A registration form with fields for email, username, and password
    - A login form with fields for email and password
    - A button to switch between the registration and login forms
    - A button to submit the registration form
    - A button to submit the login form
    - A simple error message that appears if the user enters the wrong email or password
    - A simple success message that appears if the user successfully registers or logs in
    - A simple design that is visually appealing and responsive
    - A simple user interface that is easy to use and understand

    Show me the code and instructions to run the frontend on my local machine as defined by the
    frontend developer.
"""

# Default LLM
llm = ChatOpenAI(
    model=OPENAI_GENERAL_MODEL_NAME,
    base_url=OPENAI_API_BASE,
)

# LlamaCode model
llm_code = ChatOpenAI(
    model=OPENAI_CODING_MODEL_NAME,
    base_url=OPENAI_API_BASE,
)

# AGENTS
project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory="""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality.""",
    tools=[DirectoryLoader(path="./free_programming_books/project_manager", 
                           recursive=True, 
                           show_progress=True), 
           WebsiteSearchTool(website='https://www.google.ca/'),
           YoutubeVideoSearchTool(),
           ScrapeWebsiteTool(),
           ],
    llm=llm,
    function_calling_llm=None,
    max_iter=15,
    max_rpm=None,
    verbose=True,
    allow_delegation=True,
    step_callback=None,
    cache=True,
)

frontend_developer = Agent(
    role='Frontend Developer',
    goal='Design and implement the user interface of the web application',
    backstory="""I am a knowledgable frontend developer with experience in designing and implementing user interfaces for web applications.
                 I have a strong understanding of HTML, CSS, and JavaScript, as well as modern frontend frameworks like Svelte, Node, Vue, and React.
                 My focus is on creating visually appealing, responsive, and user-friendly interfaces that meet the client's requirements and enhance the user experience.
                 I work with the Backend Developer, Database Administrator, Security Engineer, and DevOps Engineer to ensure the frontend integrates seamlessly with the backend and meets all requirements set by both the Client and the team.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 I am also responsible for ensuring the frontend is optimized for performance and accessibility, and that it follows best practices in terms of security and maintainability.""",
           # Svelte resources
    tools=[DirectoryLoader(path="./free_programming_books/svelte",
                           recursive=True,
                           show_progress=True),
           GithubSearchTool(github_repo="https://github.com/sveltejs/svelte"),
       #........
           ],
    llm=llm_code,
    function_calling_llm=None,
    max_iter=15,  # Optional, default is 25
    max_rpm=None, # Optional
    verbose=True,  # Optional
    allow_delegation=True,  # Optional
    step_callback=None,  # Optional
    cache=True,  # Optional
)

# TASKS
project_manager_task = Task(
    description=PROJECT_ASK,
    agent=project_manager,
    expected_output="Summary of the project's vision (showcasing a thorough understanding of the Client's requirements), and all features grouped by team member responsibilty (i.e. Frontend Developer, Backend Developer, Database Administrator, Security Engineer, DevOps Engineer).",
    # tools=[SerperDevTool(), JiraTool()],
    async_execution=False,
    context=None,
    config=None,
    output_json=None,
    output_pydantic=None,
    output_file=None,
    callback=None,
    human_input=True,
)

frontend_developer_task = Task(
    description="Design and implement the user interface of the web application.",
    agent=frontend_developer,
    expected_output="A visually appealing, responsive, and user-friendly interface that meets the client's requirements and enhances the user experience.",
    async_execution=False,
    context=[project_manager_task],
    config=None,
    output_json=None,
    output_pydantic=None,
    output_file=None,
    callback=None,
    human_input=True,
)

# Create the crew and assign the tasks
crew = Crew(
    id='Software Development Crew',
    tasks=[project_manager_task, frontend_developer_task],
    agents=[project_manager, frontend_developer],
    verbose=2,
    share_crew=False,
)

# Kick off the crew
crew.kickoff()

Error traceback

Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 65, in <module>
    project_manager = Agent(
                      ^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 131, in __init__
    super().__init__(**config, **data)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 172, in set_agent_executor
    self.set_cache_handler(self.cache_handler)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 244, in set_cache_handler
    self.create_agent_executor()
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 305, in create_agent_executor
    self.agent_executor = CrewAgentExecutor(
                          ^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\load\serializable.py", line 120, in __init__     
    super().__init__(**kwargs)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 1100, in validate_model
    values = validator(cls_, values)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\agents\agent.py", line 980, in validate_tools
    tools = values["tools"]
            ~~~~~~^^^^^^^^^
KeyError: 'tools'

Other Notes image

VALUES
{'name': None, 'memory': None, 'callbacks': None, 'verbose': True, 'tags': None, 'metadata': None, 'callback_manager': None, 'agent': RunnableAgent(runnable={
  input: RunnableLambda(...),
  tools: RunnableLambda(...),
  tool_names: RunnableLambda(...),
  agent_scratchpad: RunnableLambda(...)
}
| PromptTemplate(input_variables=['agent_scratchpad', 'input', 'tool_names', 'tools'], partial_variables={'goal': 'Works directly with the Client and delegates tasks to the team/reports back to the Client', 'role': 'Project Manager', 'backstory': "I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. \n                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.\n                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.\n                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.\n                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.\n                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."}, template='You are {role}. {backstory}\nYour personal goal is: {goal}\nYou ONLY have access to the following tools, and should NEVER make up tools that are 
not listed here:\n\n{tools}\n\nUse the following format:\n\nThought: you should always think about what to do\nAction: the action to take, only one name of [{tool_names}], just the name, exactly as it\'s written.\nAction Input: the input to the action, just a simple a python dictionary using " to wrap keys and values.\nObservation: the result of the action\n\nOnce all necessary information is gathered:\n\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nCurrent Task: {input}\n\nBegin! This is VERY important to you, use the tools available and give your best Final Answer, your job depends on it!\n\nThought: \n{agent_scratchpad}')
| RunnableBinding(bound=ChatOpenAI(callbacks=[<crewai.utilities.token_counter_callback.TokenCalcHandler object at 0x0000024340A9DF50>], client=<openai.resources.chat.completions.Completions object at 0x0000024340A8FE90>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x0000024342829390>, model_name='llama2', openai_api_key='NA', openai_api_base='http://localhost:11434/v1', openai_proxy=''), kwargs={'stop': ['\nObservation']})
| CrewAgentParser(agent=Agent(role=Project Manager, goal=Works directly with the Client and delegates tasks to the team/reports back to the Client, backstory=I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects.
                   I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                   I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                   I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                   I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                   My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality.)), input_keys_arg=[], return_keys_arg=[], stream_runnable=True), 'return_intermediate_steps': False, 'max_iterations': 15, 'max_execution_time': None, 'early_stopping_method': 'force', 'handle_parsing_errors': True, 'trim_intermediate_steps': -1, 'should_ask_for_human_input': False, 'llm': ChatOpenAI(callbacks=[<crewai.utilities.token_counter_callback.TokenCalcHandler object at 0x0000024340A9DF50>], client=<openai.resources.chat.completions.Completions object at 0x0000024340A8FE90>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x0000024342829390>, model_name='llama2', openai_api_key='NA', openai_api_base='http://localhost:11434/v1', openai_proxy=''), 'iterations': 0, 'task': None, 'tools_description': '', 'tools_names': '', 'original_tools': [<langchain_community.document_loaders.directory.DirectoryLoader object at 0x0000024340AE26D0>, WebsiteSearchTool(name='Search in a specific website', description="Search in a specific website(search_query: 'string') - A tool that can be used to semantic search a query from https://www.google.ca/ website content.", args_schema=<class 'crewai_tools.tools.website_search.website_search_tool.FixedWebsiteSearchToolSchema'>, description_updated=False, cache_function=<function BaseTool.<lambda> at 0x0000024342351300>, summarize=False, adapter=EmbedchainAdapter(embedchain_app=<embedchain.app.App object at 0x00000243422B2D90>, summarize=False), config=None), YoutubeVideoSearchTool(name='Search a Youtube Video content', description="Search a Youtube Video content(search_query: 'string', youtube_video_url: 'string') - A tool that can be used to semantic search a query from a Youtube Video content.", args_schema=<class 'crewai_tools.tools.youtube_video_search_tool.youtube_video_search_tool.YoutubeVideoSearchToolSchema'>, description_updated=False, cache_function=<function BaseTool.<lambda> at 0x0000024342351300>, summarize=False, adapter=EmbedchainAdapter(embedchain_app=<embedchain.app.App object at 0x0000024342768D10>, summarize=False), config=None), ScrapeWebsiteTool(name='Read website content', description="Read website content(website_url: 'string') - A tool that can be used to read a website content.", args_schema=<class 'crewai_tools.tools.scrape_website_tool.scrape_website_tool.ScrapeWebsiteToolSchema'>, description_updated=False, cache_function=<function BaseTool.<lambda> at 0x0000024342351300>, website_url=None, cookies=None, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Language': 'en-US,en;q=0.9', 'Referer': 'https://www.google.com/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'Accept-Encoding': 'gzip, deflate, br'})], 'crew_agent': Agent(role=Project Manager, goal=Works directly with the Client and delegates tasks to the team/reports back to the Client, backstory=I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects.
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality.), 'crew': None, 'function_calling_llm': None, 'request_within_rpm_limit': None, 'tools_handler': <crewai.agents.tools_handler.ToolsHandler object at 0x0000024342A2F210>, 'have_forced_answer': False, 'force_answer_max_iterations': None, 'step_callback': None}
windowshopr commented 1 month ago

My initial guess here is that this:

        agent = values["agent"]
        tools = values["tools"]

...should be changed to this:

        agent = values["agent"]
        tools = agent["tools"]

...given that the 'tools' key is subbed inside the 'agent' key, however when I change that section of code, I get this error instead which I think is easily fixed, I just don't know how to/how far this rabbit hole goes, so maybe a dev can look into it?

Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 65, in <module>
    project_manager = Agent(
                      ^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 131, in __init__
    super().__init__(**config, **data)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent
  Value error, 3 validation errors for CrewAgentExecutor
tools -> 0
  value is not a valid dict (type=type_error.dict)
__root__
  'RunnableAgent' object is not subscriptable (type=type_error)
__root__
  'RunnableAgent' object is not subscriptable (type=type_error) [type=value_error, input_value={'role': 'Project Manager...k': None, 'cache': True}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.6/v/value_error
steelliberty commented 1 month ago

I had this same issue and changed the source code to tools = agent["tools"] . But I still get errors after this change -- I am adding this here because is changing the code in agent.py causing the next issue? I am trying to add tools to my Agent definition. The Agent Definition and the traceback are below.

from crewai_tools import WebsiteSearchTool def source_researcher(self) -> Agent: return Agent(config=self.agents_config['source_researcher'], llm=self.groq_llm,tools=[WebsiteSearchTool] ) Traceback : Traceback (most recent call last): File "/Users/jackmullen/jmautogpt/crew_research_1/main.py", line 17, in run() File "/Users/jackmullen/jmautogpt/crew_research_1/main.py", line 14, in run t.crew().kickoff(inputs = inputs) ^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/project/annotations.py", line 25, in wrapper task_instance = possible_task() ^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/crew.py", line 49, in source_researcher_task agent=self.source_researcher() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/crew.py", line 28, in source_researcher return Agent(config=self.agents_config['source_researcher'], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/agent.py", line 131, in init super().init(config, data) File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/pydantic/main.py", line 176, in init self.pydantic_validator.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent Value error, 3 validation errors for CrewAgentExecutor tools -> 0 value is not a valid dict (type=type_error.dict) root__ 'RunnableAgent' object is not subscriptable (type=type_error) root__ 'RunnableAgent' object is not subscriptable (type=type_error) [type=value_error, input_value={'role': 'verify the sour...ol.WebsiteSearchTool'>]}, input_type=dict] For further information visit https://errors.pydantic.dev/2.7/v/value_error

theCyberTech commented 1 month ago

@windowshopr your crewAI version is out of date, add to the latest RC with with pip install crewai==0.30.0rc6 crewai-tools==0.2.3 --update

windowshopr commented 1 month ago

@theCyberTech Issue persists:

Successfully installed crewai-0.30.0rc6 crewai-tools-0.2.3

PS I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam> python main.py
C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\_api\module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following:
from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
  warnings.warn(
Inserting batches in chromadb:   0%|                                                                                      | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 65, in <module>
    project_manager = Agent(
                      ^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 140, in __init__
    super().__init__(**config, **data)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 187, in set_agent_executor
    self.set_cache_handler(self.cache_handler)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 259, in set_cache_handler
    self.create_agent_executor()
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 332, in create_agent_executor
    self.agent_executor = CrewAgentExecutor(
                          ^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\load\serializable.py", line 120, in __init__     
    super().__init__(**kwargs)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 1100, in validate_model
    values = validator(cls_, values)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\agents\agent.py", line 980, in validate_tools
    tools = values["tools"]
            ~~~~~~^^^^^^^^^
KeyError: 'tools'
theCyberTech commented 1 month ago

I wonder if the issue id in the way you are setting up the tools:

tools=[DirectoryLoader(path="./free_programming_books/project_manager",  recursive=True,  show_progress=True), 
           WebsiteSearchTool(website='https://www.google.ca/'),
           YoutubeVideoSearchTool(),
           ScrapeWebsiteTool(),
           ],

Can you try instantiating outside of the constructor like so

from crewai_tools import GithubSearchTool
from crewai_tools import YoutubeVideoSearchTool
from crewai_tools import ScrapeWebsiteTool
from crewai_tools import CodeDocsSearchTool
from crewai_tools import EXASearchTool

dir_loader = DirectoryLoader(path="./free_programming_books/project_manager",  recursive=True,  show_progress=True
website_search_tool = WebsiteSearchTool(website='https://www.google.ca/')
youtube_search_tool = YoutubeVideoSearchTool()
scrape_website_tool =  ScrapeWebsiteTool()

tools=[dir_loader, website_search_tool,  youtube_search_tool, scrape_website_tool],
windowshopr commented 1 month ago

Same issue:

#...
# TOOLS
# Project Manager
proj_manager_dir_tool = DirectoryLoader(path="./free_programming_books/project_manager", recursive=True, show_progress=True)
proj_manager_website_tool = WebsiteSearchTool(website='https://www.google.ca/')
proj_manager_youtube_tool = YoutubeVideoSearchTool()
proj_manager_scrape_tool = ScrapeWebsiteTool()
# proj_manager_github_tool = GithubSearchTool()
# proj_manager_codedocs_tool = CodeDocsSearchTool(docs_url='https://docs.github.com/en')

# AGENTS
project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory="""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality.""",
    tools=[proj_manager_dir_tool, proj_manager_website_tool, proj_manager_youtube_tool, proj_manager_scrape_tool],
    llm=llm,
    function_calling_llm=None,
    max_iter=15,  # Optional, default is 25
    max_rpm=None, # Optional
    verbose=True,  # Optional
    allow_delegation=True,  # Optional
    step_callback=None,  # Optional
    cache=True,  # Optional
)

#...
Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 75, in <module>
    project_manager = Agent(
                      ^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 140, in __init__
    super().__init__(**config, **data)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 187, in set_agent_executor
    self.set_cache_handler(self.cache_handler)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 259, in set_cache_handler
    self.create_agent_executor()
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 332, in create_agent_executor
    self.agent_executor = CrewAgentExecutor(
                          ^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\load\serializable.py", line 120, in __init__     
    super().__init__(**kwargs)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\v1\main.py", line 1100, in validate_model
    values = validator(cls_, values)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\agents\agent.py", line 980, in validate_tools
    tools = values["tools"]
            ~~~~~~^^^^^^^^^
KeyError: 'tools'
steelliberty commented 1 month ago

@windowshopr your crewAI version is out of date, add to the latest RC with with pip install crewai==0.30.0rc6 crewai-tools==0.2.3 --update

Thanks for the help but no luck, updated the two packages and got a similar error : Traceback (most recent call last): File "", line 1, in File "/Users/jackmullen/jmautogpt/crew_research_1/main.py", line 14, in run t.crew().kickoff(inputs = inputs) ^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/project/annotations.py", line 39, in wrapper task_instance = possible_task() ^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/project/annotations.py", line 10, in memoized_func cache[key] = func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/crew.py", line 49, in source_researcher_task agent=self.source_researcher() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/project/annotations.py", line 10, in memoized_func cache[key] = func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/crew.py", line 28, in source_researcher return Agent(config=self.agents_config['source_researcher'], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/crewai/agent.py", line 140, in init super().init(config, **data) File "/Users/jackmullen/jmautogpt/crew_research_1/.venv/lib/python3.11/site-packages/pydantic/main.py", line 176, in init self.pydantic_validator.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent Value error, 3 validation errors for CrewAgentExecutor tools -> 0 value is not a valid dict (type=type_error.dict) root__ 'RunnableAgent' object is not subscriptable (type=type_error) root__ 'RunnableAgent' object is not subscriptable (type=type_error) [type=value_error, input_value={'role': 'verify the sour...ol.WebsiteSearchTool'>]}, input_type=dict] For further information visit https://errors.pydantic.dev/2.7/v/value_error

slavakurilyak commented 1 month ago

Try updating langchain and/or langchain-community to resolve RunnableAgent error

Pip Commands

pip install langchain
pip install langchain-community

As of today:

pip install langchain==0.1.17
pip install langchain-community==0.0.37

Poetry Commands

poetry add langchain
poetry add langchain-community

As of today:

poetry add langchain==0.1.17
poetry add langchain-community==0.0.37
windowshopr commented 1 month ago

The same issue persists. It's a logic issue not a dependency issue.

windowshopr commented 1 month ago

Steps to continue debugging:

langchain > agents > agent.py

    @root_validator()
    def validate_tools(cls, values: Dict) -> Dict:
        """Validate that tools are compatible with agent."""
        agent = values["agent"]
        # tools = values["tools"]
        tools = agent["tools"] ############ Here
        allowed_tools = agent.get_allowed_tools()
        if allowed_tools is not None:
            if set(allowed_tools) != set([tool.name for tool in tools]):
                raise ValueError(
                    f"Allowed tools ({allowed_tools}) different than "
                    f"provided tools ({[tool.name for tool in tools]})"
                )
        return values

    @root_validator()
    def validate_return_direct_tool(cls, values: Dict) -> Dict:
        """Validate that tools are compatible with agent."""
        agent = values["agent"]
        # tools = values["tools"]
        tools = agent["tools"] ############ Here
        if isinstance(agent, BaseMultiActionAgent):
            for tool in tools:
                if tool.return_direct:
                    raise ValueError(
                        "Tools that have `return_direct=True` are not allowed "
                        "in multi-action agents"
                    )
        return values

CrewAI application code (slim down the agent)

project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory=dedent(f"""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."""),
    # tools=[proj_manager_dir_tool, proj_manager_website_tool, proj_manager_youtube_tool, proj_manager_scrape_tool],
    # llm=llm,
    # function_calling_llm=None,
    # max_iter=15,  # Optional, default is 25
    # max_rpm=None, # Optional
    # verbose=True,  # Optional
    # allow_delegation=True,  # Optional
    # step_callback=None,  # Optional
    # cache=True,  # Optional
)

pydantic > main.py

    def __init__(self, /, **data: Any) -> None:  # type: ignore
        """Create a new model by parsing and validating input data from keyword arguments.

        Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
        validated to form a valid model.

        `self` is explicitly positional-only to allow `self` as a field name.
        """
        # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
        __tracebackhide__ = True
        print("Data: ", data) ############### Here, want to see what "data" is...
        self.__pydantic_validator__.validate_python(data, self_instance=self)

Current traceback:

LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following:
from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
  warnings.warn(
Data:  {}
Data:  {}
Data:  {}
Data:  {}
Data:  {}
Data:  {}
Data:  {}
Data:  {}
Data:  {'name': 'embedchain_store', 'metadata': None, 'id': UUID('702e7158-afbd-4407-91a0-1e433de5a72d'), 'tenant': 'default_tenant', 'database': 'default_database'}
Data:  {'name': 'embedchain_store', 'metadata': None, 'id': UUID('702e7158-afbd-4407-91a0-1e433de5a72d'), 'tenant': 'default_tenant', 'database': 'default_database'}
Data:  {'embedchain_app': <embedchain.app.App object at 0x0000027F455EB7D0>, 'summarize': False}
Inserting batches in chromadb:   0%|                                                                                      | 0/1 [00:00<?, ?it/s]
Data:  {}
Data:  {}
Data:  {'name': 'embedchain_store', 'metadata': None, 'id': UUID('702e7158-afbd-4407-91a0-1e433de5a72d'), 'tenant': 'default_tenant', 'database': 'default_database'}
Data:  {'name': 'embedchain_store', 'metadata': None, 'id': UUID('702e7158-afbd-4407-91a0-1e433de5a72d'), 'tenant': 'default_tenant', 'database': 'default_database'}
Data:  {'embedchain_app': <embedchain.app.App object at 0x0000027F46EFB810>, 'summarize': False}
Data:  {}
Data:  {'role': 'Project Manager', 'goal': 'Works directly with the Client and delegates tasks to the team/reports back to the Client', 'backstory': "I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. \n    
             I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.\n                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.\n                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.\n      
           I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the 
information I need to make informed decisions.\n                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."}
Data:  {'i18n': I18N(prompt_file=None), 'tools': [], 'system_template': None, 'prompt_template': None, 'response_template': None}
Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 76, in <module>
    project_manager = Agent(
                      ^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai\agent.py", line 140, in __init__
    super().__init__(**config, **data)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 177, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent
  Value error, 2 validation errors for CrewAgentExecutor
__root__
  'RunnableAgent' object is not subscriptable (type=type_error)
__root__
  'RunnableAgent' object is not subscriptable (type=type_error) [type=value_error, input_value={'role': 'Project Manager...t standard of quality."}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.7/v/value_error
windowshopr commented 1 month ago

Disregard my last, I've discovered that it's an issue with the tools parameter of the Agent class. When I comment out the list of tools in the Agent, the code works as is, so the issue is here:

# TOOLS
# Project Manager
proj_manager_dir_tool = DirectoryLoader(path="./free_programming_books/project_manager", recursive=True, show_progress=True)
proj_manager_website_tool = WebsiteSearchTool(website='https://www.google.ca/')
proj_manager_youtube_tool = YoutubeVideoSearchTool()
proj_manager_scrape_tool = ScrapeWebsiteTool()
# AGENTS
project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory=dedent(f"""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."""),
    # tools=[proj_manager_dir_tool, proj_manager_website_tool, proj_manager_youtube_tool, proj_manager_scrape_tool], # TAKE THIS OUT AND IT WORKS....
    llm=llm,
    function_calling_llm=None,
    max_iter=15,  # Optional, default is 25
    max_rpm=None, # Optional
    verbose=True,  # Optional
    allow_delegation=True,  # Optional
    step_callback=None,  # Optional
    cache=True,  # Optional
)
slavakurilyak commented 1 month ago

Run the code with one tool at a time to identify if any specific tool is causing the issue.

# Add Tools Incrementally
project_manager.tools = [proj_manager_dir_tool]

# Test with a single tool
# Comment this part and test with the next tool to identify the problematic one
project_manager.tools.append(proj_manager_website_tool)
project_manager.tools.append(proj_manager_youtube_tool)
project_manager.tools.append(proj_manager_scrape_tool)

# Proceed with the rest of your setup
windowshopr commented 1 month ago

Thank you! While your suggestion did not work exactly as expected, what I discovered was to NOT assign the list of tools during the class definition, but to only append each tool AFTER the class object was created. Like so:

# AGENTS
project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory=dedent(f"""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."""),
    # tools=[proj_manager_dir_tool,  ###### TAKE THEM OUT OF HERE, ADD AFTER CLASS IS DEFINED
        #    proj_manager_website_tool, 
        #    proj_manager_youtube_tool, 
        #    proj_manager_scrape_tool,
        #    ],
    llm=llm,
    function_calling_llm=None,
    max_iter=15,  # Optional, default is 25
    max_rpm=None, # Optional
    verbose=True,  # Optional
    allow_delegation=True,  # Optional
    step_callback=None,  # Optional
    cache=True,  # Optional
)
project_manager.tools.append(proj_manager_dir_tool)
project_manager.tools.append(proj_manager_website_tool)
project_manager.tools.append(proj_manager_youtube_tool)
project_manager.tools.append(proj_manager_scrape_tool)
windowshopr commented 1 month ago

Actually I spoke too soon. Doing that only delayed the same error until the crew.kickoff() call. It's still saying key error 'tools'. When I take out ALL tools from the script, the code runs fine, so I think there's an issue linking crewai and langchain by their tools. Will require more investigating.

pxb1000 commented 1 month ago

@windowshopr I'm getting the same KeyError for projects where I have separate main, agents, tasks, and tools modules/files, but finally got it to work in having it all in main.

I have the same error ending in:

    tools = values["tools"]
KeyError: 'tools'

But when using a single main.py file, this is what has worked, for example for a search tool....

Include "tool" on your imports:

from crewai_tools import SerperDevTool, tool
from langchain.tools import tool

Create an instance for your tool before Agents, Tasks, etc...

search_tools = SerperDevTool()

Use the @tool decorator followed by the tool method:

@tool('search_tools')
def search(query: str, num_results = 5):
    """Search the web for information on a given topic"""
    response = SerperDevTool().run(query, num_results=num_results)
    return response

Then call within each agent:

tools = [search_tools]

I'm still trying to debug this KeyError in the case with multiple modules/files.

windowshopr commented 1 month ago

Thanks, but that didn't work for me on my side. I'm running everything out of one file too, I tried your steps like the following, same error:

# TOOLS
# Create an instance for your tool before Agents, Tasks, etc...
project_manager_docs = DirectoryLoader(path="./free_programming_books/project_manager", recursive=True, show_progress=True)

# Use the @tool decorator followed by the tool method:
@tool('project_manager_docs_tool')
def search(query, num_results=5): # Parameters not used
    """Search for project management documentation."""
    response = DirectoryLoader(path="./free_programming_books/project_manager", recursive=True, show_progress=True).load() # load instead of run for directory loader
    return response

# AGENTS
project_manager = Agent(
    role='Project Manager',
    goal='Works directly with the Client and delegates tasks to the team/reports back to the Client',
    backstory=dedent(f"""I am an experienced Project Manager in the software development space with a proven track record of successfully delivering projects. 
                 I excel at creating and maintaining detailed project plans, coordinating team activities, and communicating effectively with stakeholders.
                 I work closely with the client to understand their requirements, and then delegate tasks to the appropriate team members.
                 I report updates back to the client and ask for instructions, feedback and approval as needed by the team and client.
                 I am able to reference all kinds of materials such as books/PDFs, websites, Github repos, videos and search engine results to get the information I need to make informed decisions.
                 My focus is on ensuring the project meets the client's requirements and is delivered to the highest standard of quality."""),
    tools=[project_manager_docs],
    llm=llm,
    max_iter=15,
    verbose=True,
    allow_delegation=True,
    cache=True,
)

#....

It seems clunky that you have to instantiate the tool first, just to redefine it in a tool wrapper later, but I am happy that it works for you! Will need to figure it out on my side. Hopefully someone finds a solution in a similar environment to mine posted in OP. Thanks!

pxb1000 commented 1 month ago

@windowshopr I finally debugged the KeyError in the multi-module format.

I added a "tools" method in my search_tools.py module, and this method calls the SearchTools.search method with the @tool decorator.

    def tools():
        return [SearchTools.search]

    @tool
    def search(query: str, num_results = 5):
        """Search the web for information on a given topic"""
        response = SerperDevTool().run(query, num_results=num_results)
        return response

In the agents.py module I updated tools to point to SearchTools.tools() method.

tools = SearchTools.tools(),

I'm still working through other issues, but it avoids the KeyError. I'm now getting this message in the terminal while the program is running:

" It seems we encountered an unexpected error while trying to use the tool."

pxb1000 commented 1 month ago

@windowshopr After trying a bunch of different versions, this is what finally worked for me in a multi-module setup.

In the search_tools.py module I used a variation of what I showed before. This time I'm instantiating the SerperDevTool within the tools method.


class SearchTools:

    os.environ["SERPER_API_KEY"] = config("SERPER_API_KEY")

    def tools():
        search_tools = SerperDevTool()
        return [search_tools]

    @tool('search_tools')
    def search(query, num_results = 5):
        """Search the web for information on a given topic"""
        response = SerperDevTool.run(query=query, num_results=num_results)
        return response

Interestingly, this seems to mirror the solution in the single-file version (when using main.py only). It seems clunky to first instantiate, but that 's what seems to work with the @tool decorator.

pxb1000 commented 1 month ago

@windowshopr I've been working through a few KeyError issues on other tools, and in looking back at your posts, take another look at the method naming and instance naming.

Here's an abbreviated version of what's worked for me...

# Use the tool decorator and set up tool method
@tool('tool_name')
def method_name(argument_name_if_needed):
    """Description of the tool"""
    response = your function goes here
    return response

# Create an instance
tool_name_instance = method_name

# Create agent
agent_name = Agent(
     tools = [tool_name_instance]
     )
Karb101 commented 3 weeks ago

I've noticed that KeyError: 'tools' was popping out when I include run() method to the tool.

Sample tool code : my_query = "Some query which needs to be looked up in PDF file" pdf_rag_search = PDFSearchTool().run(query=my_query) ##### Invokes KeyError:'tools' pdf_rag_search = PDFSearchTool() ##### runs normally

Sample task code: some_task = Task( description=("some text"), expected_output=("some text"), tools=[pdf_rag_search], agent=sample_agent )

When I execute the crew.kickoff() with necessary inputs, I have encountered "KeyError: 'tools'" and when I've removed the run method from the tool error disappears.

aditya33agrawal commented 3 weeks ago

I've noticed that KeyError: 'tools' was popping out when I include run() method to the tool.

Sample tool code : my_query = "Some query which needs to be looked up in PDF file" pdf_rag_search = PDFSearchTool().run(query=my_query) ##### Invokes KeyError:'tools' pdf_rag_search = PDFSearchTool() ##### runs normally

Sample task code: some_task = Task( description=("some text"), expected_output=("some text"), tools=[pdf_rag_search], agent=sample_agent )

When I execute the crew.kickoff() with necessary inputs, I have encountered "KeyError: 'tools'" and when I've removed the run method from the tool error disappears.

How do you add the pdf file path here?

theCyberTech commented 3 weeks ago

tool = PDFSearchTool(pdf='path/to/your/document.pdf')

aditya33agrawal commented 3 weeks ago

tool = PDFSearchTool(pdf='path/to/your/document.pdf')

I am trying the same way, still the issue persists.

from crewai_tools.tools import PDFSearchTool pdf_search_tool = PDFSearchTool(pdf='../data/CBSE 8 Science.pdf') tools = values["tools"]


KeyError: 'tools'
theCyberTech commented 3 weeks ago

PDFSearchTool

Do you have any agents or tasks that have no tools set like this:

tools = []

if so try removing that line

aditya33agrawal commented 3 weeks ago

y removing that line

I am not using tools in task but using in agents. Example for agent: Please correct the code:

topic_extractor = Agent( role='Topic Extractor', goal='Extract the topic from the pdf', backstory="""You are an expert Topic Extractor, skilled in identifying and isolating key subjects from extensive documents. Your ability to discern relevant topics from a myriad of information helps in creating focused and meaningful content.""", verbose=True, allow_delegation=True, tools=[pdf_search_tool] )

Even implemented like this but still not working: topic_extractor.tools.append(pdf_search_tool)

theCyberTech commented 3 weeks ago

Do your other agents have this configured:

tools = []

aditya33agrawal commented 3 weeks ago

Do your other agents have this configured:

tools = []

Changed all the agents like x.tools.append(abcd)

theCyberTech commented 3 weeks ago

No, remove it if you are not using tools on an agent

anshulbhide commented 6 days ago

I have the same error where I'm trying to define a custom tool - https://github.com/joaomdmoura/crewAI/issues/815

haziq-marvis commented 3 days ago

SOLVED: I had class based tools implemented, I was able to solve this issue by passing the instance of my tool instead of the class: agents.py

class Agents():
    def translator_agent(self):
        return Agent(
            role='Senior Translator',
            goal='Analyze the text and translate it into the target language.',
            tools=[LanguageValidator()],  # This has to be an instance, like this.
            backstory='You are an expert in translating text from one language to another, ensuring accuracy and fluency in the target language.',
            verbose=True
        )

here are my tools: tool.py:

from crewai_tools import BaseTool

class LanguageValidator(BaseTool):
    name: str = "Supported Language Validator"
    description: str = "Used to validate if the language is supported or not."

    def _run(self, language: str) -> str:
        # Implementation goes here
        print("language", language)
        if language == "English" or language == "Urdu":
            return True
        else:
            return False

just for reference, these are my tasks: tasks.py:

from textwrap import dedent
from crewai import Task

class Tasks():
    def translate_user_sentence(self, agent, sentence, target_language):
        return Task(
            description=dedent(f"""Analyze the text: {sentence} and translate it into the target language: {target_language}."""),
            expected_output=dedent(f"""A translated version of the given text: {sentence} in the prefered language: {target_language}."""),
            agent=agent
        )

    def review_translated_sentence(self, agent, sentence, target_language):
        return Task(
            description=dedent(f"""Review the translated version of given sentence: {sentence}\n the target language was: {target_language}, make sure its correct."""),
            expected_output=dedent(f"""A pixel perfect and proof-read translated version of the given text: {sentence} in the prefered language: {target_language}, with no mistakes."""),
            agent=agent
        )

These are my main packages and versions:

crewai==0.35.0
crewai-tools==0.4.0
cryptography==42.0.8
huggingface-hub==0.23.4
langchain==0.1.20
langchain-cohere==0.1.5
langchain-community==0.0.38
langchain-core==0.1.52
langchain-openai==0.1.7
langchain-text-splitters==0.0.2
langsmith==0.1.82
numpy==1.26.4
oauthlib==3.2.2
onnxruntime==1.18.1
openai==1.35.7
opentelemetry-api==1.25.0
tiktoken==0.7.0
tokenizers==0.19.1

I am using Python 3.10.