DuckDuckGo can't run

I am try to use duckduckgo but i found this :

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.”

def _run(self, query: str) -> str:
    duckduckgo_tool = DuckDuckGoSearchRun()
    
    response = duckduckgo_tool.invoke(query)

    return response

I try to fix many solutions but i still stuck this
Please help me to fix this

Thank you for you help

1 Like

@wrty62 Can you confirm the DuckDuckGo Search SDK is installed properly? Are you using CrewAI Flows?

thank you

Can you confirm the DuckDuckGo Search SDK is installed properly?

Yes I think install every env i have.

Are you using CrewAI Flows?
No. I’m not understanding about it , Can you tell me more ?

If you run pip show duckduckgo-search in the terminal, what do you get? Please copy-paste the response.

(crewai-env) (base) noom-wrrty@wrty-mac sendthistodej % pip show duckduckgo-search
Name: duckduckgo_search
Version: 6.3.7
Summary: Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.
Home-page: GitHub - deedy5/duckduckgo_search: Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.
Author: deedy5
Author-email:
License: MIT License
Location: /opt/anaconda3/envs/crewai-env/lib/python3.11/site-packages
Requires: click, primp
Required-by:

This indicates that the DuckDuckGo Search SDK was successfully installed inside the virtual environment.

Can you please show your code? What CrewAI SDK version are you using?

this version & my code
crewai version: 0.83.0

:: crew.py ::

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

for now i still can’t resolve this issue T___T

This should works:

  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()

Duck_search = MyCustomDuckDuckGoTool()