使用 Tavily 的 LLM 优化搜索 API 在网上搜索,返回包含内容片段、评分和元数据的相关结果。适用于无需编写代码即可查找任意主题的网页内容。
搜索技能 搜索网络并获得相关结果, 以优化 LLM 的消耗.是一项面向实际任务的技能,主要用于Prerequists.;Tavily API Key 需要 - 获取您的 key , 请访问 https://tavily.com.;
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
在 Web 上执行搜索,并返回专为大语言模型(LLM)消费而优化的相关结果。
需要 Tavily API 密钥 —— 请前往 https://tavily.com 获取您的密钥
将其添加到 ~/.claude/settings.json 中:
{
"env": {
"TAVILY_API_KEY": "tvly-your-api-key-here"
}
}
./scripts/search.sh ''
示例:
# 基础搜索
./scripts/search.sh '{"query": "python async patterns"}'
# 带选项的搜索
./scripts/search.sh '{"query": "React hooks tutorial", "max_results": 10}'
# 带过滤器的高级搜索
./scripts/search.sh '{"query": "AI news", "topic": "news", "time_range": "week", "max_results": 10}'
# 按域名过滤的搜索
./scripts/search.sh '{"query": "machine learning", "include_domains": ["arxiv.org", "github.com"], "search_depth": "advanced"}'
curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "latest developments in quantum computing",
"max_results": 5
}'
curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "machine learning best practices",
"max_results": 10,
"search_depth": "advanced",
"include_domains": ["arxiv.org", "github.com"],
"chunks_per_source": 3
}'
POST https://api.tavily.com/search
| Header | 值 |
|---|---|
Authorization |
Bearer |
Content-Type |
application/json |
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
query |
string | 必填 | 搜索查询语句(建议控制在 400 字符以内) |
max_results |
integer | 5 | 最多返回结果数(取值范围:0–20) |
search_depth |
string | "basic" |
可选值:ultra-fast、fast、basic、advanced |
topic |
string | "general" |
可选值:general、news、finance |
chunks_per_source |
integer | 3 | 每来源返回的文本块数量(仅 advanced 和 fast 模式支持) |
time_range |
string | null | 可选值:day、week、month、year |
include_domains |
array | [] | 指定需包含的域名列表(最多支持 300 个) |
exclude_domains |
array | [] | 指定需排除的域名列表(最多支持 150 个) |
include_answer |
boolean | false | 是否包含 AI 生成的答案 |
include_raw_content |
boolean | false | 是否包含网页全文内容 |
include_images |
boolean | false | 是否包含图片结果 |
{
"query": "latest developments in quantum computing",
"results": [
{
"title": "Page Title",
"url": "https://example.com/page",
"content": "Extracted text snippet...",
"score": 0.85
}
],
"response_time": 1.2
}
| 深度 | 延迟 | 相关性 | 内容类型 |
|---|---|---|---|
ultra-fast |
最低 | 较低 | NLP 摘要 |
fast |
较低 | 良好 | 文本块(Chunks) |
basic |
中等 | 高 | NLP 摘要 |
advanced |
较高 | 最高 | 文本块(Chunks) |
各搜索深度适用场景:
ultra-fast:实时对话、自动补全等对延迟极度敏感的场景fast:需要文本块(Chunks),但延迟仍为关键考量因素basic:通用搜索场景,兼顾速度与质量的平衡选择advanced:对结果精度要求极高(推荐作为默认选项)curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "AI news today",
"topic": "news",
"time_range": "day",
"max_results": 10
}'
curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "Python async best practices",
"include_domains": ["docs.python.org", "realpython.com", "github.com"],
"search_depth": "advanced"
}'
curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "React hooks tutorial",
"max_results": 3,
"include_raw_content": true
}'
curl --request POST
--url https://api.tavily.com/search
--header "Authorization: Bearer $TAVILY_API_KEY"
--header 'Content-Type: application/json'
--data '{
"query": "AAPL earnings Q4 2024",
"topic": "finance",
"max_results": 10
}'
include_domains 限定可信信源范围time_range 确保获取最新信息score 字段(取值范围 0–1)进行筛选 —— 保留高相关性结果相关专题
热门下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.3万人学习
共49课时 | 82.7万人学习
最新文章