Tavily

Guide to use Tavily tool on your AI agent using Vity Toolkit

Search, crawl, map, and extract live web content via Tavily’s research APIs.

Details

Supported Auth Type

AuthType.API_KEY

Quick Start

1

Install the package.

npm install vity-toolkit langchain @langchain/openai
2

Initialize Vity Toolkit and Langchain.

import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";

const P = (globalThis as any).process;

const model = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
    userPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
    appPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
});

Make sure that you already have integrated and connected the app.

3

Add the tool.

const tools = toolKit.getTools({ apps: [App.TAVILY] });
4

Define the Agent.

const prompt = ChatPromptTemplate.fromMessages([
    ["system", `You are an AI agent that uses Tavily to search, extract, crawl and map websites on users' behalf.
                You need to take action on Tavily using Tavily APIs. Use correct tools to run APIs from the given tool-set.`],
    ["placeholder", "{chat_history}"],
    ["human", "{input}"],
    ["placeholder", "{agent_scratchpad}"],
]);


const agent = createToolCallingAgent({ llm: model, tools, prompt });

const agentExecutor = new AgentExecutor({
    agent,
    tools,
    verbose: false,
});
5

Execute the Agent.

const response = await agentExecutor.invoke({ input: "Use Tavily to find the latest Solana core updates (last 6 months, advanced). Prefer docs.solana.com, solana.com, solana.com/news, solana.org, foundation.solana.org. Summarize key changes with links and dates." });
console.log(response);

Supported Actions

Action
Description
Action.TAVILY_SEARCH

Search the web using Tavily's AI search engine.

Action.TAVILY_EXTRACT

Extract and process content from URLs using Tavily.

Action.TAVILY_CRAWL

Crawl a website starting from a base URL using Tavily.

Action.TAVILY_MAP

Create a structured map of website URLs using Tavily.

Last updated