I encountered an error while trying to use the tool. This was the error: Could not import duckduckgo-search python package. Please install it with pip install -U duckduckgo-search…
Tool DuckDuckGo Search Tool accepts these inputs: Tool Name: DuckDuckGo Search Tool
Tool Arguments: {‘query’: {‘description’: None, ‘type’: ‘str’}}
Tool Description: Search the web for a given query…
Moving on then. I MUST either use a tool (use one at time) OR give my best final answer not both at the same time. To Use the following format:
Thought: you should always think about what to do
Action: the action to take, should be one of [DuckDuckGo Search Tool]
Action Input: the input to the action, dictionary enclosed in curly braces
Observation: the result of the action
… (this Thought/Action/Action Input/Result can repeat N times)
Thought: I now can give a great answer
Final Answer: Your final answer must be the great and the most complete as possible, it must be outcome described
This My custom_tool setup :
from crewai.tools import BaseTool
from langchain_community.tools import DuckDuckGoSearchRun
class MyCustomDuckDuckGoTool(BaseTool):
name: str = “DuckDuckGo Search Tool”
description: str = “Search the web for a given query.”
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task, before_kickoff, after_kickoff
from sendthistodej.tools.custom_tool import MyCustomDuckDuckGoTool
@CrewBase
class Sendthistodej():
"""Sendthistodej crew"""
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
@before_kickoff # Optional hook to be executed before the crew starts
def pull_data_example(self, inputs):
# Example of pulling data from an external API, dynamically changing the inputs
inputs['extra_data'] = "This is extra data"
return inputs
@after_kickoff # Optional hook to be executed after the crew has finished
def log_results(self, output):
# Example of logging results, dynamically changing the output
print(f"Results: {output}")
return output
@agent
def researcher(self) -> Agent:
return Agent(
config=self.agents_config['researcher'],
tools= [MyCustomDuckDuckGoTool()],
verbose=True
)
@agent
def content_strategist(self) -> Agent:
return Agent(
config=self.agents_config['content_strategist'],
verbose=True
)
@agent
def creative_writer(self) -> Agent:
return Agent(
config=self.agents_config['creative_writer'],
verbose=True
)
@agent
def editor(self) -> Agent:
return Agent(
config=self.agents_config['editor'],
verbose=True
)
@task
def research_task(self) -> Task:
return Task(
config=self.tasks_config['research_task'],
)
@task
def content_strategy_task(self) -> Task:
return Task(
config=self.tasks_config['content_strategy_task'],
output_file='markdown.md'
)
@task
def writing_task(self) -> Task:
return Task(
config=self.tasks_config['writing_task'],
output_file='writing.md'
)
@task
def editing_task(self) -> Task:
return Task(
config=self.tasks_config['editing_task'],
output_file='editing.md'
)
@crew
def crew(self) -> Crew:
"""Creates the Sendthistodej crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
)
:: custom_tool.py
from crewai.tools import BaseTool
from langchain_community.tools import DuckDuckGoSearchRun
class MyCustomDuckDuckGoTool(BaseTool):
name: str = "DuckDuckGo Search Tool"
description: str = "Search the web for a given query."
def _run(self, query: str) -> str:
duckduckgo_tool = DuckDuckGoSearchRun()
response = duckduckgo_tool.invoke(query)
return response
from crewai.tools import BaseTool
from langchain_community.tools import DuckDuckGoSearchRun
class MyCustomDuckDuckGoTool(BaseTool):
name: str = "DuckDuckGo Search Tool"
description: str = "Search the web for a given query."
def _run(self, query: str) -> str:
# Ensure the DuckDuckGoSearchRun is invoked properly.
duckduckgo_tool = DuckDuckGoSearchRun()
response = duckduckgo_tool.invoke(query)
return response
def _get_tool(self):
# Create an instance of the tool when needed
return MyCustomDuckDuckGoTool()