Generating Agents and Tasks files dynamically

Although it might not perfectly achieve your goal, I believe it’s worth exploring the Planning feature. As stated in the docs:

The planning feature in CrewAI allows you to add planning capability to your crew. When enabled, before each Crew iteration, all Crew information is sent to an AgentPlanner that will plan the tasks step by step, and this plan will be added to each task description.

To enable planning, you need to set the following parameters:

  • planning: Set to True
  • planning_llm: Assign a specific LLM you would like to use.

Here’s a code example:

from crewai import Crew, Agent, Task, Process, LLM

my_crew = Crew(
    agents=self.agents,
    tasks=self.tasks,
    process=Process.sequential,
    planning=True,
    planning_llm=LLM(model="anthropic/claude-3-5-sonnet-20241022"),
)