Skip to main content

Overview

The webSearch tool performs web searches using the Firecrawl API, filtering results to prioritize trusted news outlets. It’s designed to find high-quality, diverse sources for argument analysis.

Function Signature

As Genkit Tool

As Standalone Function

Source: src/ai/tools/web-search.ts:54

Input Schema

string
required
The search query.

Input Type

Output Schema

WebSearchResult[]
required
An array of search results from trusted news sources.Each result contains:
  • title: The title of the search result
  • link: The URL of the search result
  • snippet: A brief summary of the content

Output Type

Trusted News Outlets

The tool filters results to prioritize these trusted sources:

How It Works

  1. Site Filtering: Constructs a search query with site: filters for trusted outlets
  2. Firecrawl Request: Sends request to Firecrawl API with 20 result limit
  3. Fallback: If filtered search returns few results, performs general search
  4. Deduplication: Removes duplicate URLs before returning
  5. Formatting: Returns up to 20 results with title, link, and snippet

Example Usage

Standalone Function

As AI Tool

Configuration

Firecrawl API Settings:
  • Limit: 20 results per request
  • Language: English (en)
  • Scrape Options: Markdown format
  • Endpoint: https://api.firecrawl.dev/v1/search

Environment Variables

string
required
Your Firecrawl API key. Get one at firecrawl.dev.

Error Handling

The tool includes multiple fallback mechanisms:
  • If trusted source search fails, performs general search
  • If Firecrawl returns < 5 results, adds general search results
  • Returns empty array if all searches fail (no throw)
  • Logs warnings for debugging

Performance

  • Average response time: 1-3 seconds
  • Returns up to 20 results
  • Automatically retries with general search if needed
  • Optimized for diversity and quality over quantity