Skip to main content

Web search tools with Google and DuckDuckGo support

Project description

Search Tools (Python @tool Pattern)

Web search capabilities using Google (primary) and DuckDuckGo (fallback).

Installation

uv add tool-search-tools

Tools Provided

Tool Description
web_search Search with automatic Google → DuckDuckGo fallback
search_google Google only (requires API credentials)
search_duckduckgo DuckDuckGo only (no credentials needed)

Configuration

Google Search (Optional)

Set environment variables for Google Programmable Search Engine:

export GOOGLE_API_KEY="your-api-key"
export GOOGLE_CSE_ID="your-cse-id"

Without these, web_search automatically falls back to DuckDuckGo.

Rate Limiting (Optional)

export GOOGLE_SEARCH_RATE_LIMIT="1.0"      # requests per second
export GOOGLE_SEARCH_TIMEOUT="30.0"        # seconds
export DUCKDUCKGO_SEARCH_RATE_LIMIT="1.0"
export DUCKDUCKGO_SEARCH_TIMEOUT="30.0"

Usage

Direct Invocation

from search_tools import web_search

result = await web_search.ainvoke({"query": "python async tutorial", "num_results": 5})

print(result["provider"])  # "google" or "duckduckgo"
for r in result["results"]:
    print(f"{r['title']}: {r['url']}")

With LangGraph

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import ToolNode
from search_tools import web_search

tools = [web_search]
llm = ChatOpenAI(model="gpt-4o-mini")
llm_with_tools = llm.bind_tools(tools)
tool_node = ToolNode(tools)

Response Format

{
    "results": [
        {"title": "Page Title", "url": "https://...", "snippet": "Description..."},
        ...
    ],
    "provider": "google",  # or "duckduckgo"
    "query": "original query",
    "count": 5
}

When to Use Which

Tool Use Case
web_search Default choice - automatic fallback
search_google Need Google specifically, handle errors yourself
search_duckduckgo Testing, or when Google quota exhausted

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentarch_search_tools-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentarch_search_tools-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file agentarch_search_tools-1.0.0.tar.gz.

File metadata

  • Download URL: agentarch_search_tools-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for agentarch_search_tools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 78bd8cd3724736a3ebbbdf34d59536252a638ebc8a8a9af68e75fe56a888a11d
MD5 0af3e0811ab5f5f3a77d6dd2de10d900
BLAKE2b-256 3bd637ad1ec25fb9f069e06fb955adf191f53e7032ae5b0d3e2408b780a8696d

See more details on using hashes here.

File details

Details for the file agentarch_search_tools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentarch_search_tools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 808130aa8fc9b5f39be0a118b4cdd2f914d5114bf9ba0dfa3f31f0c7e7d27439
MD5 34596181092d23910e301b2aaade7571
BLAKE2b-256 a6cda67b00e76a2e83f238e8dfbc61412a99f6bbaaff437d18e5577fa954dc25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page