"""Runnable example: the 5 Lordevo tools as LlamaIndex FunctionTools, each called once the way an agent would call it. No LLM key needed. Without AGENT_WALLET_KEY only free trial calls work (3 per IP per UTC day). python example.py Env: AGENT_WALLET_KEY (optional, a Base wallet holding a little USDC), LORDEVO_BASE_URL (default the live shop), LORDEVO_EXAMPLE_SITE (default https://example.com, the catalog's example input), LORDEVO_X402_NETWORK (default eip155:8453 = Base mainnet; only a test copy of the shop uses another one). """ import json import os from urllib.parse import urlparse from lordevo_x402 import LordevoSync from lordevo_llamaindex import lordevo_tools BASE = os.environ.get("LORDEVO_BASE_URL") or "https://shop.lordevo.com" def make_client() -> LordevoSync: """Free trial first, then pays per call. Same as LordevoSync.from_private_key(key, trial=True), with the network as a setting so the example also runs against a test copy of the shop.""" key = os.environ.get("AGENT_WALLET_KEY") if not key: return LordevoSync(base_url=BASE, trial=True) # free trial calls only from eth_account import Account from x402 import x402ClientSync from x402.http.clients import x402_requests from x402.mechanisms.evm.exact import register_exact_evm_client x = x402ClientSync() register_exact_evm_client(x, Account.from_key(key), networks=os.environ.get("LORDEVO_X402_NETWORK") or "eip155:8453") return LordevoSync(x402_requests(x), base_url=BASE, trial=True, max_price_usd=0.01) def main(): site = os.environ.get("LORDEVO_EXAMPLE_SITE") or "https://example.com" host = urlparse(site).hostname tools = lordevo_tools(make_client()) by_name = {t.metadata.name: t for t in tools} calls = [ ("page_markdown", {"url": site}), ("can_fetch", {"url": f"{site}/blog/post"}), ("tech_stack", {"url": site}), ("dns_lookup", {"host": host, "type": "MX"}), ("email_validate", {"email": f"jane@{host}"}), ("can_fetch", {"url": "ftp://not-a-web-url"}), # bad input: an instant tool that fails is not charged ] out = [] for name, args in calls: body = json.loads(by_name[name].call(**args).raw_output) free = bool((body.get("_trial") or {}).get("free")) out.append({"tool": name, "ok": "error" not in body, "free_trial": free, "error": body.get("error"), "charged": body.get("charged") if "error" in body else None}) print(name, f"error {body['error']}: {body.get('message')}" if "error" in body else ("ok (free trial)" if free else "ok")) schema = by_name["page_markdown"].metadata.get_parameters_dict() print("RESULT " + json.dumps({"framework": "llamaindex", "tools": [t.metadata.name for t in tools], "schema_keys": list(schema["properties"]), "calls": out})) if __name__ == "__main__": main()