Address PR feedback: Add type hints and improve docstrings

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-08 16:03:22 +00:00
parent e7a95d0b2d
commit 519ab3f324
2 changed files with 27 additions and 3 deletions

View File

@@ -873,7 +873,19 @@ class Crew(BaseModel):
tools = self._inject_delegation_tools(tools, self.manager_agent, self.agents) tools = self._inject_delegation_tools(tools, self.manager_agent, self.agents)
return tools 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 = ( context = (
aggregate_raw_outputs_from_tasks(task.context) aggregate_raw_outputs_from_tasks(task.context)
if task.context and len(task.context) > 0 if task.context and len(task.context) > 0

View File

@@ -1,7 +1,8 @@
"""Test that context=[] is respected and doesn't include previous task outputs.""" """Test that context=[] is respected and doesn't include previous task outputs."""
import pytest
from unittest import mock from unittest import mock
import pytest
from crewai import Agent, Crew, Process, Task from crewai import Agent, Crew, Process, Task
from crewai.tasks.task_output import OutputFormat, TaskOutput from crewai.tasks.task_output import OutputFormat, TaskOutput
from crewai.utilities.formatter import ( from crewai.utilities.formatter import (
@@ -9,8 +10,19 @@ from crewai.utilities.formatter import (
aggregate_raw_outputs_from_tasks, aggregate_raw_outputs_from_tasks,
) )
def test_context_empty_list(): 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( researcher = Agent(