Skip to main content
Tavily’s Search API is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.

概述

集成详情

Tool features

设置

The integration lives in the langchain-tavily package.

凭证

We also need to set our Tavily API key. You can get an API key by visiting this site and creating an account.

Instantiation

Here we show how to instantiate an instance of the Tavily search 工具。 The tool accepts various parameters to customize the search. After instantiation we invoke the 工具与 a simple query. This tool allows you to complete search queries using Tavily’s Search API endpoint. Instantiation The tool accepts various parameters during instantiation:
  • max_results (optional, int): Maximum number of search results to return. Default is 5.
  • topic (optional, str): Category of the search. Can be “general”, “news”, or “finance”. Default is “general”.
  • include_answer (optional, bool): Include an answer to original query in results. Default is False.
  • include_raw_content (optional, bool): Include cleaned and parsed HTML of each search result. Default is False.
  • include_images (optional, bool): Include a list of query related images in the response. Default is False.
  • include_image_descriptions (optional, bool): Include descriptive text for each image. Default is False.
  • search_depth (optional, str): Depth of the search, either “basic” or “advanced”. Default is “basic”.
  • time_range (optional, str): The time range back from the current date to filter results - “day”, “week”, “month”, or “year”. Default is None.
  • include_domains (optional, List[str]): List of domains to specifically include. Default is None.
  • exclude_domains (optional, List[str]): List of domains to specifically exclude. Default is None.
For a comprehensive overview of the available parameters, refer to the Tavily Search API documentation

Invocation

Invoke directly with args

The Tavily search tool accepts the following arguments during invocation:
  • query (required): A 自然语言 search query
  • The following arguments can also be set during invocation : include_images, search_depth , time_range, include_domains, exclude_domains, include_images
  • For reliability and performance reasons, certain parameters that affect response size cannot be modified during invocation: include_answer and include_raw_content. These limitations prevent unexpected context window issues and ensure consistent results.
NOTE: The optional arguments are available for agents to dynamically set, if you set an argument during instantiation and then invoke the 工具与 a different value, the tool will use the value you passed during invocation.

Invoke with ToolCall

We can also invoke the 工具与 a model-generated ToolCall, in which case a ToolMessage will be returned:

Use within an agent

We can use our tools directly with an agent executor by binding the tool to the agent. This gives the agent the ability to dynamically set the available arguments to the Tavily search 工具。 In the below example when we ask the agent to find “What nation hosted the Euro 2024? Include only wikipedia sources.” the agent will dynamically set the argments and invoke Tavily search tool : Invoking tavily_search with {'query': 'Euro 2024 host nation', 'include_domains': ['wikipedia.org']
We will need to install langgraph:

API 参考

所有 Tavily Search API 功能和配置的详细文档请前往 API reference: docs.tavily.com/documentation/api-reference/endpoint/search