From d3da73136c59c35790a6fcb3f72f3c638e399ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sat, 4 Jan 2025 13:44:33 -0300 Subject: [PATCH] small adjustments before cutting version --- src/crewai/task.py | 8 +++----- src/crewai/tools/agent_tools/base_agent_tools.py | 6 +++--- src/crewai/translations/en.json | 3 ++- src/crewai/utilities/planning_handler.py | 7 +++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/crewai/task.py b/src/crewai/task.py index 217e7dbfd..d55373e28 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -133,7 +133,6 @@ class Task(BaseModel): default=3, description="Maximum number of retries when guardrail fails" ) retry_count: int = Field(default=0, description="Current number of retries") - start_time: Optional[datetime.datetime] = Field( default=None, description="Start time of the task execution" ) @@ -391,10 +390,9 @@ class Task(BaseModel): ) self.retry_count += 1 - context = ( - f"### Previous attempt failed validation: {guardrail_result.error}\n\n\n" - f"### Previous result:\n{task_output.raw}\n\n\n" - "Try again, making sure to address the validation error." + context = self.i18n.errors("validation_error").format( + guardrail_result_error=guardrail_result.error, + task_output=task_output.raw ) return self._execute_core(agent, context, tools) diff --git a/src/crewai/tools/agent_tools/base_agent_tools.py b/src/crewai/tools/agent_tools/base_agent_tools.py index e67dce72a..b00fbb7b5 100644 --- a/src/crewai/tools/agent_tools/base_agent_tools.py +++ b/src/crewai/tools/agent_tools/base_agent_tools.py @@ -1,5 +1,5 @@ import logging -from typing import Optional, Union +from typing import Optional from pydantic import Field @@ -54,12 +54,12 @@ class BaseAgentTool(BaseTool): ) -> str: """ Execute delegation to an agent with case-insensitive and whitespace-tolerant matching. - + Args: agent_name: Name/role of the agent to delegate to (case-insensitive) task: The specific question or task to delegate context: Optional additional context for the task execution - + Returns: str: The execution result from the delegated agent or an error message if the agent cannot be found diff --git a/src/crewai/translations/en.json b/src/crewai/translations/en.json index a1ea30436..3cee10aa6 100644 --- a/src/crewai/translations/en.json +++ b/src/crewai/translations/en.json @@ -34,7 +34,8 @@ "tool_arguments_error": "Error: the Action Input is not a valid key, value dictionary.", "wrong_tool_name": "You tried to use the tool {tool}, but it doesn't exist. You must use one of the following tools, use one at time: {tools}.", "tool_usage_exception": "I encountered an error while trying to use the tool. This was the error: {error}.\n Tool {tool} accepts these inputs: {tool_inputs}", - "agent_tool_execution_error": "Error executing task with agent '{agent_role}'. Error: {error}" + "agent_tool_execution_error": "Error executing task with agent '{agent_role}'. Error: {error}", + "validation_error": "### Previous attempt failed validation: {guardrail_result_error}\n\n\n### Previous result:\n{task_output}\n\n\nTry again, making sure to address the validation error." }, "tools": { "delegate_work": "Delegate a specific task to one of the following coworkers: {coworkers}\nThe input to this tool should be the coworker, the task you want them to do, and ALL necessary context to execute the task, they know nothing about the task, so share absolute everything you know, don't reference things but instead explain them.", diff --git a/src/crewai/utilities/planning_handler.py b/src/crewai/utilities/planning_handler.py index 9092dedda..6ce74f236 100644 --- a/src/crewai/utilities/planning_handler.py +++ b/src/crewai/utilities/planning_handler.py @@ -1,4 +1,3 @@ -import json import logging from typing import Any, List, Optional @@ -78,10 +77,10 @@ class CrewPlanner: def _get_agent_knowledge(self, task: Task) -> List[str]: """ Safely retrieve knowledge source content from the task's agent. - + Args: task: The task containing an agent with potential knowledge sources - + Returns: List[str]: A list of knowledge source strings """ @@ -108,6 +107,6 @@ class CrewPlanner: f"[{', '.join(str(tool) for tool in task.agent.tools)}]" if task.agent and task.agent.tools else '"agent has no tools"', f',\n "agent_knowledge": "[\\"{knowledge_list[0]}\\"]"' if knowledge_list and str(knowledge_list) != "None" else "" ) - + tasks_summary.append(task_summary) return " ".join(tasks_summary)