Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
fix: add type hints and ignore type checks for config access (#2603)
Lucas Gomidebc91e94f039d
diff --git a/README.md b/README.mdindex a1bf63645..4d563daee 100644--- a/README.md+++ b/README.md@@ -257,10 +257,14 @@ reporting_task:from crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, taskfrom crewai_tools import SerperDevTool+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List@CrewBaseclass LatestAiDevelopmentCrew():"""LatestAiDevelopment crew"""+ agents: List[BaseAgent]+ tasks: List[Task]@agentdef researcher(self) -> Agent:diff --git a/docs/concepts/agents.mdx b/docs/concepts/agents.mdxindex 8f04b9d49..fa954d4fc 100644--- a/docs/concepts/agents.mdx+++ b/docs/concepts/agents.mdx@@ -118,7 +118,7 @@ class LatestAiDevelopmentCrew():@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]verbose=True,tools=[SerperDevTool()])@@ -126,7 +126,7 @@ class LatestAiDevelopmentCrew():@agentdef reporting_analyst(self) -> Agent:return Agent(- config=self.agents_config['reporting_analyst'],+ config=self.agents_config['reporting_analyst'], # type: ignore[index]verbose=True)```diff --git a/docs/concepts/crews.mdx b/docs/concepts/crews.mdxindex e5602539a..76268457e 100644--- a/docs/concepts/crews.mdx+++ b/docs/concepts/crews.mdx@@ -52,12 +52,16 @@ After creating your CrewAI project as outlined in the [Installation](/installati```python codefrom crewai import Agent, Crew, Task, Processfrom crewai.project import CrewBase, agent, task, crew, before_kickoff, after_kickoff-+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List@CrewBaseclass YourCrewName:"""Description of your crew"""+ agents: List[BaseAgent]+ tasks: List[Task]+# Paths to your YAML configuration files# To see an example agent and task defined in YAML, checkout the following:# - Task: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended@@ -80,27 +84,27 @@ class YourCrewName:@agentdef agent_one(self) -> Agent:return Agent(- config=self.agents_config['agent_one'],+ config=self.agents_config['agent_one'], # type: ignore[index]verbose=True)@agentdef agent_two(self) -> Agent:return Agent(- config=self.agents_config['agent_two'],+ config=self.agents_config['agent_two'], # type: ignore[index]verbose=True)@taskdef task_one(self) -> Task:return Task(- config=self.tasks_config['task_one']+ config=self.tasks_config['task_one'] # type: ignore[index])@taskdef task_two(self) -> Task:return Task(- config=self.tasks_config['task_two']+ config=self.tasks_config['task_two'] # type: ignore[index])@crewdiff --git a/docs/concepts/llms.mdx b/docs/concepts/llms.mdxindex f2f027746..560448f21 100644--- a/docs/concepts/llms.mdx+++ b/docs/concepts/llms.mdx@@ -438,7 +438,7 @@ In this section, you'll find detailed examples that help you select, configure,@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]llm=local_nvidia_nim_llm)diff --git a/docs/concepts/tasks.mdx b/docs/concepts/tasks.mdxindex 8a0ce74e0..2a47448de 100644--- a/docs/concepts/tasks.mdx+++ b/docs/concepts/tasks.mdx@@ -113,7 +113,7 @@ class LatestAiDevelopmentCrew():@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]verbose=True,tools=[SerperDevTool()])@@ -121,20 +121,20 @@ class LatestAiDevelopmentCrew():@agentdef reporting_analyst(self) -> Agent:return Agent(- config=self.agents_config['reporting_analyst'],+ config=self.agents_config['reporting_analyst'], # type: ignore[index]verbose=True)@taskdef research_task(self) -> Task:return Task(- config=self.tasks_config['research_task']+ config=self.tasks_config['research_task'] # type: ignore[index])@taskdef reporting_task(self) -> Task:return Task(- config=self.tasks_config['reporting_task']+ config=self.tasks_config['reporting_task'] # type: ignore[index])@crewdiff --git a/docs/guides/crews/first-crew.mdx b/docs/guides/crews/first-crew.mdxindex 8aa384112..8eb2619d1 100644--- a/docs/guides/crews/first-crew.mdx+++ b/docs/guides/crews/first-crew.mdx@@ -185,15 +185,20 @@ Let's modify the `crew.py` file:from crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, taskfrom crewai_tools import SerperDevTool+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List@CrewBaseclass ResearchCrew():"""Research crew for comprehensive topic analysis and reporting"""+ agents: List[BaseAgent]+ tasks: List[Task]+@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]verbose=True,tools=[SerperDevTool()])@@ -201,20 +206,20 @@ class ResearchCrew():@agentdef analyst(self) -> Agent:return Agent(- config=self.agents_config['analyst'],+ config=self.agents_config['analyst'], # type: ignore[index]verbose=True)@taskdef research_task(self) -> Task:return Task(- config=self.tasks_config['research_task']+ config=self.tasks_config['research_task'] # type: ignore[index])@taskdef analysis_task(self) -> Task:return Task(- config=self.tasks_config['analysis_task'],+ config=self.tasks_config['analysis_task'], # type: ignore[index]output_file='output/report.md')@@ -387,4 +392,4 @@ Now that you've built your first crew, you can:<Check>Congratulations! You've successfully built your first CrewAI crew that can research and analyze any topic you provide. This foundational experience has equipped you with the skills to create increasingly sophisticated AI systems that can tackle complex, multi-stage problems through collaborative intelligence.-</Check>\ No newline at end of file+</Check>diff --git a/docs/guides/flows/first-flow.mdx b/docs/guides/flows/first-flow.mdxindex cb10de275..d5784f0a9 100644--- a/docs/guides/flows/first-flow.mdx+++ b/docs/guides/flows/first-flow.mdx@@ -203,35 +203,40 @@ These task definitions provide detailed instructions to our agents, ensuring the# src/guide_creator_flow/crews/content_crew/content_crew.pyfrom crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, task+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List@CrewBaseclass ContentCrew():"""Content writing crew"""+ agents: List[BaseAgent]+ tasks: List[Task]+@agentdef content_writer(self) -> Agent:return Agent(- config=self.agents_config['content_writer'],+ config=self.agents_config['content_writer'], # type: ignore[index]verbose=True)@agentdef content_reviewer(self) -> Agent:return Agent(- config=self.agents_config['content_reviewer'],+ config=self.agents_config['content_reviewer'], # type: ignore[index]verbose=True)@taskdef write_section_task(self) -> Task:return Task(- config=self.tasks_config['write_section_task']+ config=self.tasks_config['write_section_task'] # type: ignore[index])@taskdef review_section_task(self) -> Task:return Task(- config=self.tasks_config['review_section_task'],+ config=self.tasks_config['review_section_task'], # type: ignore[index]context=[self.write_section_task()])diff --git a/docs/quickstart.mdx b/docs/quickstart.mdxindex 2cbc2df9a..cb01c15cc 100644--- a/docs/quickstart.mdx+++ b/docs/quickstart.mdx@@ -87,15 +87,20 @@ Follow the steps below to get Crewing! 🚣♂️from crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, taskfrom crewai_tools import SerperDevTool+ from crewai.agents.agent_builder.base_agent import BaseAgent+ from typing import List@CrewBaseclass LatestAiDevelopmentCrew():"""LatestAiDevelopment crew"""+ agents: List[BaseAgent]+ tasks: List[Task]+@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]verbose=True,tools=[SerperDevTool()])@@ -103,20 +108,20 @@ Follow the steps below to get Crewing! 🚣♂️@agentdef reporting_analyst(self) -> Agent:return Agent(- config=self.agents_config['reporting_analyst'],+ config=self.agents_config['reporting_analyst'], # type: ignore[index]verbose=True)@taskdef research_task(self) -> Task:return Task(- config=self.tasks_config['research_task'],+ config=self.tasks_config['research_task'], # type: ignore[index])@taskdef reporting_task(self) -> Task:return Task(- config=self.tasks_config['reporting_task'],+ config=self.tasks_config['reporting_task'], # type: ignore[index]output_file='output/report.md' # This is the file that will be contain the final report.)diff --git a/src/crewai/cli/templates/crew/crew.py b/src/crewai/cli/templates/crew/crew.pyindex 700f97c07..43a2608a4 100644--- a/src/crewai/cli/templates/crew/crew.py+++ b/src/crewai/cli/templates/crew/crew.py@@ -1,6 +1,7 @@from crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, task-+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List# If you want to run a snippet of code before or after the crew starts,# you can use the @before_kickoff and @after_kickoff decorators# https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators@@ -9,25 +10,26 @@ from crewai.project import CrewBase, agent, crew, taskclass {{crew_name}}():"""{{crew_name}} crew"""+ agents: List[BaseAgent]+ tasks: List[Task]+# Learn more about YAML configuration files here:# Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended# Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended- agents_config = 'config/agents.yaml'- tasks_config = 'config/tasks.yaml'-+# If you would like to add tools to your agents, you can learn more about it here:# https://docs.crewai.com/concepts/agents#agent-tools@agentdef researcher(self) -> Agent:return Agent(- config=self.agents_config['researcher'],+ config=self.agents_config['researcher'], # type: ignore[index]verbose=True)@agentdef reporting_analyst(self) -> Agent:return Agent(- config=self.agents_config['reporting_analyst'],+ config=self.agents_config['reporting_analyst'], # type: ignore[index]verbose=True)@@ -37,13 +39,13 @@ class {{crew_name}}():@taskdef research_task(self) -> Task:return Task(- config=self.tasks_config['research_task'],+ config=self.tasks_config['research_task'], # type: ignore[index])@taskdef reporting_task(self) -> Task:return Task(- config=self.tasks_config['reporting_task'],+ config=self.tasks_config['reporting_task'], # type: ignore[index]output_file='report.md')diff --git a/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py b/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.pyindex 5e978d985..1f2a81466 100644--- a/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py+++ b/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py@@ -1,5 +1,7 @@from crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, task+from crewai.agents.agent_builder.base_agent import BaseAgent+from typing import List# If you want to run a snippet of code before or after the crew starts,# you can use the @before_kickoff and @after_kickoff decorators@@ -10,6 +12,9 @@ from crewai.project import CrewBase, agent, crew, taskclass PoemCrew:"""Poem Crew"""+ agents: List[BaseAgent]+ tasks: List[Task]+# Learn more about YAML configuration files here:# Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended# Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended@@ -21,7 +26,7 @@ class PoemCrew:@agentdef poem_writer(self) -> Agent:return Agent(- config=self.agents_config["poem_writer"],+ config=self.agents_config["poem_writer"], # type: ignore[index])# To learn more about structured task outputs,@@ -30,7 +35,7 @@ class PoemCrew:@taskdef write_poem(self) -> Task:return Task(- config=self.tasks_config["write_poem"],+ config=self.tasks_config["write_poem"], # type: ignore[index])@crewdiff --git a/tests/crew_test.py b/tests/crew_test.pyindex c2ffe7350..fd0d9f3d4 100644--- a/tests/crew_test.py+++ b/tests/crew_test.py@@ -4069,11 +4069,17 @@ def test_crew_guardrail_feedback_in_context():@pytest.mark.vcr(filter_headers=["authorization"])def test_before_kickoff_callback():- from crewai.project import CrewBase, agent, before_kickoff, task+ from crewai.project import CrewBase@CrewBaseclass TestCrewClass:- from crewai.project import crew+ from typing import List++ from crewai.agents.agent_builder.base_agent import BaseAgent+ from crewai.project import CrewBase, agent, before_kickoff, crew, task++ agents: List[BaseAgent]+ tasks: List[Task]agents_config = Nonetasks_config = Nonediff --git a/tests/project_test.py b/tests/project_test.pyindex e0813a13f..c07922351 100644--- a/tests/project_test.py+++ b/tests/project_test.py@@ -1,6 +1,9 @@+from typing import List+import pytestfrom crewai.agent import Agent+from crewai.agents.agent_builder.base_agent import BaseAgentfrom crewai.crew import Crewfrom crewai.llm import LLMfrom crewai.project import (@@ -40,28 +43,32 @@ class InternalCrew:agents_config = "config/agents.yaml"tasks_config = "config/tasks.yaml"+ agents: List[BaseAgent]+ tasks: List[Task]+@llmdef local_llm(self):return LLM(- model='openai/model_name',+ model="openai/model_name",api_key="None",- base_url="http://xxx.xxx.xxx.xxx:8000/v1")+ base_url="http://xxx.xxx.xxx.xxx:8000/v1",+ )@agentdef researcher(self):- return Agent(config=self.agents_config["researcher"])+ return Agent(config=self.agents_config["researcher"]) # type: ignore[index]@agentdef reporting_analyst(self):- return Agent(config=self.agents_config["reporting_analyst"])+ return Agent(config=self.agents_config["reporting_analyst"]) # type: ignore[index]@taskdef research_task(self):- return Task(config=self.tasks_config["research_task"])+ return Task(config=self.tasks_config["research_task"]) # type: ignore[index]@taskdef reporting_task(self):- return Task(config=self.tasks_config["reporting_task"])+ return Task(config=self.tasks_config["reporting_task"]) # type: ignore[index]@before_kickoffdef modify_inputs(self, inputs):@@ -165,24 +172,27 @@ def test_before_kickoff_with_none_input():def test_multiple_before_after_kickoff():@CrewBaseclass MultipleHooksCrew:+ agents: List[BaseAgent]+ tasks: List[Task]+agents_config = "config/agents.yaml"tasks_config = "config/tasks.yaml"@agentdef researcher(self):- return Agent(config=self.agents_config["researcher"])+ return Agent(config=self.agents_config["researcher"]) # type: ignore[index]@agentdef reporting_analyst(self):- return Agent(config=self.agents_config["reporting_analyst"])+ return Agent(config=self.agents_config["reporting_analyst"]) # type: ignore[index]@taskdef research_task(self):- return Task(config=self.tasks_config["research_task"])+ return Task(config=self.tasks_config["research_task"]) # type: ignore[index]@taskdef reporting_task(self):- return Task(config=self.tasks_config["reporting_task"])+ return Task(config=self.tasks_config["reporting_task"]) # type: ignore[index]@before_kickoffdef first_before(self, inputs):