Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@langchain/tavily

langchain-ai51.9kMIT1.0.0TypeScript support: included

Tavily integration for LangChain.js

readme

@langchain/tavily

NPM - Version

This package provides integrations for the Tavily search engine within LangChain.js. Tavily is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.

This package exposes four tools:

  • TavilySearch: Performs a search optimized for LLMs and RAG.
  • TavilyExtract: Extracts raw content from a list of URLs.
  • TavilyCrawl: Initiates a structured web crawl starting from a specified base URL.
  • TavilyMap: Generates a site map starting from a specified base URL.

Installation

npm install @langchain/tavily

Setup

You need a Tavily API key to use these tools. You can get one here. Set it as an environment variable:

process.env.TAVILY_API_KEY = "YOUR_API_KEY";

Usage

TavilySearch

import { TavilySearch } from "@langchain/tavily";

const tool = new TavilySearch({
  maxResults: 5,
  // You can set other constructor parameters here, e.g.:
  // topic: "general",
  // includeAnswer: false,
  // includeRawContent: false,
  // includeImages: false,
  // searchDepth: "basic",
});

// Invoke with a query
const results = await tool.invoke({
  query: "what is the current weather in SF?",
});

console.log(results);

TavilyExtract

import { TavilyExtract } from "@langchain/tavily";

const tool = new TavilyExtract({
  // Constructor parameters:
  // extractDepth: "basic",
  // includeImages: false,
});

// Invoke with a list of URLs
const results = await tool.invoke({
  urls: ["https://en.wikipedia.org/wiki/Lionel_Messi"],
});

console.log(results);

TavilyCrawl

import { TavilyCrawl } from "@langchain/tavily";

const tool = new TavilyCrawl({
  // Constructor parameters:
  // extractDepth: "basic",
  // format: "markdown",
  // maxDepth: 3,
  // maxBreadth: 50,
  // limit: 100,
  // includeImages: false,
  // allowExternal: false,
});

// Invoke with a URL and optional parameters
const results = await tool.invoke({
  url: "https://docs.tavily.com/",
  instructions: "Find information about the LangChain integration.",
});

console.log(results);

TavilyMap

import { TavilyMap } from "@langchain/tavily";

const tool = new TavilyMap({
  // Constructor parameters:
  // maxDepth: 3,
  // maxBreadth: 50,
  // limit: 100,
  // allowExternal: false,
});

// Invoke with a URL and optional parameters
const results = await tool.invoke({
  url: "https://docs.tavily.com/",
});

console.log(results);

Documentation

For more detailed information, check out the documentation pages:

License

This package is licensed under the MIT License. See the LICENSE file for details.

changelog

@langchain/tavily

1.0.0

This release updates the package for compatibility with LangChain v1.0. See the v1.0 release notes for details on what's new.