Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/BHARTIYAYASH/TRUTH-MAPPER/llms.txt

Use this file to discover all available pages before exploring further.

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

export const webSearch = ai.defineTool(
  {
    name: 'webSearch',
    description: 'Searches the web using Firecrawl for maximum coverage. Returns results from trusted news sources.',
    inputSchema: WebSearchInputSchema,
    outputSchema: WebSearchOutputSchema,
  },
  async (input) => { ... }
)

As Standalone Function

export async function searchWeb(
  query: string
): Promise<{ title: string; link: string; snippet: string }[]>
Source: src/ai/tools/web-search.ts:54

Input Schema

query
string
required
The search query.

Input Type

const WebSearchInputSchema = z.object({
  query: z.string().describe('The search query.'),
});

Output Schema

results
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

const WebSearchResultSchema = z.object({
  title: z.string().describe('The title of the search result.'),
  link: z.string().describe('The URL of the search result.'),
  snippet: z.string().describe('A brief summary of the search result.'),
});

const WebSearchOutputSchema = z.array(WebSearchResultSchema);

Trusted News Outlets

The tool filters results to prioritize these trusted sources:
const TRUSTED_NEWS_OUTLETS = [
  "opindia.com",
  "swarajyamag.com",
  "thehindu.com",
  "indianexpress.com",
  "hindustantimes.com",
  "timesofindia.indiatimes.com",
  "ndtv.com",
  "bbc.com",
  "reuters.com",
  "aljazeera.com",
  "cnn.com",
  "nytimes.com",
  "washingtonpost.com",
  "theguardian.com",
  "businesstoday.in",
  "livemint.com",
  "economictimes.indiatimes.com",
  "firstpost.com",
  "wionews.com",
  "apnews.com",
  "bloomberg.com",
  "cnbc.com",
  "pib.gov.in",
];

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

import { searchWeb } from '@/ai/tools/web-search';

const results = await searchWeb('climate change policy');

console.log(`Found ${results.length} results`);

results.forEach(result => {
  console.log(`${result.title} - ${result.link}`);
  console.log(result.snippet);
});

As AI Tool

import { ai } from '@/ai/genkit';
import { webSearch } from '@/ai/tools/web-search';

const response = await ai.generate({
  prompt: 'Find the latest news on climate change',
  tools: [webSearch],
});

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

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

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

Build docs developers (and LLMs) love