diff --git a/src/crewai/agent.py b/src/crewai/agent.py index d828cf7f39..b3850095d8 100644 --- a/src/crewai/agent.py +++ b/src/crewai/agent.py @@ -93,7 +93,6 @@ class Agent(BaseModel): ) llm: Optional[Any] = Field( default_factory=lambda: ChatOpenAI( - temperature=0.7, model_name="gpt-4", ), description="Language model that will run the agent.", @@ -109,6 +108,7 @@ def _deny_user_set_id(cls, v: Optional[UUID4]) -> None: @model_validator(mode="after") def set_private_attrs(self): + """Set private attributes.""" self._logger = Logger(self.verbose) if self.max_rpm and not self._rpm_controller: self._rpm_controller = RPMController( @@ -118,12 +118,16 @@ def set_private_attrs(self): @model_validator(mode="after") def check_agent_executor(self) -> "Agent": + """Check if the agent executor is set.""" if not self.agent_executor: self.set_cache_handler(self.cache_handler) return self def execute_task( - self, task: str, context: str = None, tools: List[Any] = None + self, + task: str, + context: Optional[str] = None, + tools: Optional[List[Any]] = None, ) -> str: """Execute a task with the agent. @@ -157,17 +161,27 @@ def execute_task( return result - def set_cache_handler(self, cache_handler) -> None: + def set_cache_handler(self, cache_handler: CacheHandler) -> None: + """Set the cache handler for the agent. + + Args: + cache_handler: An instance of the CacheHandler class. + """ self.cache_handler = cache_handler self.tools_handler = ToolsHandler(cache=self.cache_handler) self.__create_agent_executor() - def set_rpm_controller(self, rpm_controller) -> None: + def set_rpm_controller(self, rpm_controller: RPMController) -> None: + """Set the rpm controller for the agent. + + Args: + rpm_controller: An instance of the RPMController class. + """ if not self._rpm_controller: self._rpm_controller = rpm_controller self.__create_agent_executor() - def __create_agent_executor(self) -> CrewAgentExecutor: + def __create_agent_executor(self) -> None: """Create an agent executor for the agent. Returns: diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 1a847fe6b1..ee2cb4947c 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -33,7 +33,7 @@ class Crew(BaseModel): process: The process flow that the crew will follow (e.g., sequential). verbose: Indicates the verbosity level for logging during execution. config: Configuration settings for the crew. - cache_handler: Handles caching for the crew's operations. + _cache_handler: Handles caching for the crew's operations. max_rpm: Maximum number of requests per minute for the crew execution to be respected. id: A unique identifier for the crew instance. """ @@ -71,11 +71,22 @@ def _deny_user_set_id(cls, v: Optional[UUID4]) -> None: @classmethod @field_validator("config", mode="before") - def check_config_type(cls, v: Union[Json, Dict[str, Any]]): + def check_config_type( + cls, v: Union[Json, Dict[str, Any]] + ) -> Union[Json, Dict[str, Any]]: + """Validates that the config is a valid type. + + Args: + v: The config to be validated. + + Returns: + The config if it is valid. + """ return json.loads(v) if isinstance(v, Json) else v @model_validator(mode="after") - def set_private_attrs(self): + def set_private_attrs(self) -> "Crew": + """Set private attributes.""" self._cache_handler = CacheHandler() self._logger = Logger(self.verbose) self._rpm_controller = RPMController(max_rpm=self.max_rpm, logger=self._logger) @@ -110,8 +121,15 @@ def _setup_from_config(self): self.agents = [Agent(**agent) for agent in self.config["agents"]] self.tasks = [self._create_task(task) for task in self.config["tasks"]] - def _create_task(self, task_config): - """Creates a task instance from its configuration.""" + def _create_task(self, task_config: Dict[str, Any]) -> Task: + """Creates a task instance from its configuration. + + Args: + task_config: The configuration of the task. + + Returns: + A task instance. + """ task_agent = next( agt for agt in self.agents if agt.role == task_config["agent"] ) @@ -140,8 +158,12 @@ def _sequential_loop(self) -> str: self._rpm_controller.stop_rpm_counter() return task_output - def _prepare_and_execute_task(self, task): - """Prepares and logs information about the task being executed.""" + def _prepare_and_execute_task(self, task: Task) -> None: + """Prepares and logs information about the task being executed. + + Args: + task: The task to be executed. + """ if task.agent.allow_delegation: task.tools += AgentTools(agents=self.agents).tools() diff --git a/src/crewai/task.py b/src/crewai/task.py index 89af3f2982..49b7e59fdc 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -39,11 +39,12 @@ def _deny_user_set_id(cls, v: Optional[UUID4]) -> None: @model_validator(mode="after") def check_tools(self): + """Check if the tools are set.""" if not self.tools and (self.agent and self.agent.tools): self.tools.extend(self.agent.tools) return self - def execute(self, context: str = None) -> str: + def execute(self, context: Optional[str] = None) -> str: """Execute the task. Returns: