Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:666ghj BettaFish TavilyNewsAgency search

From Leeroopedia
Knowledge Sources
Domains Information_Retrieval, News_Search, Web_Search
Last Updated 2026-10-08 00:00 GMT

Overview

Concrete API wrapper client for the Tavily news search service providing six specialized news search methods for the QueryEngine pipeline.

Description

The TavilyNewsAgency class wraps the Tavily API client, providing six AI Agent-callable search tools: basic news search, deep news analysis, last 24 hours, last week, news images, and date-range search. Each tool targets a different news research strategy. The class handles API authentication, request construction, response parsing into typed dataclasses (TavilyResponse, SearchResult, ImageResult), and retry logic.

Usage

Import this class when you need news search for the QueryEngine pipeline. It is initialized by `DeepSearchAgent.__init__` in QueryEngine.

Code Reference

Source Location

  • Repository: BettaFish
  • File: `QueryEngine/tools/search.py:L77-251`

Signature

class TavilyNewsAgency:
    def __init__(self, api_key: Optional[str] = None):
        """Args: api_key - Tavily API key (defaults to env TAVILY_API_KEY)"""

    def basic_search_news(self, query: str, max_results: int = 7) -> TavilyResponse:
        """Standard fast news search."""

    def deep_search_news(self, query: str) -> TavilyResponse:
        """Deep analysis with advanced AI summary and up to 20 results."""

    def search_news_last_24_hours(self, query: str) -> TavilyResponse:
        """News from the last 24 hours only."""

    def search_news_last_week(self, query: str) -> TavilyResponse:
        """News from the last week."""

    def search_images_for_news(self, query: str) -> TavilyResponse:
        """News-related images with descriptions."""

    def search_news_by_date(self, query: str, start_date: str, end_date: str) -> TavilyResponse:
        """News within a specific date range (YYYY-MM-DD format)."""

Import

from QueryEngine.tools.search import TavilyNewsAgency, TavilyResponse

I/O Contract

Inputs

Name Type Required Description
query str Yes News search query
max_results int No Max results (varies by tool)
start_date/end_date str For date search YYYY-MM-DD format

Outputs

Name Type Description
TavilyResponse dataclass query, answer, results (List[SearchResult]), images, response_time
SearchResult dataclass title, url, content, score, published_date

Usage Examples

Basic News Search

from QueryEngine.tools.search import TavilyNewsAgency

agency = TavilyNewsAgency(api_key="tvly-...")

response = agency.basic_search_news("人工智能政策", max_results=7)
for r in response.results:
    print(f"  [{r.published_date}] {r.title}")

Date Range Search

response = agency.search_news_by_date(
    "教育改革",
    start_date="2024-01-01",
    end_date="2024-06-30"
)
print(f"Found {len(response.results)} news articles")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment