# Crewai run getting keyerror for newly defined task and agents

**URL:** <https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754>\
**Category:** CrewAI Community Support\
**Tags:** tools\_issues, agent, task, crewai\
**Created:** [March 17, 2025, 10:54am UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754 "2025-03-17T10:54:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devdatta\_Jadhav](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/devdatta_jadhav/32/945_2.png) [@Devdatta\_Jadhav](https://community.crewai.com/u/Devdatta_Jadhav)\
**Post date:** [March 17, 2025, 10:54am UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/1 "2025-03-17T10:54:07Z")

</div>

Hello,  
I install crewai and uv as mentioned in the crewai docs quickstart and then created the crewai project using “crewai create crew latest-ai-development”  
then executed “crewai run”. Which executed the run and the crew started showing result. Then I added only one new task and agent in config file and in same format as previous. But the extra thing is only that I added tools for agent. Then I kickoff the crew by running crewai run and its asked me to install databricks and databricks-sdk. So I did it by uv add databricks. After that I executed crew run again and started getting error as below,  
Traceback (most recent call last):  
File “/home/intellih/F11/latest\_ai\_development/.venv/bin/run\_crew”, line 10, in   
sys.exit(run())  
File “/home/intellih/F11/latest\_ai\_development/src/latest\_ai\_development/main.py”, line 21, in run  
LatestAiDevelopment().crew().kickoff(inputs=inputs)  
File “/home/intellih/F11/latest\_ai\_development/.venv/lib/python3.10/site-packages/crewai/project/utils.py”, line 11, in memoized\_func  
cache[key] = func(\*args, \*\*kwargs)  
File “/home/intellih/F11/latest\_ai\_development/.venv/lib/python3.10/site-packages/crewai/project/annotations.py”, line 95, in wrapper  
task\_instance = task\_method(self)  
File “/home/intellih/F11/latest\_ai\_development/.venv/lib/python3.10/site-packages/crewai/project/utils.py”, line 11, in memoized\_func  
cache[key] = func(\*args, \*\*kwargs)  
File “/home/intellih/F11/latest\_ai\_development/.venv/lib/python3.10/site-packages/crewai/project/annotations.py”, line 28, in wrapper  
result = func(\*args, \*\*kwargs)  
File “/home/intellih/F11/latest\_ai\_development/src/latest\_ai\_development/crew.py”, line 61, in Player\_research\_task  
config=self.tasks\_config[‘Player\_research\_task’],  
KeyError: ‘Player\_research\_task’  
An error occurred while running the crew: Command ‘[‘uv’, ‘run’, ‘run\_crew’]’ returned non-zero exit status 1.

I removed the tools mentioned in agent but that did not work. I double checked if anything is missing but everything is same as tasks and agents mentioned in default structure.

Anybody else facing same kind of issue or have solution for this ?

---

<div class="post-metadata">

**Author:** ![zinyando](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/zinyando/32/4435_2.png) [@zinyando](https://community.crewai.com/u/zinyando)\
**Post date:** [March 17, 2025, 12:47pm UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/2 "2025-03-17T12:47:54Z")

</div>

Are you sure you are using the same key for the task as defined in the yaml file. Make sure the capitalisation is the same.

You can share the task and agent definitions as well as the crew definition code here too. It might give better context for people to help you.

---

<div class="post-metadata">

**Author:** ![Devdatta\_Jadhav](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/devdatta_jadhav/32/945_2.png) [@Devdatta\_Jadhav](https://community.crewai.com/u/Devdatta_Jadhav)\
**Post date:** [March 17, 2025, 4:35pm UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/3 "2025-03-17T16:35:26Z")

</div>

Yes, I checked the config and its correct. Sharing here the config files and crew

**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.

reporting\_analyst:  
role: \>  
{topic} Reporting Analyst  
goal: \>  
Create detailed reports based on {topic} data analysis and research findings  
backstory: \>  
You’re a meticulous analyst with a keen eye for detail. You’re known for  
your ability to turn complex data into clear and concise reports, making  
it easy for others to understand and act on the information you provide.

Player\_Researcher:  
role: \>  
The best Cricket Player Researcher  
goal: \>  
Being the best Cricket Player Researcher in gathering, interpret cricket and players related data  
backstory: \>  
Known the Best CRICKET SPORT PLAYER researcher, you’re skilled researcher who have fine knowledge of cricket and research the individual player

**tasks.yaml**

research\_task:  
description: \>  
Conduct a thorough research about {topic}  
Make sure you find any interesting and relevant information given  
the current year is 2024.  
expected\_output: \>  
A list with 10 bullet points of the most relevant information about {topic}  
agent: researcher

reporting\_task:  
description: \>  
Review the context you got and expand each topic into a full section for a report.  
Make sure the report is detailed and contains any and all relevant information.  
expected\_output: \>  
A fully fledge reports with the mains topics, each with a full section of information.  
Formatted as markdown without ‘```’  
agent: reporting\_analyst

Player\_research\_task:  
description: \>  
Collect the personal details such as DOB, Origin Country, age, Height, Role in Team, Batting Style, Bowling Style, etc. for {player}

expected\_output: \>  
Your final answer MUST be a detailed report of all gathered information for {player}

agent: Player\_researcher  
#async\_execution: true

**crew.py**

from crewai import Agent, Crew, Process, Task  
from crewai.project import CrewBase, agent, crew, task  
#from crewai\_tools import ScrapeWebsiteTool, WebsiteSearchTool, SerperDevTool

#Uncomment the following line to use an example of a custom tool  
#from latest\_ai\_development.tools.custom\_tool import MyCustomTool

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

@CrewBase  
class LatestAiDevelopment():  
“”“LatestAiDevelopment crew”“”

```
agents_config = 'config/agents.yaml'
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 reporting_analyst(self) -> Agent:
	return Agent(
		config=self.agents_config['reporting_analyst'],
		verbose=True
	)

@agent
def Player_Researcher(self) -> Agent:
	return Agent(
        config=self.agents_config['Player_Researcher'],
        memory=True,
        #tools=[ScrapeWebsiteTool(), WebsiteSearchTool(), SerperDevTool()],
        verbose=True,
        #allow_delegation=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'
	)

@task
def Player_research_task(self) -> Task:
	return Task(
        config=self.tasks_config['Player_research_task'],
        agent=self.Player_Researcher(),
        #async_execution=True,
        output_file='player_research.txt'
    )

@crew
def crew(self) -> Crew:
	"""Creates the LatestAiDevelopment 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/
	)

```

---

<div class="post-metadata">

**Author:** ![zinyando](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/zinyando/32/4435_2.png) [@zinyando](https://community.crewai.com/u/zinyando)\
**Post date:** [March 17, 2025, 5:05pm UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/4 "2025-03-17T17:05:08Z")

</div>

Your issue is in the naming differences in your task definition in yaml and the agent name you declared in the crew.py

```auto
Player_research_task:
description: >
Collect the personal details such as DOB, Origin Country, age, Height, Role in Team, Batting Style, Bowling Style, etc. for {player}
expected_output: >
  Your final answer MUST be a detailed report of all gathered information for {player}
agent: Player_researcher
#async_execution: true

```

```auto
@agent
def Player_Researcher(self) -> Agent:
	return Agent(
        config=self.agents_config['Player_Researcher'],
        memory=True,
        #tools=[ScrapeWebsiteTool(), WebsiteSearchTool(), SerperDevTool()],
        verbose=True,
        #allow_delegation=True
    )

```

Your agent is named `Player_Researcher` but your task has agent `Player_researcher`. Your crew.py task also has an agent assigned

```auto
@task
def Player_research_task(self) -> Task:
	return Task(
        config=self.tasks_config['Player_research_task'],
        agent=self.Player_Researcher(),
        #async_execution=True,
        output_file='player_research.txt'
    )

```

Delete the agent from crew.py `Player_research_task` and fix the agent name in your yaml file task definition and it should work.

---

<div class="post-metadata">

**Author:** ![Devdatta\_Jadhav](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/devdatta_jadhav/32/945_2.png) [@Devdatta\_Jadhav](https://community.crewai.com/u/Devdatta_Jadhav)\
**Post date:** [March 18, 2025, 6:53am UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/5 "2025-03-18T06:53:15Z")

</div>

Thanks, I corrected it and it worked.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/1X/ecda97e72f77c7100e0a761444b1c991925cc789.png) [@system](https://community.crewai.com/u/system)\
**Post date:** [March 19, 2025, 6:54am UTC](https://community.crewai.com/t/crewai-run-getting-keyerror-for-newly-defined-task-and-agents/4754/6 "2025-03-19T06:54:17Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
