Metadata-Version: 2.4
Name: x402-agent-tools
Version: 0.1.0
Summary: Pay-per-call AI Agent Tools (Web Reader, Search, JSON Extractor, CAPTCHA solver) with automated x402 Base USDC micropayments
Author-email: drain54 <indradarmawan87@gmail.com>
License: MIT
Keywords: agent,x402,langchain,crewai,elizaos,usdc,base,micropayments
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.25.0
Requires-Dist: eth-account>=0.11.0
Requires-Dist: eth-utils>=2.0.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: langchain
Requires-Dist: langchain>=0.1.0; extra == "langchain"
Provides-Extra: crewai
Requires-Dist: crewai>=0.28.0; extra == "crewai"
Provides-Extra: all
Requires-Dist: langchain>=0.1.0; extra == "all"
Requires-Dist: crewai>=0.28.0; extra == "all"

# x402 Agent Tools ⚡

**Zero API-key, pay-per-call agent tools for LangChain, CrewAI, and ElizaOS.**  
Powered by open **x402** micropayments in USDC on **Base mainnet**.

Agents sign an EIP-3009 transfer authorization with their own EVM key for fractions of a cent per call. No credit cards, no monthly SaaS subscriptions.

---

## Tools Included

| Tool | Endpoint | Cost | Description |
|---|---|---|---|
| **Web Reader** | `/v1/read` | $0.005 | Strips ads and boilerplate, extracts clean Markdown + tokens |
| **Web Search** | `/v1/search` | $0.005 | Live multi-engine search (TinyFish, DDGS, Jina) |
| **JSON Extractor** | `/v1/extract-json` | $0.015 | Schema-driven structured data extraction |
| **Stealth Fetch** | `/v1/fetch-stealth` | $0.010 | Browser TLS & headers impersonation for anti-bot bypass |
| **CAPTCHA Solver** | `/v1/solve-captcha` | $0.001–0.0025 | Solves Turnstile, reCAPTCHA v2, Cloudflare |

---

## Installation

```bash
pip install x402-agent-tools
# or for LangChain / CrewAI:
pip install "x402-agent-tools[langchain]"
pip install "x402-agent-tools[crewai]"
```

---

## Quickstart (Python SDK)

```python
import os
from x402_agent_tools import X402Client

client = X402Client(private_key=os.getenv("EVM_PRIVATE_KEY"))

# 1. Read webpage into clean markdown ($0.005)
markdown = await client.read_web_page("https://news.ycombinator.com")
print(markdown["content"])

# 2. Live web search ($0.005)
results = await client.search_web("Base L2 ecosystem news")
for r in results["results"]:
    print(r["title"], "->", r["url"])

# 3. Extract structured JSON ($0.015)
product = await client.extract_json(
    url="https://example.com/product",
    schema={"fields": ["name", "price", "stock_status"]}
)
print(product["data"])
```

---

## LangChain / LangGraph Integration

```python
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from x402_agent_tools.langchain import X402WebReaderTool, X402WebSearchTool

llm = ChatOpenAI(model="gpt-4o-mini")
tools = [
    X402WebReaderTool(private_key="0x..."),
    X402WebSearchTool(private_key="0x...")
]

agent = initialize_agent(tools, llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION)
agent.run("What are the latest developer updates on Base blockchain?")
```

---

## CrewAI Integration

```python
from crewai import Agent, Task, Crew
from x402_agent_tools.crewai import CrewWebReaderTool, CrewWebSearchTool

researcher = Agent(
    role="Web Researcher",
    goal="Gather live web intel without needing third-party API keys",
    tools=[CrewWebSearchTool(), CrewWebReaderTool()],
    verbose=True
)
```

---

## ElizaOS Plugin (TypeScript)

For ElizaOS agents, use the included plugin:

```bash
npm install @drain54/plugin-x402-tools
```

In `character.json`:
```json
{
  "name": "ResearchBot",
  "plugins": ["@drain54/plugin-x402-tools"],
  "settings": {
    "secrets": {
      "EVM_PRIVATE_KEY": "0x..."
    }
  }
}
```

---

## Architecture & Settlement

1. Agent sends request to `https://verify.drain54.my.id/v1/...`
2. Server returns `402 Payment Required` with exact USDC amount and EIP-712 domain.
3. Client signs standard EIP-3009 `TransferWithAuthorization`.
4. PayAI facilitator verifies signature and broadcasts gasless Multicall3 settlement on Base.
5. Server fulfills request with fresh data.

## License
MIT
