From fffe4df8c3af5fc75c4f325d7872ae270b5acecb Mon Sep 17 00:00:00 2001 From: Brandon Hancock Date: Mon, 8 Jul 2024 20:04:27 -0400 Subject: [PATCH] WIP --- src/crewai/crew.py | 2 +- src/crewai/crews/crew_output.py | 12 ++++++++++++ src/crewai/tasks/task_output.py | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 5a1fc87fe..0fd1170f4 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -459,7 +459,7 @@ class Crew(BaseModel): self._file_handler.log( agent=role, task=task.description, status="started" ) - + # TODO: IF USER OVERRIDE THE CONTEXT, PASS THAT if task.async_execution: context = aggregate_raw_outputs_from_task_outputs(task_outputs) future = task.execute_async( diff --git a/src/crewai/crews/crew_output.py b/src/crewai/crews/crew_output.py index 018fc76ff..2a997af60 100644 --- a/src/crewai/crews/crew_output.py +++ b/src/crewai/crews/crew_output.py @@ -8,6 +8,7 @@ from crewai.utilities.formatter import aggregate_raw_outputs_from_task_outputs class CrewOutput(BaseModel): output: List[TaskOutput] = Field(description="Result of the final task") + # TODO: TYPED OUTPUT tasks_output: list[TaskOutput] = Field( description="Output of each task", default=[] ) @@ -15,14 +16,24 @@ class CrewOutput(BaseModel): description="Processed token summary", default={} ) + # TODO: Support 1 output by default + # TODO: GIVE THEM THE OPTION TO ACCESS + # TODO: RESULT get's back a string + # TODO: Ask @joao what is the desired behavior here def result( self, ) -> List[str | BaseModel | Dict[str, Any]]: """Return the result of the task based on the available output.""" + if len(self.output) == 1: + return self.output[0].result() + results = [output.result() for output in self.output] return results + # TODO: RESULT PYDANTIC + # TODO: RESULT JSON D + def raw_output(self) -> str: """Return the raw output of the task.""" return aggregate_raw_outputs_from_task_outputs(self.output) @@ -41,4 +52,5 @@ class CrewOutput(BaseModel): # TODO: Confirm with Joao that we want to print the raw output and not the object def __str__(self): + # TODO: GRAB LAST TASK AND CALL RESULT ON IT. return str(self.raw_output()) diff --git a/src/crewai/tasks/task_output.py b/src/crewai/tasks/task_output.py index 8dc50b0ae..633e10fc9 100644 --- a/src/crewai/tasks/task_output.py +++ b/src/crewai/tasks/task_output.py @@ -7,6 +7,8 @@ from pydantic import BaseModel, Field, model_validator class TaskOutput(BaseModel): """Class that represents the result of a task.""" + # TODO: MAKE SURE TO FULLY SUPPORT OUTPUT FILE + description: str = Field(description="Description of the task") summary: Optional[str] = Field(description="Summary of the task", default=None) raw_output: str = Field(description="Result of the task") @@ -43,7 +45,7 @@ class TaskOutput(BaseModel): return self.json_output[key] raise KeyError(f"Key '{key}' not found in pydantic_output or json_output") - def to_output_dict(self) -> Dict[str, Any]: + def to_dict(self) -> Dict[str, Any]: """Convert json_output and pydantic_output to a dictionary.""" output_dict = {} if self.json_output: