Fix Task config and callback parameters being silently ignored

- Preserve config dictionary in process_config function instead of removing it
- Only set Task attributes for valid model fields in set_attributes_based_on_config
- Add comprehensive tests for config retention, value extraction, and callback retention
- Add reproduction script demonstrating the fix for issue #3160
- Fix deprecation warning by using class.model_fields instead of instance.model_fields

Fixes #3160

Co-Authored-By: Jo\u00E3o <joao@crewai.com>
This commit is contained in:
Devin AI
2025-07-14 15:02:17 +00:00
parent b6d699f764
commit 66ad84ef58
4 changed files with 202 additions and 3 deletions

View File

@@ -324,7 +324,8 @@ class Task(BaseModel):
"""Set attributes based on the agent configuration."""
if self.config:
for key, value in self.config.items():
setattr(self, key, value)
if key in self.__class__.model_fields:
setattr(self, key, value)
return self
@model_validator(mode="after")

View File

@@ -34,6 +34,4 @@ def process_config(
else:
values[key] = value
# Remove the config from values to avoid duplicate processing
values.pop("config", None)
return values