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.2.tar.gz (6.8 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.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentarch_search_tools-1.0.2.tar.gz
  • Upload date:
  • Size: 6.8 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.2.tar.gz
Algorithm Hash digest
SHA256 4e01217463461ea0fc8c491f0cfd954fdc75e0e14ba71aabf36225dd0412c68d
MD5 539b0feb354806a86fb762ff99fd2477
BLAKE2b-256 2b5f41f2d65fc991b79706e600f1aabb479b34653a31708aa3ba03df01d43f09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agentarch_search_tools-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 221f5d2298f45cfc4fcf5fa334cb9ba846b1f93b1c3add388000b34c6ab839de
MD5 14e7dff852de319b5d762ef5d35afbad
BLAKE2b-256 7194bd0749fa983ce16472c32dcbc12478871c54271e24bcada4881af01103f4

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