Skip to main content

Tavily Search

Tavily Search is a robust search API tailored specifically for LLM Agents. It seamlessly integrates with diverse data sources to ensure a superior, relevant search experience.


Set up an API key here and set it as an environment variable named TAVILY_API_KEY.

You'll also need to install the @langchain/community package:

npm install @langchain/openai @langchain/community


import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
import { ChatOpenAI } from "@langchain/openai";
import type { ChatPromptTemplate } from "@langchain/core/prompts";

import { pull } from "langchain/hub";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";

// Define the tools the agent will have access to.
const tools = [new TavilySearchResults({ maxResults: 1 })];

// Get the prompt to use - you can modify this!
// If you want to see the prompt in full, you can at:
const prompt = await pull<ChatPromptTemplate>(

const llm = new ChatOpenAI({
model: "gpt-3.5-turbo-1106",
temperature: 0,

const agent = await createOpenAIFunctionsAgent({

const agentExecutor = new AgentExecutor({

const result = await agentExecutor.invoke({
input: "what is the weather in wailea?",


input: 'what is the weather in wailea?',
output: "The current weather in Wailea, HI is 64°F with clear skies. The high for today is 82°F and the low is 66°F. If you'd like more detailed information, you can visit [The Weather Channel]("

API Reference:

Was this page helpful?

You can also leave detailed feedback on GitHub.