Skip to content

KeyError: 'tools' #574

@windowshopr

Description

@windowshopr

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}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions