Metadata-Version: 2.5
Name: openai-agents-agentsearch
Version: 0.6.0
Summary: OpenAI Agents SDK function tools for AgentSearch: free live web search, plus pay-per-call news, extract, JS render, screenshots and search-and-read
Project-URL: Repository, https://github.com/agentsearchhq-coder/openai-agents-agentsearch
Project-URL: Issues, https://github.com/agentsearchhq-coder/openai-agents-agentsearch/issues
Project-URL: Homepage, https://agentsearchhq.com/?utm_source=openai-agents-agentsearch&utm_medium=package
Project-URL: Documentation, https://agentsearchhq.com/agents.md?utm_source=openai-agents-agentsearch&utm_medium=package
License-Expression: MIT
License-File: LICENSE
Keywords: agents,agentsearch,openai,openai-agents,tools,web-search,x402
Requires-Python: >=3.10
Requires-Dist: httpx>=0.25
Requires-Dist: openai-agents>=0.2
Requires-Dist: pydantic>=2
Provides-Extra: paid
Requires-Dist: x402[evm]>=2.0; extra == 'paid'
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# openai-agents-agentsearch

Function tools for the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) backed by [AgentSearch](https://agentsearchhq.com/?utm_source=openai-agents-agentsearch&utm_medium=package): live web search for agents. Free search needs no API key.

| Tool | Cost |
|---|---|
| `agentsearch_search` | **Free** with no wallet (up to 25 searches/day per IP, up to 5 results, no key). With a wallet and the `[paid]` extra, $0.003/call and unlimited (from 0.6.0; `AGENTSEARCH_MODE=free` or `search_mode="free"` keeps it free). |
| `agentsearch_news_search` | $0.003/call (recent news with publish dates; no results, no charge) |
| `agentsearch_extract` | $0.002/call (USDC on Base via x402 to AgentSearch) |
| `agentsearch_render` | $0.005/call (headless browser for JS pages) |
| `agentsearch_screenshot` | $0.004/call (PNG/JPEG saved to a local file; path returned) |
| `agentsearch_search_and_read` | $0.005/call (search plus the top pages' text in one payment) |

## Install

```bash
pip install -U openai-agents-agentsearch
```

## Quickstart

```python
from agents import Agent, Runner
from openai_agents_agentsearch import agentsearch_search, agentsearch_tools

agent = Agent(
    name="Researcher",
    instructions="Answer with current facts. Cite URLs.",
    tools=[agentsearch_search],          # or agentsearch_tools() for search + news + extract + render + screenshot + search_and_read
)
result = Runner.run_sync(agent, "What changed in the latest OpenAI Agents SDK release?")
print(result.final_output)
```

## Search modes

The model only sees `agentsearch_search(query, max_results=None)`; it can never choose paid search. The search mode is a developer setting:

```python
from openai_agents_agentsearch import agentsearch_tools, make_agentsearch_search

tools = agentsearch_tools(search_mode="free")   # keep search free even with a wallet; or make_agentsearch_search("free")
```

- `auto` (default since 0.6.0): paid ($0.003/call, unlimited) if the `[paid]` extra is installed and a wallet is set, otherwise the free relay.
- `free`: the free relay, even with a wallet (the opt-out).
- `paid`: unlimited paid search. Falls back to free with a logged warning if the `[paid]` extra or wallet is missing.

Every search result has an `agentsearch_mode` field (`free: ...` / `paid: ...`), and the first paid search in a process logs one `AgentSearch search mode: paid ...` line.

`AGENTSEARCH_MODE` (`free`/`paid`/`auto`) takes precedence over the developer setting.

`agentsearch_extract` accepts `formats` (`markdown`, `text`, `html`, `links`); `agentsearch_render` also accepts `formats` and `wait_for_selector`.

## Filters, news and screenshots (0.5.0)

Paid search, `agentsearch_news_search` and `agentsearch_search_and_read` accept `freshness` (day/week/month/year), `date_from`/`date_to` (YYYY-MM-DD), `country`, `language`, and up to 5 `include_domains`/`exclude_domains`; free search ignores them. `agentsearch_extract` accepts `max_chars` (up to 50000) and `include_links`. `agentsearch_screenshot` takes `url`, `format` (png/jpeg), `full_page`, `viewport_width`/`viewport_height` (e.g. 390x844 for mobile), saves the image in `AGENTSEARCH_SCREENSHOT_DIR` and returns its path, so base64 never floods the model's context. News, screenshot and search-and-read are direct-only (not on Pocket).

## Paid mode

Install the `paid` extra (`pip install "openai-agents-agentsearch[paid]"`) and set `AGENTSEARCH_WALLET_PRIVATE_KEY` to the private key of a **new wallet made only for this**, funded with a little USDC on Base (e.g. $1; no ETH needed). Since 0.3.0 each call is paid over x402 **directly to AgentSearch's own API** (`https://api.agentsearchhq.com`, USDC on Base, settled only on success) using the official x402 Python SDK: search $0.003, news $0.003, extract $0.002, render $0.005, screenshot $0.004, search-and-read $0.005. $1 covers about 500 extracts or 200 search-and-read calls. Prefer the Pocket Network Agentic Portal ($0.005 per call)? Set `AGENTSEARCH_PAYMENT_ROUTE=pocket`. Extract and render use the key directly, and from 0.6.0 search pays too ($0.003) unless you set `AGENTSEARCH_MODE=free` (or `agentsearch_tools(search_mode="free")`). If paid is chosen but the `[paid]` extra or the key is missing, search falls back to free with a logged warning.

**Reuse a wallet you already have (0.6.0+).** Instead of pasting a key, set `AGENTSEARCH_WALLET_FILE` to a file holding a 64-hex private key, or JSON with a `privateKey` field. `AGENTSEARCH_WALLET_FILE=agentcash` reuses AgentCash's `~/.agentcash/wallet.json`. The file is read only when signing and its contents are never logged. Encrypted keystores and remote signers (CDP server wallets) are not supported yet.

| Env var | Default |
|---|---|
| `AGENTSEARCH_MAX_TOTAL_ATOMIC` | `1000000` ($1.00 per process) |
| `AGENTSEARCH_PAYMENT_ROUTE` | `direct` (AgentSearch's x402 API); `pocket` = Pocket Network Agentic Portal at $0.005/call |
| `AGENTSEARCH_MAX_PER_CALL_ATOMIC` | `20000` on the direct route, `5000` on Pocket ($0.020 / $0.005; can only be lowered) |
| `AGENTSEARCH_SCREENSHOT_DIR` | a temp folder (`agentsearch-screenshots`) |
| `AGENTSEARCH_TIMEOUT_MS` | `30000` |
| `AGENTSEARCH_MODE` | unset = `auto` (`auto`, `free` or `paid`; overrides `search_mode`) |
| `AGENTSEARCH_WALLET_FILE` | unset (path to a wallet file instead of a pasted key; `agentcash` = `~/.agentcash/wallet.json`) |

Limits are checked before anything is signed. The key is not included in tool output or error messages. Paid results include a `payment` object.

## Errors

Tools return `"Error: ..."` strings instead of raising. A 429 from the free relay means the daily limit (up to 25 searches/day per IP) was hit, and the message explains how to upgrade. Search, news and search-and-read reject queries shorter than 2 characters (after trimming) before any request, so nothing is sent or charged; other 4xx errors from the free relay say to fix the input instead of retrying it unchanged.

## Development

```bash
pip install -e ".[test]" && pytest     # unit tests (mocked)
AGENTSEARCH_LIVE=1 pytest -k live       # one real free search
```

Docs: https://agentsearchhq.com/agents.md?utm_source=openai-agents-agentsearch&utm_medium=package

MIT
