Skip to content

Commit

Permalink
Tool name recognition based on string distance (#521)
Browse files Browse the repository at this point in the history
* adding variations of ask question and delegate work tools

* Revert "adding variations of ask question and delegate work tools"

This reverts commit 38d4589.

* adding distance calculation for tool names.

* proper formatting

* remove brackets
  • Loading branch information
deadlious committed May 2, 2024
1 parent dae0aed commit 531c70b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/crewai/tools/tool_usage.py
@@ -1,6 +1,7 @@
import ast
from textwrap import dedent
from typing import Any, List, Union
from difflib import SequenceMatcher

from langchain_core.tools import BaseTool
from langchain_openai import ChatOpenAI
Expand Down Expand Up @@ -215,12 +216,15 @@ def _check_tool_repeated_usage(

def _select_tool(self, tool_name: str) -> BaseTool:
for tool in self.tools:
if tool.name.lower().strip() == tool_name.lower().strip():
if (
tool.name.lower().strip() == tool_name.lower().strip()
or SequenceMatcher(None, tool.name.lower().strip(), tool_name.lower().strip()).ratio() > 0.9
):
return tool
self.task.increment_tools_errors()
if tool_name and tool_name != "":
raise Exception(
f"Action '{tool_name}' don't exist, these are the only available Actions: {self.tools_description}"
f"Action '{tool_name}' don't exist, these are the only available Actions:\n {self.tools_description}"
)
else:
raise Exception(
Expand Down

0 comments on commit 531c70b

Please sign in to comment.