Skip to content

Commit

Permalink
Small RC Fixes (#608)
Browse files Browse the repository at this point in the history
* mentioning ollama on the docs as embedder

* lowering barrier to match tool with simialr name

* Fixing agent tools to support co_worker

* Adding new tests

* Fixing type"

* updating tests

* fixing conflict
  • Loading branch information
joaomdmoura committed May 13, 2024
1 parent 7a4d3dd commit 7fd8850
Show file tree
Hide file tree
Showing 21 changed files with 203,703 additions and 3,188 deletions.
2 changes: 1 addition & 1 deletion docs/tools/CSVSearchTool.md
Expand Up @@ -50,7 +50,7 @@ tool = CSVSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/CodeDocsSearchTool.md
Expand Up @@ -53,7 +53,7 @@ tool = CodeDocsSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/DOCXSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = DOCXSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/DirectorySearchTool.md
Expand Up @@ -43,7 +43,7 @@ tool = DirectorySearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/GitHubSearchTool.md
Expand Up @@ -55,7 +55,7 @@ tool = GithubSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/JSONSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = JSONSearchTool(
},
},
"embedder": {
"provider": "google",
"provider": "google", # or openai, ollama, ...
"config": {
"model": "models/embedding-001",
"task_type": "retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/MDXSearchTool.md
Expand Up @@ -49,7 +49,7 @@ tool = MDXSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/PDFSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = PDFSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/PGSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = PGSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/TXTSearchTool.md
Expand Up @@ -50,7 +50,7 @@ tool = TXTSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/WebsiteSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = WebsiteSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/XMLSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = XMLSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/YoutubeChannelSearchTool.md
Expand Up @@ -48,7 +48,7 @@ tool = YoutubeChannelSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/YoutubeVideoSearchTool.md
Expand Up @@ -52,7 +52,7 @@ tool = YoutubeVideoSearchTool(
),
),
embedder=dict(
provider="google",
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
Expand Down
8 changes: 5 additions & 3 deletions src/crewai/tools/agent_tools.py
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Union

from langchain.tools import StructuredTool
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -33,12 +33,14 @@ def tools(self):
]
return tools

def delegate_work(self, coworker: str, task: str, context: str):
def delegate_work(self, task: str, context: str, coworker: Union[str, None] = None, **kwargs):
"""Useful to delegate a specific task to a co-worker passing all necessary context and names."""
coworker = coworker or kwargs.get("co_worker")
return self._execute(coworker, task, context)

def ask_question(self, coworker: str, question: str, context: str):
def ask_question(self, question: str, context: str, coworker: Union[str, None] = None, **kwargs):
"""Useful to ask a question, opinion or take from a co-worker passing all necessary context and names."""
coworker = coworker or kwargs.get("co_worker")
return self._execute(coworker, question, context)

def _execute(self, agent, task, context):
Expand Down
11 changes: 9 additions & 2 deletions src/crewai/tools/tool_usage.py
Expand Up @@ -219,13 +219,20 @@ def _check_tool_repeated_usage(
)

def _select_tool(self, tool_name: str) -> BaseTool:
for tool in self.tools:
order_tools = sorted(
self.tools,
key=lambda tool: SequenceMatcher(
None, tool.name.lower().strip(), tool_name.lower().strip()
).ratio(),
reverse=True,
)
for tool in order_tools:
if (
tool.name.lower().strip() == tool_name.lower().strip()
or SequenceMatcher(
None, tool.name.lower().strip(), tool_name.lower().strip()
).ratio()
> 0.9
> 0.85
):
return tool
self.task.increment_tools_errors()
Expand Down
27 changes: 27 additions & 0 deletions tests/agent_tools/agent_tools_test.py
Expand Up @@ -28,6 +28,20 @@ def test_delegate_work():
)


@pytest.mark.vcr(filter_headers=["authorization"])
def test_delegate_work_with_wrong_co_worker_variable():
result = tools.delegate_work(
co_worker="researcher",
task="share your take on AI Agents",
context="I heard you hate them",
)

assert (
result
== "AI Agents are essentially computer programs that are designed to perform tasks autonomously, with the ability to adapt and learn from their environment. These tasks range from simple ones such as setting alarms, to more complex ones like diagnosing diseases or driving cars. AI agents have the potential to revolutionize many industries, making processes more efficient and accurate. \n\nHowever, like any technology, AI agents have their downsides. They can be susceptible to biases based on the data they're trained on and they can also raise privacy concerns. Moreover, the widespread adoption of AI agents could result in significant job displacement in certain industries.\n\nDespite these concerns, it's important to note that the development and use of AI agents are heavily dependent on human decisions and policies. Therefore, the key to harnessing the benefits of AI agents while mitigating the risks lies in responsible and thoughtful development and implementation.\n\nWhether one 'loves' or 'hates' AI agents often comes down to individual perspectives and experiences. But as a researcher, it is my job to provide balanced and factual information, so I hope this explanation helps you understand better what AI Agents are and the implications they have."
)


@pytest.mark.vcr(filter_headers=["authorization"])
def test_ask_question():
result = tools.ask_question(
Expand All @@ -41,6 +55,19 @@ def test_ask_question():
== "As an AI researcher, I don't have personal feelings or emotions like love or hate. However, I recognize the importance of AI Agents in today's technological landscape. They have the potential to greatly enhance our lives and make tasks more efficient. At the same time, it is crucial to consider the ethical implications and societal impacts that come with their use. My role is to provide objective research and analysis on these topics."
)

@pytest.mark.vcr(filter_headers=["authorization"])
def test_ask_question_with_wrong_co_worker_variable():
result = tools.ask_question(
co_worker="researcher",
question="do you hate AI Agents?",
context="I heard you LOVE them",
)

assert (
result
== "No, I don't hate AI agents. In fact, I find them quite fascinating. They are powerful tools that can greatly assist in various tasks, including my research. As a technology researcher, AI and AI agents are subjects of interest to me due to their potential in advancing our understanding and capabilities in various fields. My supposed love for them stems from this professional interest and the potential they hold."
)


def test_delegate_work_to_wrong_agent():
result = tools.ask_question(
Expand Down

0 comments on commit 7fd8850

Please sign in to comment.