How to access the output of a specific agent within a Process.hierarchical before executing the other agents in the chain?

Currently I am working on implementing a system of several agents executing several tasks in a chain through Process.hierarchical , at the end of the task of the first agent I wanted to take its result and pass it to a function to do something and then continue executing the others agents, I found a parameter " callback=
" that the task can receive, which simply executes a function after executing the specific task, but I need to pass the result from the agent that performed this task to this function, how do I get this result only from this first agent while the others will still be executed in chain?

If you can’t get the agent’s response in the middle of the chain execution, I would like to know if there is a way to get the response from a single specific agent at the end?

Hi Marcos, Right now, an option is to run the exact crew, but we can fetch the output from a single task. This is a example:-

Example task

task = Task(
description=‘Find and summarize the latest AI news’,
expected_output=‘A bullet list summary of the top 5 most important AI news’,
agent=research_agent,
tools=[search_tool]
)

Execute the crew

crew = Crew(
agents=[research_agent],
tasks=[task],
verbose=True
)

result = crew.kickoff()

Accessing the task output

task_output = task.output

  • You can return the ‘task_output.json_dict’ if it’s within a function.
1 Like