Skip to content

Comments

fix: validate agent type in Task to give clear error message#4539

Open
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
hztBUAA:fix/task-agent-validation
Open

fix: validate agent type in Task to give clear error message#4539
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
hztBUAA:fix/task-agent-validation

Conversation

@hztBUAA
Copy link

@hztBUAA hztBUAA commented Feb 20, 2026

Summary

Error before this fix

AttributeError: 'str' object has no attribute 'get'

Error after this fix

pydantic_core._pydantic_core.ValidationError: 1 validation error for Task
agent
  Value error, Expected a dictionary or BaseAgent instance, got str.
  Please provide a valid BaseAgent object or a configuration dictionary.

Test plan

  • Added test_task_with_invalid_agent_type_raises_validation_error covering string, int, and list inputs
  • Verified existing tests (test_task_definition_based_on_dict, test_task_callback, test_task_copy_*) still pass
  • Verified that Task(agent=None) and Task() (no agent) continue to work correctly

…buteError

When creating a Task with an invalid agent type (e.g. a string),
process_config() would crash with 'AttributeError: str object has no
attribute get' because it assumed the input was always a dict.

Add an isinstance check at the start of process_config() to raise a
clear ValueError when non-dict values are passed. Pydantic wraps this
into a ValidationError with a helpful message like:
"Expected a dictionary or BaseAgent instance, got str."

Fixes crewAIInc#4419
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Task(agent=...) with non-Agent type crashes with AttributeError instead of validation error

1 participant