mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
fix: resolve type annotation mismatch in Task.context field
- Update context field type annotation from Optional[List[Task]] to Union[List[Task], _NotSpecified, None] - Add ConfigDict(arbitrary_types_allowed=True) to Task model to support _NotSpecified type - Add comprehensive tests covering the type annotation fix and sentinel behavior - Fixes issue #3019 where context field default NOT_SPECIFIED didn't match type annotation The fix maintains backward compatibility while making the type annotation accurate. The NOT_SPECIFIED sentinel distinguishes between 'not passed' and 'explicitly passed None'. Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -26,6 +26,7 @@ from typing import (
|
||||
from pydantic import (
|
||||
UUID4,
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
PrivateAttr,
|
||||
field_validator,
|
||||
@@ -39,7 +40,7 @@ from crewai.tasks.output_format import OutputFormat
|
||||
from crewai.tasks.task_output import TaskOutput
|
||||
from crewai.tools.base_tool import BaseTool
|
||||
from crewai.utilities.config import process_config
|
||||
from crewai.utilities.constants import NOT_SPECIFIED
|
||||
from crewai.utilities.constants import NOT_SPECIFIED, _NotSpecified
|
||||
from crewai.utilities.guardrail import process_guardrail, GuardrailResult
|
||||
from crewai.utilities.converter import Converter, convert_to_model
|
||||
from crewai.utilities.events import (
|
||||
@@ -78,6 +79,8 @@ class Task(BaseModel):
|
||||
used_tools: int = 0
|
||||
tools_errors: int = 0
|
||||
delegations: int = 0
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
i18n: I18N = I18N()
|
||||
name: Optional[str] = Field(default=None)
|
||||
prompt_context: Optional[str] = None
|
||||
@@ -95,7 +98,7 @@ class Task(BaseModel):
|
||||
agent: Optional[BaseAgent] = Field(
|
||||
description="Agent responsible for execution the task.", default=None
|
||||
)
|
||||
context: Optional[List["Task"]] = Field(
|
||||
context: Union[List["Task"], _NotSpecified, None] = Field(
|
||||
description="Other tasks that will have their output used as context for this task.",
|
||||
default=NOT_SPECIFIED,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user