diff --git a/src/crewai/agent.py b/src/crewai/agent.py index b9fd27ba42..db0c5d3057 100644 --- a/src/crewai/agent.py +++ b/src/crewai/agent.py @@ -118,7 +118,7 @@ def execute_task( Output of the agent """ if context: - task = self.i18n.slices("task_with_context").format( + task = self.i18n.slice("task_with_context").format( task=task, context=context ) @@ -175,7 +175,7 @@ def __create_agent_executor(self) -> CrewAgentExecutor: backstory=self.backstory, ) - bind = self.llm.bind(stop=[self.i18n.slices("observation")]) + bind = self.llm.bind(stop=[self.i18n.slice("observation")]) inner_agent = ( agent_args | execution_prompt diff --git a/src/crewai/agents/exceptions.py b/src/crewai/agents/exceptions.py index 7749149b0c..8dccf8c592 100644 --- a/src/crewai/agents/exceptions.py +++ b/src/crewai/agents/exceptions.py @@ -10,7 +10,8 @@ class TaskRepeatedUsageException(OutputParserException): error: str = "TaskRepeatedUsageException" message: str - def __init__(self, tool: str, tool_input: str, text: str): + def __init__(self, i18n: I18N, tool: str, tool_input: str, text: str): + self.i18n = i18n self.text = text self.tool = tool self.tool_input = tool_input diff --git a/src/crewai/prompts.py b/src/crewai/prompts.py index 69c14dbf6a..2504aa0bce 100644 --- a/src/crewai/prompts.py +++ b/src/crewai/prompts.py @@ -1,7 +1,7 @@ from typing import ClassVar from langchain.prompts import PromptTemplate -from pydantic import BaseModel, PrivateAttr +from pydantic import BaseModel, Field from .i18n import I18N @@ -9,7 +9,7 @@ class Prompts(BaseModel): """Manages and generates prompts for a generic agent with support for different languages.""" - i18n: I18N = PrivateAttr(default=I18N()) + i18n: I18N = Field(default=I18N()) SCRATCHPAD_SLICE: ClassVar[str] = "\n{agent_scratchpad}" diff --git a/src/crewai/tools/agent_tools.py b/src/crewai/tools/agent_tools.py index acbdd48edf..dd4f4289b4 100644 --- a/src/crewai/tools/agent_tools.py +++ b/src/crewai/tools/agent_tools.py @@ -46,10 +46,10 @@ def __execute(self, command): try: agent, task, context = command.split("|") except ValueError: - return self.i18n.tools("agent_tool_missing_param") + return self.i18n.errors("agent_tool_missing_param") if not agent or not task or not context: - return self.i18n.tools("agent_tool_missing_param") + return self.i18n.errors("agent_tool_missing_param") agent = [ available_agent @@ -58,7 +58,9 @@ def __execute(self, command): ] if not agent: - return self.i18n.tools("agent_tool_unexsiting_coworker") + return self.i18n.errors("agent_tool_unexsiting_coworker").format( + coworkers=", ".join([agent.role for agent in self.agents]) + ) agent = agent[0] return agent.execute_task(task, context) diff --git a/src/crewai/translations/en.json b/src/crewai/translations/en.json index 76530d5a12..420a5781d6 100644 --- a/src/crewai/translations/en.json +++ b/src/crewai/translations/en.json @@ -10,7 +10,7 @@ "errors": { "used_too_many_tools": "I've used too many tools for this task. I'm going to give you my absolute BEST Final answer now and not use any more tools.", "agent_tool_missing_param": "\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_tool_unexsiting_coworker": "\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_tool_unexsiting_coworker": "\nError executing tool. Co-worker mentioned on the Action Input not found, it must to be one of the following options: {coworkers}.\n", "task_repeated_usage": "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" }, "tools": { diff --git a/tests/agent_tools/agent_tools_test.py b/tests/agent_tools/agent_tools_test.py index a81058c787..489f02098c 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|context`. I need to make sure to pass context as context\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" )