Error Loading the Tool from yaml file

Hi All, This is my first question post, so if something is not as expected, please let me know. Do not want to violate some rules :slight_smile:

I have the following agents.yaml

researcher:
  role: >
    {topic} Senior Data Researcher
  goal: >
    Uncover cutting-edge developments in {topic}
  backstory: >
    You're a seasoned researcher with a knack for uncovering the latest
    developments in {topic}. Known for your ability to find the most relevant
    information and present it in a clear and concise manner.
  tools: 
    - "search_tool"

and this is the tool

from typing import Type
from crewai_tools import BaseTool
from pydantic import BaseModel, Field

class MyCustomToolInput(BaseModel):
    """Input schema for MyCustomTool."""
    argument: str = Field(..., description="Description of the argument.")

class MyCustomTool(BaseTool):
    name: str = "search_tool"
    description: str = (
        "Clear description for what this tool is useful for, you agent will need this information to use it."
    )
    args_schema: Type[BaseModel] = MyCustomToolInput

    def _run(self, argument: str) -> str:
        # Implementation goes here
        return "this is an example of a tool output, ignore it and move along."

and this is my crew.py

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from crewaiexample.helpers import AgentFactory1
from crewaiexample.tools import MyCustomTool
import os


# Uncomment the following line to use an example of a custom tool
# from crewaiexample.tools.custom_tool import MyCustomTool

# Check our tools documentations for more information on how to use them
# from crewai_tools import SerperDevTool

@CrewBase
class Crew1():
	"""Crewaiexample crew"""

	def __init__(self):
		self.agents_config = 'configs/agents.yaml'
		self.tasks_config = 'config/tasks.yaml'


	@agent
	def researcher(self) -> Agent:
		return Agent(
			config=self.agents_config['researcher'],
			tools=[MyCustomTool()], # Example of custom tool, loaded on the beginning of file
			verbose=True
		)
	
    # @agent
	# def researcher(self, base_dir: str) -> Agent:
	# 	agent_config_path = os.path.join(base_dir, 'config', 'agents.yaml')
	# 	return AgentFactory1.create_agent(agent_config_path, 'researcher')


	@agent
	def reporting_analyst(self) -> Agent:
		return Agent(
			config=self.agents_config['reporting_analyst'],
			verbose=True
		)
	
	@task
	def research_task(self) -> Task:
		return Task(
			config=self.tasks_config['research_task'],
		)

	@task
	def reporting_task(self) -> Task:
		return Task(
			config=self.tasks_config['reporting_task'],
			output_file='report.md'
		)

	@crew
	def crew(self) -> Crew:
		"""Creates the Crewaiexample crew"""
		return Crew(
			agents=self.agents, # Automatically created by the @agent decorator
			tasks=self.tasks, # Automatically created by the @task decorator
			process=Process.sequential,
			verbose=True,
			# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
		)

after executing, I am getting this error:

Running the Crew
warning: `VIRTUAL_ENV=/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/venv-crewai-example-p3.11` does not match the project environment path `.venv` and will be ignored
Traceback (most recent call last):
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/.venv/bin/run_crew", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/src/crewaiexample/main.py", line 19, in run
    SupaCrew().crew().kickoff(inputs=inputs)
    ^^^^^^^^^^
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/.venv/lib/python3.11/site-packages/crewai/project/crew_base.py", line 34, in __init__
    self.map_all_agent_variables()
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/.venv/lib/python3.11/site-packages/crewai/project/crew_base.py", line 85, in map_all_agent_variables
    self._map_agent_variables(
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/.venv/lib/python3.11/site-packages/crewai/project/crew_base.py", line 112, in _map_agent_variables
    self.agents_config[agent_name]["tools"] = [
                                              ^
  File "/Users/damirkusar/Documents/Coding/damirAI/examples/crewAi/crewaiexample/.venv/lib/python3.11/site-packages/crewai/project/crew_base.py", line 113, in <listcomp>
    tool_functions[tool]() for tool in tools
    ~~~~~~~~~~~~~~^^^^^^
KeyError: 'search_tool'
An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

I think the tool reference in the agent yaml needs to match the tool class name MyCustomTool, not the tool name search_tool:

agents.yaml

researcher:
tools:
- “MyCustomTool” # This needs to match the class name

I have de same proproblem defining tools in YAML File and load with
self.tasks_config or self.agents_config. If I define tools=[MyCustomTool()] in crewai.py it work. However, this must be to differents approach in my opinion.

Looks like you are very close to a working model. Try replacing the last two lines in your Agents yaml file
tools:
- "search_tool"
with
llm: azure/gpt-4o-mini
replacing with whatever llm you are using. If you don’t want to assign a llm to this agent just leave that line blank. Since you have the tool listed properly for the agent in crew.py, it does not need to be listed in the Agents.yaml file.
Good luck and let me know if this works.