TaskOutput not formatted as expected
We're running a crew and want to output the result of each task to a Streamlit UI.
We're using the task_callback parameter with the crew, but there were two issues that tripped us up:
- The TaskOutput type is not exported in the
__init__file for tasks, we put it there manually for now and use that to type the expected object coming into the callback handler. (Also helps to know what fields are expected!)
https://github.com/joaomdmoura/crewAI/blob/a3363818498893012be970164a119068b723a402/src/crewai/tasks/task_output.py#L6-L15
- The agent name is not being passed in our code, there is no entry as defined in the code above.
I am getting a similar error when running a crew consisting of 4 agents and 5 tasks. It seems that there may be a problem with task.output's format. For reference, this is the exact error I am getting:
\Lib\site-packages\crewai\task.py", line 93, in execute
context.append(task.output.result)
^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'result'
And the function execute that gets accessed is the following:
def execute(
self,
agent: Agent | None = None,
context: Optional[str] = None,
tools: Optional[List[Any]] = None,
) -> str:
"""Execute the task.
Returns:
Output of the task.
"""
agent = agent or self.agent
if not agent:
raise Exception(
f"The task '{self.description}' has no agent assigned, therefore it can't be executed directly and should be executed in a Crew using a specific process that support that, like hierarchical."
)
if self.context:
context = []
for task in self.context:
if task.async_execution:
task.thread.join()
context.append(task.output.result)
context = "\n".join(context)
tools = tools or self.tools
if self.async_execution:
self.thread = threading.Thread(
target=self._execute, args=(agent, self, context, tools)
)
self.thread.start()
else:
result = self._execute(
task=self,
agent=agent,
context=context,
tools=tools,
)
return result
I would like to ask for some help here. I can provide more information or context, if needed.
If it's a TaskOutput class like what's defined above you'd want task.output.raw_output I believe, but I also don't see where you have the same type of callback set, what I'm describing the issue is when you pass a function to task_callback on the crew configuration.
For the code above, what does task.output look like if you print it? I'd start there to see the object shape then try to find the related class in the crewAI code.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.