High severity beginner · Fix: 2-5 min

ImportError / ModuleNotFoundError

builtins.ImportError: cannot import name 'agent' / 'task' / 'crew' from 'crewai.project'

What this error means
CrewAI's @agent, @task, and @crew decorators exist only in crewai>=0.55.0 with CrewBase; older versions or incorrect imports cause ModuleNotFoundError or missing attributes.

Stack trace

traceback
Traceback (most recent call last):
  File "my_crew.py", line 2, in <module>
    from crewai.project import agent, task, crew, CrewBase
ModuleNotFoundError: cannot import name 'agent' from 'crewai.project' (/usr/local/lib/python3.11/site-packages/crewai/project.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "my_crew.py", line 1, in <module>
    from crewai import Agent, Task, Crew, agent, task, crew
ImportError: cannot import name 'agent' from 'crewai' (/usr/local/lib/python3.11/site-packages/crewai/__init__.py)
QUICK FIX
Upgrade to crewai>=0.55.0 with `pip install --upgrade crewai` and change your import from `from crewai import agent, task, crew` to `from crewai.project import agent, task, crew, CrewBase`.

Why it happens

CrewAI introduced the @agent, @task, and @crew decorators and CrewBase class in version 0.55.0 as part of a major refactor to enable class-based crew definitions with method decorators. If you're running crewai<0.55.0, these decorators do not exist in the module. Additionally, the decorators are only available when properly imported from crewai.project after the package has been updated and installed correctly: typos in the import path or importing from the wrong submodule causes Python to raise ImportError.

Detection

Run `pip show crewai` to check your installed version before attempting to use decorators. Add `import crewai; print(crewai.__version__)` at the top of your script to log the version at runtime. Check that your virtual environment is activated and matches the crewai version in requirements.txt.

Causes & fixes

1

crewai version is <0.55.0 and does not include the @agent, @task, @crew decorators

✓ Fix

Upgrade crewai to v0.55.0 or later: `pip install --upgrade crewai>=0.55.0`. Verify with `pip show crewai` and restart your Python interpreter.

2

Importing decorators from wrong submodule (crewai instead of crewai.project)

✓ Fix

Change import from `from crewai import agent, task, crew` to `from crewai.project import agent, task, crew, CrewBase`. The decorators are only exposed in crewai.project.

3

CrewBase class not imported, causing decorator methods to fail or not be recognized

✓ Fix

Always import CrewBase alongside the decorators: `from crewai.project import agent, task, crew, CrewBase`. Your crew class must inherit from CrewBase for decorators to work.

4

Virtual environment is stale or crewai installation is incomplete after pip install

✓ Fix

Deactivate and reactivate your virtual environment. Run `pip install --upgrade --force-reinstall crewai>=0.55.0` to force a clean install. Then restart your Python interpreter and IDE.

Code: broken vs fixed

Broken - triggers the error
python
#!/usr/bin/env python3
# BROKEN: importing decorators from wrong module — crewai<0.55 or wrong import path
from crewai import Agent, Task, Crew, agent, task, crew  # ❌ ImportError: cannot import name 'agent'
from crewai.project import CrewBase
import os

class MyCrew(CrewBase):
    @agent  # ❌ Decorator fails because 'agent' is not imported
    def researcher(self) -> Agent:
        return Agent(
            role="Researcher",
            goal="Research AI topics",
            backstory="Expert researcher",
            llm="gpt-4o-mini"
        )

    @task
    def research_task(self) -> Task:
        return Task(
            description="Research generative AI",
            expected_output="Research summary",
            agent=self.researcher()
        )

if __name__ == "__main__":
    crew = MyCrew().crew()
    crew.kickoff()
Fixed - works correctly
python
#!/usr/bin/env python3
# FIXED: proper imports from crewai.project + CrewBase inheritance (crewai>=0.55.0)
from crewai.project import agent, task, crew, CrewBase  # ✅ Correct: decorators from crewai.project
from crewai import Agent, Task, Crew, Process
import os

class MyCrew(CrewBase):
    """MyCrew crew definition with @agent, @task, @crew decorators."""

    @agent
    def researcher(self) -> Agent:
        return Agent(
            role="Researcher",
            goal="Research AI topics",
            backstory="Expert researcher",
            llm="gpt-4o-mini"
        )

    @task
    def research_task(self) -> Task:
        return Task(
            description="Research generative AI",
            expected_output="Research summary",
            agent=self.researcher()
        )

    @crew
    def crew(self) -> Crew:
        """Create and return the Crew."""
        return Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True
        )

if __name__ == "__main__":
    crew_instance = MyCrew().crew()
    crew_instance.kickoff()
    print("Crew execution completed successfully.")
Changed the import statement to explicitly import @agent, @task, @crew from crewai.project (not from crewai), ensured the class inherits from CrewBase, and added the @crew decorator method to define the Crew instance properly for crewai>=0.55.0.

Workaround

If you cannot upgrade crewai immediately, use the pre-0.55 Task/Agent/Crew pattern without decorators: define Agent and Task objects directly, then pass them to Crew() without using @agent/@task/@crew decorators. Create a Crew instance with `crew = Crew(agents=[...], tasks=[...])` and call `crew.kickoff()`. This works on all versions but lacks the cleaner decorator syntax and CrewBase class organization.

Prevention

Lock your crewai version in requirements.txt to >=0.55.0 to ensure all team members and CI/CD environments use the decorator-enabled version. Add a version check at the top of your crew entry point: `import crewai; assert crewai.__version__ >= '0.55.0', f'crewai>=0.55.0 required, got {crewai.__version__}'`. Use type hints and IDE autocomplete (which will fail on wrong imports) to catch import mistakes before runtime.

Python 3.9+ · crewai >=0.55.0 · tested on 0.55.x, 0.56.x, 0.57.x
Verified 2026-04 · gpt-4o-mini, claude-3-5-haiku-20241022
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.