IntegrateTavily with Pydantic AI to enhance your AI agents with powerful web search capabilities. Pydantic AI provides a framework for building AI agents with tools, making it easy to incorporate real-time web search and data extraction into your applications.
Step 3: Initialize Pydantic AI Agent with Tavily Tools
Copy
Ask AI
import osfrom pydantic_ai.agent import Agentfrom pydantic_ai.common_tools.tavily import tavily_search_tool# Get API key from environmentapi_key = os.getenv('TAVILY_API_KEY')assert api_key is not None# Initialize the agent with Tavily toolsagent = Agent( 'openai:o3-mini', tools=[tavily_search_tool(api_key)], system_prompt='Search Tavily for the given query and return the results.')
# Example 1: Basic search for newsresult = agent.run_sync('Tell me the top news in the GenAI world, give me links.')print(result.output)
Example Response:
Copy
Ask AI
Here are some of the top recent news articles related to GenAI:1. How CLEAR users can improve risk analysis with GenAI – Thomson Reuters Read more: https://legal.thomsonreuters.com/blog/how-clear-users-can-improve-risk-analysis-with-genai/ (This article discusses how CLEAR's new GenAI-powered tool streamlines risk analysis by quickly summarizing key information from various public data sources.)2. TELUS Digital Survey Reveals Enterprise Employees Are Entering Sensitive Data Into AI Assistants More Than You Think – FT.com Read more: https://markets.ft.com/data/announce/detail?dockey=600-202502260645BIZWIRE_USPRX____20250226_BW490609-1 (This news piece highlights findings from a TELUS Digital survey showing that many enterprise employees use public GenAI tools and sometimes even enter sensitive data.)3. The Essential Guide to Generative AI – Virtualization Review Read more: https://virtualizationreview.com/Whitepapers/2025/02/SNOWFLAKE-The-Essential-Guide-to-Generative-AI.aspx (This guide provides insights into how GenAI is revolutionizing enterprise strategies and productivity, with input from industry leaders.)