I am going to build an app using CrewAI in python
I already built a crew and then add agents list, task list and step_callback function.
I would like to get detailed agent info(role, …) and detailed task info from callback function whenever event(ToolResult, AgentAction, TaskOutput) has happened
Well, the argument passed to the task_callback function is an object of the TaskOutput class. The attributes of this class are documented here.
As for the argument passed to the step_callback function, it will vary depending on the step that was completed. It can be an object of the ToolResult, AgentAction, or AgentFinish class. That’s why I suggested earlier that a well-defined event listener might be better suited for your use case.
In any case, to learn more about the argument your callback is receiving, here’s a snippet:
from crewai import LLM, Agent, Task, Crew, Process
from typing import Any
# [Define your Agents, Tasks, Tools, etc.]
def log_task_output(task_output: Any):
print("\n--- Task Callback Received ---")
if task_output is not None:
print(f"Object type: {type(task_output).__name__}")
attributes = getattr(
task_output, "__dict__", "N/A (object may lack __dict__)"
)
print(f"Instance attributes: {attributes}")
else:
print("Received None object.")
def log_step_output(step_output: Any):
print("\n--- Step Callback Received ---")
if step_output is not None:
print(f"Object type: {type(step_output).__name__}")
attributes = getattr(
step_output, "__dict__", "N/A (object may lack __dict__)"
)
print(f"Instance attributes: {attributes}")
else:
print("Received None object.")
my_crew = Crew(
agents=[...],
tasks=[...],
process=Process.sequential,
task_callback=log_task_output,
step_callback=log_step_output,
verbose=False
)
my_crew.kickoff()