"""Runnable example: the 5 Lordevo tools as OpenAI Agents SDK function tools, each invoked once the way the Runner would call it. No OpenAI 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 asyncio import json import os from urllib.parse import urlparse from agents.tool_context import ToolContext from lordevo_x402 import LordevoSync from lordevo_agents import lordevo_function_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) async def main(): site = os.environ.get("LORDEVO_EXAMPLE_SITE") or "https://example.com" host = urlparse(site).hostname tools = lordevo_function_tools(make_client()) by_name = {t.name: t for t in tools} calls = [ ("page_markdown", {"url": site, "include_links": None, "max_tokens": None}), ("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 i, (name, args) in enumerate(calls): raw = json.dumps(args) body = json.loads(await by_name[name].on_invoke_tool(ToolContext(None, tool_name=name, tool_call_id=f"example-{i}", tool_arguments=raw), raw)) 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")) print("RESULT " + json.dumps({"framework": "openai-agents-python", "tools": [t.name for t in tools], "schema_keys": list(by_name["page_markdown"].params_json_schema["properties"]), "strict": by_name["page_markdown"].strict_json_schema, "calls": out})) if __name__ == "__main__": asyncio.run(main())