From 60f370d1367f5a0ae4dfa7482af4413651ed779c Mon Sep 17 00:00:00 2001 From: "snorkell-ai[bot]" <146478655+snorkell-ai[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:29:31 +0000 Subject: [PATCH] [Snorkell.ai]: Documentation for agent.py --- src/crewai/agent.py | 58 +++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/src/crewai/agent.py b/src/crewai/agent.py index 2db15d3cb7..0408b851f9 100644 --- a/src/crewai/agent.py +++ b/src/crewai/agent.py @@ -102,19 +102,17 @@ class Agent(BaseModel): @field_validator("id", mode="before") @classmethod def _deny_user_set_id(cls, v: Optional[UUID4]) -> None: - """ - Deny user to set the ID. + """ Deny user to set the ID. Args: cls: The class instance. v: The value to be set. - Raises: - PydanticCustomError: If the user tries to set the field. - Returns: - None - """ + : None + + Raises: + PydanticCustomError: If the user tries to set the field. """ if v: raise PydanticCustomError( "may_not_set_field", "This field is not to be set by the user.", {} @@ -122,17 +120,9 @@ def _deny_user_set_id(cls, v: Optional[UUID4]) -> None: @model_validator(mode="after") def set_private_attrs(self): - """ - Set private attributes. + """ Set private attributes. - This method initializes private attributes such as _logger and _rpm_controller based on the provided parameters. - - Raises: - : - - Returns: - : - """ + This method initializes private attributes such as _logger and _rpm_controller based on the provided parameters. """ self._logger = Logger(self.verbose) if self.max_rpm and not self._rpm_controller: self._rpm_controller = RPMController( @@ -142,15 +132,10 @@ def set_private_attrs(self): @model_validator(mode="after") def check_agent_executor(self) -> "Agent": - """ - Check if agent executor is set, and if not, set the cache handler. + """ Check if agent executor is set, and if not, set the cache handler. Returns: - Agent: The current instance of the Agent class. - - Raises: - : - """ + Agent: The current instance of the Agent class. """ if not self.agent_executor: self.set_cache_handler(self.cache_handler) return self @@ -160,17 +145,13 @@ def execute_task( ) -> str: """ Execute a task with the agent. - Args: - task (str): Task to execute. - context (str, optional): Context to execute the task in. Defaults to None. - tools (List[Any], optional): Tools to use for the task. Defaults to None. - - Returns: - str: Output of the agent + Args: + task (str): Task to execute. + context (str?): Context to execute the task in. Defaults to None. + tools (List[Any]?): Tools to use for the task. Defaults to None. - Raises: - Any exceptions that may occur during the task execution. - """ + Returns: + str: Output of the agent """ if context: task = self.i18n.slice("task_with_context").format( task=task, context=context @@ -194,18 +175,13 @@ def execute_task( return result def set_cache_handler(self, cache_handler) -> None: - """ - Set the cache handler for the current instance. + """ Set the cache handler for the current instance. Args: cache_handler: The cache handler to be set. - Raises: - None - Returns: - None - """ + : None """ self.cache_handler = cache_handler self.tools_handler = ToolsHandler(cache=self.cache_handler) self.__create_agent_executor()