Add explicit type annotations for agents_config and tasks_config #3802
+4,340
−4,094
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.
Add explicit type annotations for agents_config and tasks_config
Fixes #3801
Summary
This PR addresses issue #3801 where
agents_configandtasks_configin@CrewBasedecorated classes lacked explicit type annotations, making the code un-Pythonic and reducing IDE/type checker support.Key changes:
AgentsConfigDictandTasksConfigDicttype aliases for better typingload_configurations()to usecast()for proper type hintsCrewInstanceProtocol to use strongly-typed config dictionariescrewai.projectfor user convenience (can importAgentConfig,TaskConfig, etc.)AgentConfigandTaskConfigTypedDicts to support both raw YAML values (strings) and processed values (instances) using union typesWhat users get:
Review & Testing Checklist for Human
uv run pytest tests -vv@CrewBaseclass and verify that IDE autocomplete works forself.agents_configandself.tasks_config, and that existing projects don't breakagent: str | Anyandllm: str | Anysupport both YAML strings and resolved instances. This is pragmatic but reduces type safety. Consider if this tradeoff is acceptable or if separate Raw/Processed TypedDicts would be betteruv run pytest tests -vvuv run mypy lib/crewai/srcto ensure type checking still works across the codebaseTest Plan
self.agents_config["agent_name"]from crewai.project import AgentConfig, AgentsConfigDictNotes
CrewInstanceProtocol, so they work for all@CrewBasedecorated classes