← 返回
AI智能 Key 中文

tavily-search

Web search using Tavily API - a powerful search engine for AI agents. Use when you need to search the web for current information, news, research, or any top...
使用 Tavily API 进行网页搜索,提供强大的 AI 代理搜索功能,适用于获取当前信息、新闻、研究或热门内容等需求。
chasehl
AI智能 clawhub v1.0.0 1 版本 98585.7 Key: 需要
★ 3
Stars
📥 8,793
下载
💾 4,133
安装
1
版本
#latest

概述

Tavily Search

Web search using Tavily API - optimized for AI agents and RAG applications.

Quick Start

Prerequisites

Set your Tavily API key:

export TAVILY_API_KEY="tvly-your-api-key"

Or use the Python client directly with API key.

Basic Search

from tavily import TavilyClient

client = TavilyClient(api_key="tvly-your-api-key")
response = client.search("Latest AI developments")

for result in response['results']:
    print(f"Title: {result['title']}")
    print(f"URL: {result['url']}")
    print(f"Content: {result['content'][:200]}...")

Q&A Search (Get Direct Answers)

answer = client.qna_search(query="Who won the 2024 US Presidential Election?")
print(answer)

Context Search (For RAG Applications)

context = client.get_search_context(
    query="Climate change effects on agriculture",
    max_tokens=4000
)
# Use context directly in LLM prompts

Search Parameters

Common Parameters

ParameterTypeDescriptionDefault
---------------------------------------
querystringSearch query (required)-
search_depthstring"basic" or "comprehensive""basic"
max_resultsintNumber of results (1-20)5
include_answerboolInclude AI-generated answerFalse
include_raw_contentboolInclude full page contentFalse
include_imagesboolInclude image URLsFalse

Advanced Parameters

ParameterTypeDescription
------------------------------
topicstringSearch topic: "general" or "news"
time_rangestringTime filter: "day", "week", "month", "year"
include_domainslistRestrict to specific domains
exclude_domainslistExclude specific domains
exact_matchboolRequire exact phrase matching

Response Format

Standard Search Response

{
  "query": "search query",
  "results": [
    {
      "title": "Result Title",
      "url": "https://example.com/article",
      "content": "Snippet or full content...",
      "score": 0.95,
      "raw_content": "Full page content (if requested)..."
    }
  ],
  "answer": "AI-generated answer (if requested)",
  "images": ["image_url1", "image_url2"],
  "response_time": 1.23
}

Error Handling

Common Errors

from tavily import TavilyClient
from tavily.exceptions import TavilyError, RateLimitError, InvalidAPIKeyError

client = TavilyClient(api_key="your-api-key")

try:
    response = client.search("query")
except InvalidAPIKeyError:
    print("Invalid API key. Check your TAVILY_API_KEY.")
except RateLimitError:
    print("Rate limit exceeded. Please wait before retrying.")
except TavilyError as e:
    print(f"Tavily error: {e}")

Best Practices

1. Use Context Search for RAG

For retrieval-augmented generation, use get_search_context() instead of standard search:

context = client.get_search_context(
    query=user_query,
    max_tokens=4000,  # Fit within your LLM's context window
    search_depth="comprehensive"
)

# Use in prompt
prompt = f"""Based on the following context:
{context}

Answer this question: {user_query}"""

2. Handle Rate Limits

Tavily has rate limits. Implement exponential backoff:

import time
from tavily.exceptions import RateLimitError

def search_with_retry(client, query, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.search(query)
        except RateLimitError:
            if attempt < max_retries - 1:
                wait_time = 2 ** attempt  # Exponential backoff
                print(f"Rate limited. Waiting {wait_time}s...")
                time.sleep(wait_time)
            else:
                raise

3. Filter Results

Use domain filters to improve result quality:

# Only search trusted news sources
response = client.search(
    query="breaking news",
    include_domains=["bbc.com", "reuters.com", "apnews.com"],
    time_range="day"  # Only recent news
)

4. Use Q&A Mode for Facts

For factual questions, use Q&A mode for direct answers:

# Good for: "Who won the 2024 election?"
answer = client.qna_search("Who won the 2024 US Presidential Election?")

# Good for: "What is the capital of France?"
answer = client.qna_search("Capital of France")

Additional Resources

  • Tavily Documentation: https://docs.tavily.com
  • Python SDK: https://github.com/tavily-ai/tavily-python
  • JavaScript SDK: https://github.com/tavily-ai/tavily-js
  • API Reference: https://docs.tavily.com/documentation/api-reference

Skill Maintenance

This skill requires:

  • TAVILY_API_KEY environment variable set
  • tavily-python package installed (pip install tavily-python)

For issues or updates, refer to the Tavily documentation or GitHub repository.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 19:16 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

self-improving agent

pskoett
捕获经验教训、错误和纠正,以实现持续改进。使用时机:(1)命令或操作意外失败;(2)用户纠正……
★ 4,055 📥 795,910
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,349 📥 317,697
ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 709 📥 243,527