# Lordevo tools for LlamaIndex

> Needs `lordevo-x402` **0.1.5 or later** (on npm and PyPI; 0.1.3 lacks `trial=True`).

Five web tools as LlamaIndex `FunctionTool`s, paid per call with x402 (USDC on Base). No account and no API key. Useful for RAG ingestion: `page_markdown` turns a web page into clean Markdown, and `can_fetch` checks robots.txt before you crawl.

| Tool | What it does | Price per call |
|---|---|---|
| `page_markdown` | A web page as clean, LLM-ready Markdown | $0.002 |
| `can_fetch` | robots.txt + AI-crawler permission check for a URL | $0.002 |
| `tech_stack` | What a site is built with (CMS, frameworks, analytics) | $0.002 |
| `dns_lookup` | DNS records (A, AAAA, CNAME, MX, TXT, NS, SOA, CAA) | $0.002 |
| `email_validate` | Email syntax + domain + MX (no mailbox probing) | $0.002 |

Prices are from the shop's price table (checked 13 Nov 2026; the published `lordevo-x402` 0.1.5 lists the same prices). The live price is always the one in the HTTP 402 and in https://shop.lordevo.com/catalog.json.

## Install
```bash
pip install "lordevo-x402[pay]>=0.1.5" llama-index-core
```
Copy `lordevo_llamaindex.py` next to your code.

## Use (5 lines)
```python
import os
from llama_index.core.agent.workflow import FunctionAgent
from lordevo_x402 import LordevoSync
from lordevo_llamaindex import lordevo_tools
agent = FunctionAgent(tools=lordevo_tools(LordevoSync.from_private_key(os.environ["AGENT_WALLET_KEY"], trial=True, max_price_usd=0.01)), llm=llm)
```
`llm` is any LlamaIndex LLM with tool calling. Then `await agent.run("Read https://example.com and summarise it.")`. `lordevo_tools(client, ["page-markdown"])` picks other tools.

## Free trial
With `trial=True` the first calls of the day are free: 3 calls per IP per UTC day on tools priced up to $0.005 (all five tools here). After that the client pays. Without a wallet key, use `LordevoSync(trial=True)`: free calls only; when they are used up the tool returns `{"error": "payment_required", ...}` to the model.

## How payment works
An unpaid request gets HTTP 402 with the price. The x402 requests session signs a USDC payment from your agent wallet on Base and retries; the shop's facilitator settles it, so the wallet needs USDC but no ETH for gas. `max_price_usd` refuses any tool priced above it before a request is made. Answers of 400 or higher are not charged. Use a separate agent wallet with a small balance; key in an environment variable, never in code.

## Errors
The tools never raise: errors reach the model as JSON with `error`, `message` and `charged` (always `false` for errors).

## Run the example
```bash
python example.py                              # free trial calls only
AGENT_WALLET_KEY=0x... python example.py       # free first, then paid
```

MIT licence. LlamaIndex is MIT-licensed; only its public `FunctionTool.from_defaults` API is used.

## Files
- [example.py](https://shop.lordevo.com/guides/sdk/llamaindex/example.py)
- [lordevo_llamaindex.py](https://shop.lordevo.com/guides/sdk/llamaindex/lordevo_llamaindex.py)

All SDK guides: https://shop.lordevo.com/guides/sdk
