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.

Overview

Integration details

Tool features

Setup

The integration lives in the @langchain/tavily package, which you can install as shown below:

Credentials

Set up a Tavily API key and set it as an environment variable named TAVILY_API_KEY.
It’s also helpful (but not needed) to set up LangSmith for best-in-class observability:

Instantiation

The tool accepts various parameters during instantiation:
  • maxResults (optional, number): Maximum number of search results to return. Default is 5.
  • topic (optional, string): Category of the search. Can be "general", "news", or "finance". Default is "general".
  • includeAnswer (optional, boolean): Include an answer to the original query in the results. Default is false.
  • includeRawContent (optional, boolean | "markdown" | "text"): Include cleaned and parsed content of each search result. Default is false.
  • includeImages (optional, boolean): Include a list of query-related images in the response. Default is false.
  • includeImageDescriptions (optional, boolean): Include descriptive text for each image. Default is false.
  • searchDepth (optional, string): Depth of the search, either "basic" or "advanced". Default is "basic".
  • timeRange (optional, string): Time range from the current date to filter results — "day", "week", "month", or "year". Default is undefined.
  • includeDomains (optional, string[]): Domains to specifically include. Default is [].
  • excludeDomains (optional, string[]): Domains to specifically exclude. Default is [].
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 natural language search query.
  • The following arguments can also be set during invocation: includeImages, searchDepth, timeRange, includeDomains, excludeDomains.
  • For reliability and performance reasons, certain parameters that affect response size cannot be modified during invocation: includeAnswer and includeRawContent. 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 tool with a different value, the tool will use the value you passed during invocation.

Invoke with ToolCall

We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:

Use within an agent

We can use the search tool directly with a LangChain agent by passing it to createAgent. The agent can dynamically set parameters like includeDomains, searchDepth, and timeRange as part of its tool call. In the example below, when we ask the agent to find “What nation hosted Euro 2024? Include only wikipedia sources.” the agent will dynamically set the arguments and invoke the Tavily search tool with { query: "Euro 2024 host nation", includeDomains: ["wikipedia.org"] }.

API reference

For detailed documentation of all Tavily Search API features and configurations head to the API reference: docs.tavily.com/documentation/api-reference/endpoint/search