fix: validate agent type in Task to give clear error message#4539
Open
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
Open
fix: validate agent type in Task to give clear error message#4539hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Task(agent="not_an_agent")now raises a clearValidationErrorinstead of crashing withAttributeError: 'str' object has no attribute 'get'isinstanceguard inprocess_config()that raisesValueErrorwhen non-dict values are passed, which Pydantic wraps into a properValidationErrorBaseAgentand any other model usingprocess_config()from the same class of input errorsError before this fix
Error after this fix
Test plan
test_task_with_invalid_agent_type_raises_validation_errorcovering string, int, and list inputstest_task_definition_based_on_dict,test_task_callback,test_task_copy_*) still passTask(agent=None)andTask()(no agent) continue to work correctly