diff --git a/crewai/agents/exceptions.py b/crewai/agents/exceptions.py index 651bbda25..59578f73a 100644 --- a/crewai/agents/exceptions.py +++ b/crewai/agents/exceptions.py @@ -5,15 +5,19 @@ class TaskRepeatedUsageException(OutputParserException): """Exception raised when a task is used twice in a roll.""" error: str = "TaskRepeatedUsageException" - message: str = "\nI just used the {tool} tool with input {tool_input}. So I already know the result of that.\n" + message: str = "I just used the {tool} tool with input {tool_input}. So I already know the result of that and don't need to use it now.\n" - def __init__(self, tool: str, tool_input: str): + def __init__(self, tool: str, tool_input: str, text: str): + self.text = text self.tool = tool self.tool_input = tool_input self.message = self.message.format(tool=tool, tool_input=tool_input) super().__init__( - error=self.error, observation=self.message, send_to_llm=True, llm_output="" + error=self.error, + observation=self.message, + send_to_llm=True, + llm_output=self.text, ) def __str__(self): diff --git a/crewai/agents/output_parser.py b/crewai/agents/output_parser.py index dc70d54d2..85e28e2b8 100644 --- a/crewai/agents/output_parser.py +++ b/crewai/agents/output_parser.py @@ -66,7 +66,9 @@ class CrewAgentOutputParser(ReActSingleInputOutputParser): "input": tool_input, } if usage == last_tool_usage: - raise TaskRepeatedUsageException(tool=action, tool_input=tool_input) + raise TaskRepeatedUsageException( + tool=action, tool_input=tool_input, text=text + ) result = self.cache.read(action, tool_input) if result: diff --git a/crewai/tools/agent_tools.py b/crewai/tools/agent_tools.py index 5c4e12e99..90b317ece 100644 --- a/crewai/tools/agent_tools.py +++ b/crewai/tools/agent_tools.py @@ -18,11 +18,13 @@ class AgentTools(BaseModel): func=self.delegate_work, name="Delegate work to co-worker", description=dedent( - f"""Useful to delegate a specific task to one of the + f"""\ + Useful to delegate a specific task to one of the following co-workers: [{', '.join([agent.role for agent in self.agents])}]. The input to this tool should be a pipe (|) separated text of length - three, representing the role you want to delegate it to, the task and - information necessary. For example, `coworker|task|information`. + three, representing the co-worker you want to ask it to (one of the options), + the task and all actual context you have for the task. + For example, `coworker|task|context`. """ ), ), @@ -30,11 +32,13 @@ class AgentTools(BaseModel): func=self.ask_question, name="Ask question to co-worker", description=dedent( - f"""Useful to ask a question, opinion or take from on + f"""\ + Useful to ask a question, opinion or take from on of the following co-workers: [{', '.join([agent.role for agent in self.agents])}]. The input to this tool should be a pipe (|) separated text of length - three, representing the role you want to ask it to, the question and - information necessary. For example, `coworker|question|information`. + three, representing the co-worker you want to ask it to (one of the options), + the question and all actual context you have for the question. + For example, `coworker|question|context`. """ ), ), @@ -51,12 +55,12 @@ class AgentTools(BaseModel): def __execute(self, command): """Execute the command.""" try: - agent, task, information = command.split("|") + agent, task, context = command.split("|") except ValueError: - return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|information`.\n" + return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|context`. I need to make sure to pass context as context\n" - if not agent or not task or not information: - return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|question|information`.\n" + if not agent or not task or not context: + return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|context`. I need to make sure to pass context as context.\n" agent = [ available_agent @@ -68,5 +72,5 @@ class AgentTools(BaseModel): return f"\nError executing tool. Co-worker mentioned on the Action Input not found, it must to be one of the following options: {', '.join([agent.role for agent in self.agents])}.\n" agent = agent[0] - result = agent.execute_task(task, information) + result = agent.execute_task(task, context) return result diff --git a/tests/agent_tools/agent_tools_test.py b/tests/agent_tools/agent_tools_test.py index 02437eb88..a81058c78 100644 --- a/tests/agent_tools/agent_tools_test.py +++ b/tests/agent_tools/agent_tools_test.py @@ -48,7 +48,7 @@ def test_delegate_work_with_wrong_input(): assert ( result - == "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|information`.\n" + == "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|context`. I need to make sure to pass context as context\n" )