How to instantiate multiple crews in a single flow?

I am trying to build a multi-crew system which will be coordinated by a manager flow, but on running the flow i am getting errors that selected crew is returning a empty crew, i.e no agent or tasks even listed in it let alone user’s input.

pydantic_core.\_pydantic_core.ValidationError: 1 validation error for Crew
Either ‘agents’ and ‘tasks’ need to be set or ‘config’. \[type=missing_keys, input_value={‘agents’: [ ], ‘tasks’: \[…: True, ‘memory’: False}, input_type=dict\]

crew itself is running fine on its own, problem only arises when i try to run it from the flow.

Directory structure is something like this,
Crew’s directory structure is same as default when creating with, crewai create crew1

  • crew1/src/crew1/crew.py
  • Manager/manager/src/manager/main.py
crew_collection: Dict[str, Crew | Flow] = {
        "crew1" : Crew_class1,
        "crew2" : Crew_class2,
        "crew3 : Crew_class3,
        "crew4" : Crew_class4
    }
selected_crew = crew_collection[current_crew]()
crew_instance = selected_crew.crew()
result = crew_instance.kickoff(inputs={"content" : curr_input})

Any kind of input will be very appreciated.
Thank you

Welcome to the community

Try using the inbuilt flow Flows - CrewAI

I am using builtin flows, but the problem is actually related to config paths, since each crew has its own configs in a separate folder than flow.py, because of that crews instantiated in flow.py are not able to access configs. I even tried hardcoding the absolute config path in the crews but i still get the same error.

@Dkain Try this:
When you instantiate crews from your flow, the config paths (config/agents.yaml, config/tasks.yaml) are resolved relative to the crew’s own directory.

Solution:

  1. Ensure each crew uses the @CrewBase decorator - This is required for config loading to work properly.

  2. The config paths in your crew classes should be relative to the crew.py file location, not the flow. The @CrewBase decorator automatically looks for configs beside the class file.

  3. For multi-crew flows, use the recommended project structure:

    Manager/
    └── src/
        └── manager/
            ├── main.py          # Your flow
            └── crews/
                ├── crew1/
                │   ├── crew1.py  # @CrewBase class
                │   └── config/
                │       ├── agents.yaml
                │       └── tasks.yaml
                └── crew2/
                    └── ...
    
  4. In your crew classes, keep the default config paths:

    @CrewBase
    class Crew1:
        agents_config = 'config/agents.yaml'
        tasks_config = 'config/tasks.yaml'
    

**@CrewBase**looks for config files beside the class file and safely falls back to empty dicts if files are missing (which explains your empty agents/tasks).

Move your crews into a crews/ folder inside your flow project, or ensure the config paths are correctly relative to each crew’s .py file location.