Dynamic Agent Selection in CrewAI: Enhancing Efficiency Without Hardcoding

I’ve been working on an AI application that uses CrewAI for various tasks, such as analyzing data, managing schedules, and more. However, I’ve encountered a challenge in dynamically selecting and running only the agents relevant to the user’s query. the user enters a query, and the crew should use only related agents and tasks

Currently, when using the Crew class, all agents are initialized and executed, even if only one or two are needed for a specific task. I want to implement a seamless way to dynamically select agents based on the query’s intent without resorting to hardcoding the logic.

Here’s what I’m aiming for:

  1. Analyze the user query to determine the intent (e.g., data analysis, scheduling).
  2. Dynamically select the relevant agents for that intent.
  3. Pass only the selected agents and their tasks to the Crew instance.

I’ve tried creating a mapping between intents and agents, but it feels cumbersome and not as elegant as I’d like. I’m curious to know if anyone has implemented a similar solution or if there’s a built-in way in CrewAI to handle this efficiently.