// Runnable example: the 5 Lordevo tools as OpenAI Agents SDK (JS) 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). // node example.mjs // 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). import { RunContext } from '@openai/agents'; import { createLordevo, fromPrivateKey } from 'lordevo-x402'; import { lordevoTools } from './lordevo-agents.mjs'; const baseUrl = process.env.LORDEVO_BASE_URL || 'https://shop.lordevo.com'; const site = process.env.LORDEVO_EXAMPLE_SITE || 'https://example.com'; const host = new URL(site).hostname; const lordevo = process.env.AGENT_WALLET_KEY ? await fromPrivateKey(process.env.AGENT_WALLET_KEY, { baseUrl, trial: true, maxPriceUsd: 0.01 }) // free calls first, then pays : createLordevo({ baseUrl, trial: true }); // free trial calls only const tools = lordevoTools(lordevo); const byName = Object.fromEntries(tools.map(t => [t.name, t])); const calls = [ ['page_markdown', { url: site, include_links: null, max_tokens: null }], ['can_fetch', { url: `${site}/blog/post` }], ['tech_stack', { url: site }], ['dns_lookup', { host, type: 'MX' }], ['email_validate', { email: `jane@${host}` }], ['can_fetch', { url: 'ftp://not-a-web-url' }], // bad input: an instant tool that fails is not charged ]; const out = []; for (const [name, input] of calls) { const body = JSON.parse(await byName[name].invoke(new RunContext(), JSON.stringify(input))); out.push({ tool: name, ok: !body.error, free_trial: !!body._trial?.free, error: body.error || null, charged: body.error ? body.charged : undefined }); console.log(name, body.error ? `error ${body.error}: ${body.message}` : `ok${body._trial?.free ? ' (free trial)' : ''}`); } console.log('RESULT ' + JSON.stringify({ framework: 'openai-agents-js', tools: tools.map(t => t.name), schema_keys: Object.keys(byName.page_markdown.parameters.properties), strict: byName.page_markdown.strict, calls: out }));