Context sharing in hierarchical mode

Hello team,
And nice to meet you as I’m new here.
I’m discovering the crew AI magic :heart_eyes:

I have a crew with 2 agents:

  • file_transformation_developer
  • code_checker, that has a custom tool to execute code on an online sandbox.

I have 2 related tasks:

  • code_development
  • code_check

When using sequential process, the code works perfectly. The developer generates python code, that is then executed by the code checker.

Now I want to build a hierarchical process.
I’ve built a team lead manager. This manager first delegate the code generation to the code developer. Then, the code is tested by the code checker.
:exploding_head: However, at this point, the code checker always generates it’s own code.
I’ve put clear, upper letters instructions in agent config for code_checker agent not to generate it’s own code.
I think the problem is, the code_checker don’t get the output of the code developper.

Thanks a lot for your help,

Best,

Marc

crew.py :arrow_down:

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from flow.tools import code_executor

@CrewBase
class FileTransformationCodingCrew():
	"""File Transformation Coding Crew"""

	agents_config = 'config/agents.yaml'
	tasks_config = 'config/tasks.yaml'

	@agent
	def file_transformation_developer_team_lead(self) -> Agent:
		return Agent(
			config=self.agents_config['file_transformation_developer_team_lead'],
			verbose=True,
			memory=True,
			allow_code_execution=False,
		)
	
	@agent
	def file_transformation_developer(self) -> Agent:
		return Agent(
			config=self.agents_config['file_transformation_developer'],
			verbose=True,
			memory=True,
			allow_code_execution=False,
			allow_delegation=False,

		)
	
	@agent
	def code_checker(self) -> Agent:
		return Agent(
			config=self.agents_config['code_checker'],
			verbose=True,
			memory=True,
			tools=[code_executor.code_executor],
			allow_code_execution=True,
			allow_delegation=False,

		)

	@task
	def code_development(self) -> Task:
		return Task(
			config=self.tasks_config['code_development'],
		)

	@task
	def code_check(self) -> Task:
		return Task(
			config=self.tasks_config['code_check'],
			context=[self.code_development()]
		)

	@crew
	def crew(self) -> Crew:
		"""Creates the File Transformation Coding Crew"""
		return Crew(
			process=Process.hierarchical,
			agents=[self.file_transformation_developer(), self.code_checker()],
			manager_agent=self.file_transformation_developer_team_lead(),
			tasks=self.tasks,
			memory=False,
			verbose=True,
		)

tasks.yaml :arrow_down:

code_development:
  description: >
    Write the python script as per the specifications. Testing the script is not part of this task.
  expected_output: >
    The final answer must be the full python code, only the python code and nothing else.
  agent: file_transformation_developer
code_check:
  description: >
    Execute the code built in the code_development task. Check for errors in the execution, validates output files against specifications.
  expected_output: >
    Report on any bugs or issues, and confirmation that the expected output files are created.
  agent: code_checker

Is your managing agent actually able to communicate with your other agents? I have much the same code as you, but the managing agent isn’t even able to communicate with the other agents, let alone pass data.

Have you tried changing to memory=True in the crew instantiation? That might be overriding the individual agents.

Thanks for your answer. I’ve tried to put the crew memory at True, without success… :confused:

I am also facing the same problem,Sequential is working well but heirarchical is not working as expected

1 Like

Hello team,
Would any of you have an answer for my problem for which i still haven’t found any solution ?
Thanks a lot,
Best,
Marc

Hi, check this project: crewai-updated-tutorial-hierarchical/tasks.py at main · bhancockio/crewai-updated-tutorial-hierarchical · GitHub

As you can see task has agent as parameter. If task doesn’t have designated agent there is a chance that coding task is picked by wrong one resulting in your issue.