Closed windowshopr closed 3 months 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
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
@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
@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'
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],
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'
@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 "
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
The same issue persists. It's a logic issue not a dependency issue.
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
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
)
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
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)
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.
@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.
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!
@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."
@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.
@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]
)
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.
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?
tool = PDFSearchTool(pdf='path/to/your/document.pdf')
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'
PDFSearchTool
Do you have any agents or tasks that have no tools set like this:
tools = []
if so try removing that line
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)
Do your other agents have this configured:
tools = []
Do your other agents have this configured:
tools = []
Changed all the agents like x.tools.append(abcd)
No, remove it if you are not using tools on an agent
I have the same error where I'm trying to define a custom tool - https://github.com/joaomdmoura/crewAI/issues/815
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.
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.
This issue was closed because it has been stalled for 5 days with no activity.
Environment
Code
Error traceback
Other Notes