Integrate an AI agent
For teams building an agent that buys or pays for people. Your agent checks every purchase with TheWavly just before paying, asks the user when a purchase goes beyond what they approved, and never pays when the answer is stop.
How the integration fits
- When the user approves a task, create a mandate from their words and limits.
- Just before each payment, create a check with the exact purchase.
- Act on the decision: pay on
proceed, send the approval link onask, and tell the user onstop. - After paying, report the outcome, or let the store redeem the payment token.
Tip: Start in shadow mode. Do steps 1 and 2, log the decision, and keep paying as you do today. Turn on step 3 once the answers look right on your traffic.
Create a mandate from the user's instruction
Keep the user's words verbatim in instruction, and turn their limits into rules. Use a short restricted key with the Agent preset for the agent itself.
const mandate = await wavly.mandates.create({
instruction: "Book a refundable room in Goa under ₹4,000 for 12–14 Dec",
approved_by: "user_7f3", // your reference, never a name or phone number
agent: "tripbot",
rules: {
items: ["Hotel room"], max_amount_paise: 400000, budget_paise: 800000,
conditions: [{ term: "refundable", equals: true, label: "a refundable room" },
{ term: "free_cancellation_hours", at_least: 24 }],
},
});Check before paying
Send the purchase exactly as the seller presented it, including the terms the conditions refer to. Use your order id as the idempotency key, so a retry never creates a second check.
const purchase = { item: "Hotel room", amount_paise: 370000, merchant: "Sea View Inn", payee: "seaview@okhdfc",
terms: { refundable: true, free_cancellation_hours: 48 } };
const check = await wavly.checks.create({ mandate: mandate.id, purchase }, { idempotencyKey: "order-1042" });
if (check.decision === "proceed") { /* pay; see "Pay at the store" below */ }
else if (check.decision === "ask") { notifyUser(check.approval.share.whatsapp); } // then wait for approval.approved
else { tellUser(check.results.filter(r => r.result !== "match")); }Ask the user
On ask, send the user check.approval.url, or one of approval.share.whatsapp, approval.share.sms and approval.share.url_hi (Hindi). The page shows exactly what is being bought and which limit it goes beyond. Listen for approval.approved on your webhook, or poll the check. Once approved, POST /v1/checks/{id}/payment_token issues a fresh token for the approved purchase.
Sign as a registered agent
An API key says which company called, not which agent. Register the agent in the public registry, prove its website, and add its public key. Then every check is signed by the agent and counts toward its public record, and stores can verify it.
await wavly.registry.register({ handle: "tripbot", name: "Trip Assistant", website: "trips.example.in" });
// Publish the returned file at https://trips.example.in/.well-known/wavly-agents.json, then:
await wavly.registry.verifyDomain("tripbot");
await wavly.registry.addKey("tripbot", { jwk: publicJwk }); // Ed25519 or P-256
// From then on, pass the identity once; every check is signed
const agentClient = new Wavly(process.env.WAVLY_API_KEY, { agent: { id: "tripbot", privateKey: privateJwk } });The Python, Go and Java SDKs do the same: Wavly(key, agent={...}), wavly.WithAgent(...) and withAgent(...).
Pay at the store
At a store that takes TheWavly (it serves /.well-known/wavly-merchant.json), send two headers with the order. The store verifies them and redeems the token before charging.
const headers = Wavly.checkoutHeaders(check, "tripbot"); // Wavly-Agent and Wavly-Payment-Token
await fetch(store + "/checkout", { method: "POST", headers: { ...headers, "content-type": "application/json" }, body });Elsewhere, pay as usual and report the outcome with POST /v1/checks/{id}/outcome.
Make the check impossible to skip
An agent that has been manipulated can simply not ask. TheWavly Guard sits in front of your order and payment tools and holds every call until TheWavly answers, reading the real total from your own cart. It works in front of an MCP server, or around the payment function in LangChain, the Vercel AI SDK and the OpenAI Agents SDK. Inside a guarded function, checkoutHeaders() gives you the headers for the store. See TheWavly Guard.
MCP
Agents built on the Model Context Protocol can use TheWavly's MCP server from the SDK bundle. It exposes wavly_create_mandate, wavly_check_purchase, wavly_get_check and wavly_report_payment. Set WAVLY_AGENT and WAVLY_AGENT_KEY_FILE to sign as a registered agent.