Skip to content

Commit

Permalink
fixing translations
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Jan 12, 2024
1 parent 09e9595 commit 7910e5e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/crewai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/crewai/agents/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/crewai/prompts.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import ClassVar

from langchain.prompts import PromptTemplate
from pydantic import BaseModel, PrivateAttr
from pydantic import BaseModel, Field

from .i18n import I18N


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}"

Expand Down
8 changes: 5 additions & 3 deletions src/crewai/tools/agent_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/crewai/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_tools/agent_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down

0 comments on commit 7910e5e

Please sign in to comment.