Tavily Search Tool#
The Tavily AI search integration allows users to perform real-time web searches within the AG2 framework. Follow these steps to integrate TavilySearchTool
with AG2 Agents.
Configuring Your Tavily API Key#
-
Create a Tavily Account:
- Visit Tavily AI
- Click
Sign Up
and create an account
-
Get API Key:
- Navigate to Tavily API
- Generate API key under API Keys
-
Set Environment Variable:
Package Installation#
To get started with the Tavily Search
integration in AG2, follow these steps:
Install AG2 with openai
extra since we use openai in our examples:
Note: If you have been using
autogen
orpyautogen
, all you need to do is upgrade it using:or
as
pyautogen
,autogen
, andag2
are aliases for the same PyPI package.
You’re all set! Now you can start using Tavily AI Search with AG2.
Implementation#
The TavilySearchTool
enables agents to perform real time AI Powered web search.
Imports#
import os
from autogen import AssistantAgent, UserProxyAgent
from autogen.tools.experimental import TavilySearchTool
Agent Configuration#
Configure an assistant agent and user proxy to be used for LLM recommendation and execution respectively.
os.environ["AUTOGEN_USE_DOCKER"] = "False"
from autogen import LLMConfig
config_list = LLMConfig(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")
Tool Setup#
tavily_search_tool = TavilySearchTool(tavily_api_key=os.getenv("TAVILY_API_KEY"))
# Register the tool for LLM recommendation and execution.
tavily_search_tool.register_for_llm(assistant)
tavily_search_tool.register_for_execution(user_proxy)
Start the Conversation#
With the setup complete, you can now use the assistant to fetch live web search results.