mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Merge branch 'conditional-task-f' of github.com:joaomdmoura/crewAI into test-hierarchical-tools-proper-setup
This commit is contained in:
@@ -649,34 +649,10 @@ class Crew(BaseModel):
|
|||||||
self._log_task_start(task, agent_to_use)
|
self._log_task_start(task, agent_to_use)
|
||||||
|
|
||||||
if isinstance(task, ConditionalTask):
|
if isinstance(task, ConditionalTask):
|
||||||
if futures:
|
skipped_task_output = self._handle_conditional_task(
|
||||||
task_outputs.extend(
|
task, task_outputs, futures, task_index, was_replayed
|
||||||
self._process_async_tasks(futures, was_replayed)
|
)
|
||||||
)
|
if skipped_task_output:
|
||||||
futures.clear()
|
|
||||||
|
|
||||||
previous_output = task_outputs[task_index - 1] if task_outputs else None
|
|
||||||
if previous_output is not None and not task.should_execute(
|
|
||||||
previous_output
|
|
||||||
):
|
|
||||||
self._logger.log(
|
|
||||||
"debug",
|
|
||||||
f"Skipping conditional task: {task.description}",
|
|
||||||
color="yellow",
|
|
||||||
)
|
|
||||||
skipped_task_output = TaskOutput(
|
|
||||||
description=task.description,
|
|
||||||
raw="",
|
|
||||||
agent=task.agent.role if task.agent else "",
|
|
||||||
output_format=OutputFormat.RAW,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not was_replayed:
|
|
||||||
self._store_execution_log(
|
|
||||||
task,
|
|
||||||
skipped_task_output,
|
|
||||||
task_index,
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if task.async_execution:
|
if task.async_execution:
|
||||||
@@ -691,9 +667,7 @@ class Crew(BaseModel):
|
|||||||
futures.append((task, future, task_index))
|
futures.append((task, future, task_index))
|
||||||
else:
|
else:
|
||||||
if futures:
|
if futures:
|
||||||
task_outputs.extend(
|
task_outputs = self._process_async_tasks(futures, was_replayed)
|
||||||
self._process_async_tasks(futures, was_replayed)
|
|
||||||
)
|
|
||||||
futures.clear()
|
futures.clear()
|
||||||
|
|
||||||
context = self._get_context(task, task_outputs)
|
context = self._get_context(task, task_outputs)
|
||||||
@@ -711,6 +685,37 @@ class Crew(BaseModel):
|
|||||||
|
|
||||||
return self._create_crew_output(task_outputs)
|
return self._create_crew_output(task_outputs)
|
||||||
|
|
||||||
|
def _handle_conditional_task(
|
||||||
|
self,
|
||||||
|
task: ConditionalTask,
|
||||||
|
task_outputs: List[TaskOutput],
|
||||||
|
futures: List[Tuple[Task, Future[TaskOutput], int]],
|
||||||
|
task_index: int,
|
||||||
|
was_replayed: bool,
|
||||||
|
) -> Optional[TaskOutput]:
|
||||||
|
if futures:
|
||||||
|
task_outputs = self._process_async_tasks(futures, was_replayed)
|
||||||
|
futures.clear()
|
||||||
|
|
||||||
|
previous_output = task_outputs[task_index - 1] if task_outputs else None
|
||||||
|
if previous_output is not None and not task.should_execute(previous_output):
|
||||||
|
self._logger.log(
|
||||||
|
"debug",
|
||||||
|
f"Skipping conditional task: {task.description}",
|
||||||
|
color="yellow",
|
||||||
|
)
|
||||||
|
skipped_task_output = TaskOutput(
|
||||||
|
description=task.description,
|
||||||
|
raw="",
|
||||||
|
agent=task.agent.role if task.agent else "",
|
||||||
|
output_format=OutputFormat.RAW,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not was_replayed:
|
||||||
|
self._store_execution_log(task, skipped_task_output, task_index)
|
||||||
|
return skipped_task_output
|
||||||
|
return None
|
||||||
|
|
||||||
def _prepare_task(self, task: Task, manager: Optional[BaseAgent]):
|
def _prepare_task(self, task: Task, manager: Optional[BaseAgent]):
|
||||||
if self.process == Process.hierarchical:
|
if self.process == Process.hierarchical:
|
||||||
if manager:
|
if manager:
|
||||||
|
|||||||
Reference in New Issue
Block a user