Skip to main content

Web Search Agent

A modular Python package for intelligent web search that processes search results into structured, section-based information.

Overview

Web Search Agent is an infrastructure tool that performs web searches based on a given topic, processes the results using AI, and returns structured information organized into relevant sections. It helps users/developers quickly gather and organize comprehensive information on specific topics.

Features

  • Topic-based intelligent web searching
  • AI-powered query generation for comprehensive coverage
  • Automatic organization of search results into logical sections
  • Section-specific sub-queries for in-depth analysis
  • Structured JSON output for easy processing
  • Configurable search parameters and model settings
  • Support for multiple search APIs (Tavily, Exa)

Installation

Prerequisites

  • Python 3.11 or higher
  • OpenAI API key
  • Search API key (Tavily, Exa, etc.)

Installation Steps

# Create and activate a virtual environment (optional but recommended)
conda create -n web-search-agent python=3.11.11
conda activate web-search-agent

# Install from PyPI
pip install web-search-agent

# Or install from source
git clone https://github.com/leepokai/web-search-agent.git
cd web-search-agent
pip install -e .

# Set up environment variables
cp .env.example .env
# Edit .env file to add your API keys

Usage

Basic Usage

import asyncio
from web_search_agent import WebSearchAgent, WebSearchConfig

async def main():
    # Create a default agent
    agent = WebSearchAgent()
    
    # Search for a topic
    result = await agent.search("Artificial Intelligence ethics")
    
    # Process the results
    print(f"Topic: {result.title}")
    print(f"Found {len(result.sections)} sections")
    
    for section in result.sections:
        print(f"- {section.title}: {section.description[:100]}...")

# Run the async function
asyncio.run(main())

Advanced Usage

import asyncio
from web_search_agent import WebSearchAgent, WebSearchConfig, search_multiple_topics

async def research_project():
    # Custom configuration
    config = WebSearchConfig(
        planner_model="o1",
        initial_queries_count=3,
        max_sections=5,
        search_api="tavily",
        search_api_config={"include_raw_content": True, "max_results": 3}
    )
    
    # Search multiple topics
    topics = [
        "Renewable energy advancements",
        "Future of remote work"
    ]
    
    results = await search_multiple_topics(
        topics,
        config=config,
        verbose=True,
        save_output=True,
        output_dir="research_output"
    )
    
    # Process results
    for result in results:
        if hasattr(result, 'title'):  # Check if valid result
            print(f"\nTopic: {result.title}")
            for section in result.sections:
                print(f"- {section.title}")

# Run the async function
if __name__ == "__main__":
    asyncio.run(research_project())

Command Line Usage

# Basic usage
web-search-agent

API Reference

Main Classes

  • WebSearchAgent: Core class for performing searches and processing results
  • WebSearchConfig: Configuration class for customizing search behavior
  • WebSearchResult: Result container with all search data and sections

Key Functions

  • search_topic(topic, config=None, verbose=False): Search for a single topic
  • search_multiple_topics(topics, config=None, verbose=False, save_output=False): Search for multiple topics

Configuration Options

The WebSearchConfig class provides the following configuration options:

WebSearchConfig(
    # LLM Configuration
    llm_provider="openai",         # LLM provider (currently supports "openai")
    planner_model="o1",            # Model for planning and query generation
    
    # Search Configuration
    search_api="tavily",           # Search API (tavily, exa, etc.)
    search_api_config={            # Additional search API configuration
        "include_raw_content": True,
        "max_results": 3
    },
    
    # Query Generation
    initial_queries_count=3,       # Number of initial search queries
    section_queries_count=2,       # Number of search queries per section
    
    # Control Parameters
    max_sections=5,                # Maximum number of sections to generate
    must_cover_section_title="..." # Prompt for must-cover sections
)

Output Format

The tool outputs structured data with the following main fields:

  • title: Main search topic
  • initial_queries: List of initial search queries
  • initial_responses: Search results for each initial query
  • sections: List of generated sections
    • Each section contains: title, description, search queries and responses

Example Output

{
  "title": "Artificial Intelligence Ethics",
  "initial_queries": [...],
  "initial_responses": [...],
  "sections": [
    {
      "title": "Privacy concerns in AI systems",
      "description": "An analysis of how AI technologies impact personal privacy...",
      "search_queries": [...],
      "search_responses": [...]
    },
    ...
  ]
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for web-search-agent 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for web-search-agent 0.2.0
File Size Uploaded Provenance Actions
web_search_agent-0.2.0.tar.gz 14.0 kB Without provenance Details for web_search_agent-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for web-search-agent 0.2.0
File Interpreter ABI Platform Actions
web_search_agent-0.2.0-py3-none-any.whl Python 3 none any Details for web_search_agent-0.2.0-py3-none-any.whl

Total release size: 28.1 kB

Release files / web_search_agent-0.2.0.tar.gz

Download URL web_search_agent-0.2.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a91b8b3cd60ccd58ab34634082ecab9dd0e4cd86badd8d1dc0134278c5c6160f
BLAKE2b-256 checksum
How to use checksums
3e8cbc7a490d4e263eaf407310809d90b15dfbe40d79c40a671fb8eb7382240b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / web_search_agent-0.2.0-py3-none-any.whl

Download URL web_search_agent-0.2.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa50e4065a1ade4112abec7c5d68ca658ae1ebf379b0978475ed1f62eec81b29
BLAKE2b-256 checksum
How to use checksums
39157238cf571d3ddcf4a8978722a25dab245663e2b8b8c9d2c99e244c33532e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Security for web-search-agent 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page