S tavily search

From xg-gh-25/SwarmAI · View interactive version

S tavily search is an AI agent skill from the GitHub repository xg-gh-25/SwarmAI. Web search and content extraction through the Tavily API: search, AI answers, extract URLs. TRIGGER: \"search the web\", \"web search\", \"tavily\", \"find online\", \"搜一下\". NOT FOR: multi-round research (deep-research).

How to use this skill

Skill file

Tavily Search

Why? WebFetch can only grab a single known URL. Tavily searches the entire web, returns ranked results with relevance scores, and can generate AI-powered answers -- all in one API call. Essential for answering "what's the latest on X?" or powering research workflows.


Quick Start

"Search the web for latest AI agent frameworks"
"What's the latest news about OpenAI?"
"Extract the main content from these 5 URLs"

Setup — resolving the key (robust in ANY session)

The key lives in ~/.swarm-ai/SwarmWS/.claude/settings.local.json → env.TAVILY_API_KEY.

The harness injects it as $TAVILY_API_KEY **only on sessions spawned AFTER the key was

saved** — an older tab's process env is empty, so echo $TAVILY_API_KEY can be blank even

though the key is configured. Never conclude "key not set" from an empty env var alone.

Always resolve the key env-first, settings-file-fallback — this one line works in every

session, old or new. Put it at the top of any Tavily call:

TAVILY_API_KEY="${TAVILY_API_KEY:-$("$SWARM_BACKEND_BIN" py -c "import json,os;print(json.load(open(os.path.expanduser('~/.swarm-ai/SwarmWS/.claude/settings.local.json')))['env']['TAVILY_API_KEY'])" 2>/dev/null)}"

(settings.local.json is gitignored → the key never leaves the machine.)

💰 Free-tier only — do NOT incur paid usage

This account is on the free Researcher plan (1,000 credits/month). Keep it free:

Do not auto-fall-back to any paid tier.

the user explicitly needs depth.

```bash

curl -s https://api.tavily.com/usage -H "Authorization: Bearer $TAVILY_API_KEY"

```

account.plan_usage / plan_limit = free-tier counter; paygo_usage must stay 0.

Basic search = 1 credit. Advanced search = 2 credits.


API Reference

Search

POST https://api.tavily.com/search

curl -s -X POST https://api.tavily.com/search \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "latest AI agent frameworks 2026",
    "search_depth": "basic",
    "max_results": 5,
    "include_answer": "basic"
  }'

Parameters:

| Parameter | Type | Default | Description |

|---|---|---|---|

| query | string | (required) | Search query |

| search_depth | string | basic | basic (fast, 1 credit) or advanced (thorough, 2 credits) |

| max_results | int | 5 | Number of results (0-20) |

| include_answer | bool/string | false | true, "basic", or "advanced" -- returns AI-generated answer |

| include_raw_content | bool/string | false | true, "markdown", or "text" -- returns full page content |

| topic | string | general | "general" or "news" |

| time_range | string | none | "day", "week", "month", "year" |

| country | string | none | ISO country code to boost results (e.g., "us", "tw", "cn") |

| include_images | bool | false | Return related images |

| exclude_domains | array | none | Domains to exclude (e.g., ["pinterest.com"]) |

| include_domains | array | none | Limit search to specific domains |

Response:

{
  "query": "latest AI agent frameworks 2026",
  "answer": "AI-generated summary of search results...",
  "results": [
    {
      "title": "Page Title",
      "url": "https://example.com/article",
      "content": "Relevant snippet from the page...",
      "score": 0.95,
      "published_date": "2026-03-07"
    }
  ],
  "response_time": 1.23
}

Extract

POST https://api.tavily.com/extract

curl -s -X POST https://api.tavily.com/extract \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://example.com/article1",
      "https://example.com/article2"
    ],
    "format": "markdown"
  }'

Parameters:

| Parameter | Type | Default | Description |

|---|---|---|---|

| urls | string/array | (required) | Single URL or up to 20 URLs |

| query | string | none | Reranks extracted chunks by relevance |

| chunks_per_source | int | 3 | Chunks per URL (1-5, requires query) |

| extract_depth | string | basic | "basic" (1 credit/5 URLs) or "advanced" (2 credits/5 URLs) |

| format | string | markdown | "markdown" or "text" |

| include_images | bool | false | Include image URLs from pages |

Response:

{
  "results": [
    {
      "url": "https://example.com/article1",
      "raw_content": "# Article Title\n\nFull markdown content..."
    }
  ],
  "failed_results": [],
  "response_time": 2.1
}

Workflow

Step 1: Determine Search Type

| User Request | Search Configuration |

|---|---|

| General question | search_depth: "basic", include_answer: "basic" |

| Current events / news | topic: "news", time_range: "week" |

| Thorough research | search_depth: "advanced", max_results: 10 |

| Region-specific | Add country parameter |

| Domain-specific | Use include_domains |

| Competitive analysis | Multiple searches + extract |

Step 2: Execute Search

curl -s -X POST https://api.tavily.com/search \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "user query here",
    "search_depth": "basic",
    "max_results": 5,
    "include_answer": "basic"
  }'

Step 3: Present Results

Format results clearly:

## Search Results: [query]

**AI Answer:** [Tavily's generated answer if requested]

**Sources:**
1. [Title](url) (relevance: 95%)
   Key snippet from the page...

2. [Title](url) (relevance: 88%)
   Key snippet from the page...

3. ...

Step 4: Offer Follow-ups

After presenting results:


Common Patterns

Quick Answer

When user just wants a fast answer:

curl -s -X POST https://api.tavily.com/search \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "what is the current population of Taiwan",
    "include_answer": "advanced",
    "max_results": 3
  }'

Present the answer field directly, with sources listed below.

News Check

curl -s -X POST https://api.tavily.com/search \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "OpenAI latest announcements",
    "topic": "news",
    "time_range": "week",
    "max_results": 5,
    "include_answer": "basic"
  }'

Batch Content Extraction

When you have multiple URLs and need their content:

curl -s -X POST https://api.tavily.com/extract \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://article1.com",
      "https://article2.com",
      "https://article3.com"
    ],
    "format": "markdown",
    "query": "focus topic for relevance ranking"
  }'

Search + Extract Pipeline

For thorough research on a topic:

  1. Search to find relevant URLs
  2. Extract full content from top results
  3. Summarize or analyze
# Step 1: Search
RESULTS=$(curl -s -X POST https://api.tavily.com/search \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "topic", "max_results": 5}')

# Step 2: Extract top URLs (parse from results)
curl -s -X POST https://api.tavily.com/extract \
  -H "Authorization: Bearer $TAVILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["url1", "url2", "url3"], "format": "markdown"}'

# Step 3: Summarize extracted content

Powering Other Skills

Tavily is a building block for other skills:

| Skill | How Tavily Helps |

|---|---|

| s_deep-research | Primary search engine for multi-round research |


Cost Management

| Operation | Credits |

|---|---|

| Basic search | 1 |

| Advanced search | 2 |

| Basic extract (per 5 URLs) | 1 |

| Advanced extract (per 5 URLs) | 2 |

Free tier: 1,000 credits/month

Tips to conserve credits:


Troubleshooting

| Problem | Solution |

|---------|----------|

| $TAVILY_API_KEY empty | Old-session env not injected — use the env-first/settings-fallback resolver in Setup. Do NOT conclude the key is missing. |

| 401 Unauthorized | Key actually invalid/expired (resolver returned a bad value). Check at app.tavily.com |

| 429 Rate limited | Too many requests. Wait and retry |

| 432 Credit limit | Free monthly credits exhausted. STOP, tell the user, wait for reset — never upgrade/enable paygo to bypass. |

| Empty results | Try broader query, remove domain restrictions, check spelling |

| Extract fails for URL | Site may block bots. Try extract_depth: "advanced" |

| Slow response | Use search_depth: "basic" or reduce max_results |

| Results not recent enough | Add time_range: "day" or "week" |


Quality Rules

Verification

Before marking this task complete, show evidence for each:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.