Skip to content

Commit 19b6c15

Browse files
committed
Cutting new version with tool ussage bug fix
1 parent 3ef5020 commit 19b6c15

File tree

6 files changed

+104
-98
lines changed

6 files changed

+104
-98
lines changed

poetry.lock

Lines changed: 83 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[tool.poetry]
33
name = "crewai"
4-
version = "0.11.0"
4+
version = "0.11.1"
55
description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks."
66
authors = ["Joao Moura <joao@crewai.com>"]
77
readme = "README.md"
@@ -20,7 +20,7 @@ python = ">=3.10,<4.0"
2020
pydantic = "^2.4.2"
2121
langchain = "^0.1.0"
2222
openai = "^1.7.1"
23-
langchain-openai = "^0.0.2"
23+
langchain-openai = "^0.0.5"
2424
opentelemetry-api = "^1.22.0"
2525
opentelemetry-sdk = "^1.22.0"
2626
opentelemetry-exporter-otlp-proto-http = "^1.22.0"

src/crewai/agents/tools_handler.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ def __init__(self, cache: CacheHandler):
1616
self.cache = cache
1717
self.last_used_tool = {}
1818

19-
def on_tool_start(self, calling: ToolCalling) -> Any:
20-
"""Run when tool starts running."""
21-
self.last_used_tool = calling
22-
23-
def on_tool_end(self, calling: ToolCalling, output: str) -> Any:
19+
def on_tool_use(self, calling: ToolCalling, output: str) -> Any:
2420
"""Run when tool ends running."""
25-
if self.last_used_tool.tool_name != CacheTools().name:
21+
print(f"Tool {calling.tool_name} has been used.")
22+
self.last_used_tool = calling
23+
if calling.tool_name != CacheTools().name:
2624
self.cache.add(
2725
tool=calling.tool_name,
2826
input=calling.arguments,

src/crewai/tools/tool_usage.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ def use(self, tool_string: str):
6161
calling = self._tool_calling(tool_string)
6262
if isinstance(calling, ToolUsageErrorException):
6363
error = calling.message
64-
self._printer.print(content=f"\n\n{error}\n", color="yellow")
64+
self._printer.print(content=f"\n\n{error}\n", color="red")
6565
return error
6666
try:
6767
tool = self._select_tool(calling.tool_name)
6868
except Exception as e:
6969
error = getattr(e, "message", str(e))
70-
self._printer.print(content=f"\n\n{error}\n", color="yellow")
70+
self._printer.print(content=f"\n\n{error}\n", color="red")
7171
return error
7272
return self._use(tool_string=tool_string, tool=tool, calling=calling)
7373

@@ -94,8 +94,6 @@ def _use(
9494
except Exception:
9595
pass
9696

97-
self.tools_handler.on_tool_start(calling=calling)
98-
9997
result = self.tools_handler.cache.read(
10098
tool=calling.tool_name, input=calling.arguments
10199
)
@@ -107,18 +105,19 @@ def _use(
107105
self._run_attempts += 1
108106
if self._run_attempts > self._max_parsing_attempts:
109107
self._telemetry.tool_usage_error(llm=self.llm)
110-
return ToolUsageErrorException(
108+
error = ToolUsageErrorException(
111109
self._i18n.errors("tool_usage_exception").format(error=e)
112110
).message
111+
self._printer.print(content=f"\n\n{error}\n", color="red")
112+
return error
113113
return self.use(tool_string=tool_string)
114114

115-
self.tools_handler.on_tool_end(calling=calling, output=result)
115+
self.tools_handler.on_tool_use(calling=calling, output=result)
116116

117117
self._printer.print(content=f"\n\n{result}\n", color="yellow")
118118
self._telemetry.tool_usage(
119119
llm=self.llm, tool_name=tool.name, attempts=self._run_attempts
120120
)
121-
122121
result = self._format_result(result=result)
123122
return result
124123

src/crewai/utilities/printer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ class Printer:
22
def print(self, content: str, color: str):
33
if color == "yellow":
44
self._print_yellow(content)
5+
elif color == "red":
6+
self._print_red(content)
57
else:
68
print(content)
79

810
def _print_yellow(self, content):
911
print("\033[93m {}\033[00m".format(content))
12+
13+
def _print_red(self, content):
14+
print("\033[91m {}\033[00m".format(content))

tests/agent_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def multiplier(first_number: int, second_number: int) -> float:
125125

126126
assert agent.tools_handler.last_used_tool == {}
127127
task = Task(description="What is 3 times 4?", agent=agent)
128+
# force cleaning cache
129+
agent.tools_handler.cache = CacheHandler()
128130
output = agent.execute_task(task)
129131
tool_usage = InstructorToolCalling(
130132
tool_name=multiplier.name, arguments={"first_number": 3, "second_number": 4}
@@ -255,6 +257,8 @@ def get_final_answer(numbers) -> float:
255257
task = Task(
256258
description="The final answer is 42. But don't give it yet, instead keep using the `get_final_answer` tool."
257259
)
260+
# force cleaning cache
261+
agent.tools_handler.cache = CacheHandler()
258262
agent.execute_task(
259263
task=task,
260264
tools=[get_final_answer],

0 commit comments

Comments
 (0)