Error: [EventBus Error] Handler 'on_task_started' failed for event 'TaskStartedEvent': 'NoneType' object has no attribute 'key'

I get this error when I run my crew. I have reviewed tasks.yaml and agents.yaml and everything seems correct.

Any ideas?

1 Like

You should really provide a minimal reproducible example (a complete, concise example that isolates your problem), so that others can test your code and provide any feedback.

1 Like

I had the same issue when trying to run a single task, instead of the whole crew. Or when trying to rerun the last task with `crewai run -t .

What seemed to help me was adding the following:

def run():

    """

    Run the crew.

    """

try:

        crew = LatestAiDevelopment().crew()




# Run ONLY first task for testing

        task_1 = crew.tasks[0]  # internal_knowledge_analysis

# CRITICAL FIX: For single task execution, we must manually link agents to the crew

# This is normally handled by crew.kickoff(), but we are bypassing it.

# Without this, telemetry fails with "'NoneType' object has no attribute 'key'"

for agent in crew.agents:

            agent.crew = crew




        result = task_1.execute_sync(context="")




print("\n" + "="*80)

print("TEST COMPLETED - Task 1 only")

print("="*80)

print(f"Output file: {task_1.output_file}")

print(f"Output length: {len(str(result)) if result else 0} chars")




# Check cost (estimate)

print("\nEstimated cost: ~$2-5 for this single task")




except Exception as e:

raise Exception(f"An error occurred: {e}")