Skip to main content

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

Metadata

Release files for agentarch-search-tools 1.0.2

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

Source distribution (sdist)

Source distribution for agentarch-search-tools 1.0.2
File Size Uploaded
agentarch_search_tools-1.0.2.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentarch-search-tools 1.0.2
File Interpreter ABI Platform
agentarch_search_tools-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / agentarch_search_tools-1.0.2.tar.gz

Download URL agentarch_search_tools-1.0.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4e01217463461ea0fc8c491f0cfd954fdc75e0e14ba71aabf36225dd0412c68d
BLAKE2b-256 checksum
How to use checksums
2b5f41f2d65fc991b79706e600f1aabb479b34653a31708aa3ba03df01d43f09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release files / agentarch_search_tools-1.0.2-py3-none-any.whl

Download URL agentarch_search_tools-1.0.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
221f5d2298f45cfc4fcf5fa334cb9ba846b1f93b1c3add388000b34c6ab839de
BLAKE2b-256 checksum
How to use checksums
7194bd0749fa983ce16472c32dcbc12478871c54271e24bcada4881af01103f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.0

2 release files

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