adding ability to pass context to tasks

This commit is contained in:
João Moura
2024-02-02 23:15:27 -08:00
parent a8c1348235
commit d712ee8451
3 changed files with 701 additions and 1 deletions

View File

@@ -25,6 +25,10 @@ class Task(BaseModel):
description="Clear definition of expected output for the task.",
default=None,
)
context: Optional[List["Task"]] = Field(
description="Other tasks that will have their output used as context for this task.",
default=None,
)
output: Optional[TaskOutput] = Field(
description="Task output, it's final result after being executed", default=None
)
@@ -66,7 +70,10 @@ class Task(BaseModel):
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."
)
result = agent.execute_task(
if self.context:
context = "\n".join([task.output.result for task in self.context])
result = self.agent.execute_task(
task=self._prompt(), context=context, tools=self.tools
)