Hi everyone!
I’m currently studying how to use a custom LLM manager in a hierarchical setup, and I’ve been experimenting with an implementation based on the official documentation.
In my exercise, I created a manager agent that coordinates two other agents.
Here’s the code:
from crewai import Agent, Task, Crew, Process
from crewai.project import CrewBase, agent, task, crew
from dotenv import load_dotenv
@CrewBase
class ProductionCrew():
def __init__(self):
load_dotenv("../.env")
@agent
def creative_agent(self) -> Agent:
return Agent(
config=self.agents_config["creative_agent"],
#verbose=True
)
@agent
def budget_agent(self) -> Agent:
return Agent(
config=self.agents_config["budget_agent"],
#verbose=True
)
@agent
def manager_agent(self) -> Agent:
return Agent(
config=self.agents_config["manager_agent"],
#verbose=True,
allow_delegation=True
)
@task
def concept_task(self) -> Task:
return Task(
config=self.tasks_config["concept_task"]
)
@task
def budget_task(self) -> Task:
return Task(
config=self.tasks_config["budget_task"]
)
@crew
def crew(self) -> Crew:
return Crew(
agents=[self.creative_agent(), self.budget_agent()],
tasks=[self.concept_task(), self.budget_task()],
manager_agent=self.manager_agent(),
process=Process.hierarchical,
verbose = True
)
def run(self):
try:
self.crew().kickoff()
except:
raise Exception(f"Errore durante l'esecuzione della crew: {e}")
agents.yaml
creative_agent:
role: >
Creative Writer
goal: >
Come up with an original concept for a short film
backstory: >
Experienced screenwriter with a background in independent cinema.
llm: together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo-Free
temperature: 0.7
budget_agent:
role: >
Film Budget Analyst
goal: >
Estimate the budget for the production of the short film
backstory: >
Specialist in film production with a focus on cost control.
llm: together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo-Free
temperature: 0.7
manager_agent:
role: >
Production Manager
goal: >
Coordinate pre-production and present a complete package
backstory: >
Production manager with experience in complex film projects.
llm: together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo-Free
temperature: 0.7
tasks.yaml
concept_task:
description: >
Write an original synopsis for a short film. Include: theme, brief plot, setting, and main characters.
expected_output: >
Synopsis and setting, maximum 300 words
agent: creative_agent
budget_task:
description: >
Estimate a rough budget to produce the short film, considering: cast, location, visual effects, equipment, and post-production.
expected_output: >
Summary table with items and estimated costs
agent: budget_agent
In the documentation, the example shows a single task shared between two agents, while I’ve taken a different approach by assigning a specific task to each agent. Also, in the docs, the task isn’t explicitly assigned to any agent, whereas I’ve done so directly in my code.
I’d love to get some clarification on a few points:
- Is it a good practice to assign tasks explicitly to individual agents in a hierarchical structure with a custom manager?
- What are the best practices in this kind of setup? Should tasks be kept generic and let the manager decide who handles them?
- When using a custom LLM manager, how much autonomy should it have in assigning and managing tasks?
Any insights or suggestions would be greatly appreciated!
Thanks in advance
Edit:
Additionally, the output I was expecting was a combination of the work done by both agents—that is, the movie plot and a cost estimate.
However, the output I’m getting from the crew includes only the cost estimate.
Expected output:
Title: ...
Plot: ...
Estimated Costs: ...
Actual output:
| Category | Estimated Cost |
|------------------|------------------------|
| Cast | $25,000 - $55,000 |
| Location | $15,000 - $30,000 |
| Visual Effects | $17,000 - $35,000 |
| Equipment | $12,000 - $24,000 |
| Post-Production | $18,000 - $36,000 |
| Total Budget | $87,000 - $180,000 |
Edit 2:
Another question is: does it make sense to create a task for the manager? Or is it correct to leave the manager without any tasks?