diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 321549f22..9cbdf615b 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -873,7 +873,19 @@ class Crew(BaseModel): tools = self._inject_delegation_tools(tools, self.manager_agent, self.agents) return tools - def _get_context(self, task: Task, task_outputs: List[TaskOutput]): + def _get_context(self, task: Task, task_outputs: List[TaskOutput]) -> str: + """Get context for task execution. + + Determines whether to use the task's explicit context or aggregate outputs from previous tasks. + When task.context is an empty list, it will use the task_outputs instead. + + Args: + task: The task to get context for + task_outputs: List of previous task outputs + + Returns: + String containing the aggregated context + """ context = ( aggregate_raw_outputs_from_tasks(task.context) if task.context and len(task.context) > 0 diff --git a/tests/context_empty_list_test.py b/tests/context_empty_list_test.py index 8a8232fcf..5974400cc 100644 --- a/tests/context_empty_list_test.py +++ b/tests/context_empty_list_test.py @@ -1,7 +1,8 @@ """Test that context=[] is respected and doesn't include previous task outputs.""" -import pytest from unittest import mock +import pytest + from crewai import Agent, Crew, Process, Task from crewai.tasks.task_output import OutputFormat, TaskOutput from crewai.utilities.formatter import ( @@ -9,8 +10,19 @@ from crewai.utilities.formatter import ( aggregate_raw_outputs_from_tasks, ) + def test_context_empty_list(): - """Test that context=[] is respected and doesn't include previous task outputs.""" + """Test that context=[] is respected and doesn't include previous task outputs. + + This test verifies that when a task has context=[], the _get_context method + correctly uses task_outputs instead of an empty context list. + + Returns: + None + + Raises: + AssertionError: If the context handling doesn't work as expected + """ researcher = Agent(