DuckDuckGo Search Tool
DuckDuckGoSearchTool
with AG2 Agents.
DuckDuckGo Search
integration in AG2, you need
to install the necessary package:
Install AG2 with openai
and duckduckgo
extras:
pip install -U "ag2[openai] duckduckgo_search"
Note: If you have been usingYou’re all set! Now you can start using DuckDuckGo Search with AG2.autogen
orag2
, all you need to do is upgrade it using:orCopypip install -U "autogen[openai] duckduckgo_search"
asCopypip install -U "ag2[openai] duckduckgo_search"
autogen
, andag2
are aliases for the same PyPI package.
DuckDuckGoSearchTool
enables agents to perform real time web
searches.
import os
from autogen import AssistantAgent, UserProxyAgent
from autogen.tools.experimental import DuckDuckGoSearchTool
os.environ["AUTOGEN_USE_DOCKER"] = "False"
from autogen import LLMConfig
# Configure your LLM settings. You can use OAI_CONFIG_LIST_sample as a template.
config_list = LLMConfig.from_local("OAI_CONFIG_LIST", api_type="openai", model="gpt-4o-mini")
assistant = AssistantAgent(
name="assistant",
llm_config=config_list,
)
user_proxy = UserProxyAgent(name="user_proxy", human_input_mode="NEVER")
# Initialize the DuckDuckGoSearchTool. No API key is needed.
duckduckgo_search_tool = DuckDuckGoSearchTool()
# Register the tool for LLM recommendation and execution.
duckduckgo_search_tool.register_for_llm(assistant)
duckduckgo_search_tool.register_for_execution(user_proxy)
response = user_proxy.initiate_chat(
recipient=assistant,
message="What happened with stock prices after deepseek was launched? Please search the web using DuckDuckGo.",
max_turns=2,
)
print(f"Final Answer: {response.summary}")