Skip to content

Quickstart: let an Agent place an order ​

This page follows one scenario — finding the lowest price on Amazon and placing the order for the user — to show how a consumer app calls the Qoni SDK in order: once the user signs in to your app, your server obtains a scoped, time-bound delegation token for them, then lets the Agent shop through Web Agent. Whenever it needs the user, the Agent pauses and raises an interaction, handing the decision back to the user; the user pays themselves.

Toward the agentic web ​

Qoni's goal is to make agents first-class citizens of the web. Models think, the web is where agents act, and Qoni is the layer in between. The diagram shows the layers: a person delegates scoped, time-bound authority to the agent, and every step is audited; the agent works on web pages for the person in hosted cloud browsers, reusing sign-ins across tasks; when it is done, it hands the results back to the person.

Toward the agentic webA layered model: a person delegates scoped, audited authority to the agent, which works on the web in hosted cloud browsers and hands the results back.HTMLWebAgentHumanDelegate to agentEvery step auditedResults to humanHosted cloud browsersNo API neededSign-ins carry overRuns tasks in parallel

Qoni is managed infrastructure for personal agents. It gives an agent the three things it needs — identity, action and memory: GenAuth confirms who the person is and delegates scoped, time-bound authority to the agent, audited at every step; Web Agent lets the agent work on real websites in hosted cloud browsers, no API needed; GUMem remembers what the user said and did, so nothing has to be taught twice. All three come through one Qoni SDK.

Scenario ​

The user says one sentence to the shopping assistant in your app:

Open Amazon, search for the MacBook Neo 512GB, find the lowest price and place the order for me.

To turn that sentence into a real order, the Agent needs three things:

WhatWhyStep
The user's sessionEstablishes who is ordering; the token acts for this person onlyBefore you start
A delegation tokenLimits what the Agent may do and for how long1
A run that works with the userOpens pages, compares prices and checks out; asks the user to sign in, answer, fill in details, confirm or pay in person when needed2

How it fits together ​

The diagram shows the overall logic: the top half is authorization, and the bottom half runs for every order.

AuthorizationPer user · redo step 1 when the token expires
  1. GenAuthUser signed inSigned up or in on GenAuth’s hosted page
  2. 1GenAuthDelegate scoped accessObtained silently on your server
grant.tokencarries the user’s consent
Every orderOnce per task

Once the user signs in to your app, your server uses its AccessKey to obtain their delegation token silently, without a consent page; when the token expires, obtain a new one. For every order, DoAnything runs in a cloud browser and pauses when it needs the user. Sign-ins the user completes on websites are kept per user, reused by later tasks, and never visible to other users.

Before you start ​

  • Node.js 20.11 or later.
  • Qoni SDK 0.10.1 or later.
  • A Qoni AccessKey ID and Secret. In the Qoni Console, under AccessKey → Edit scopes, select WebAgent Do Anything, WebAgent Site Login and WebAgent Browser Takeover. A scope that is not selected returns 403 eak.delegation.scope_not_allowed in step 1.
  • The user has signed up and signed in to your app through GenAuth, and your server keeps their user ID. The user ID must belong to the user pool bound to this workspace. See User sign-up and sign-in.
  • A UI that can put a request in front of the user, such as a web dialog or a mobile push. Step 2 uses it for every interaction.

Install the SDK and initialize the client on your app server:

bash
npm install @qoniai/qoni@0.10.1
ts
import { Qoni, QoniScopes, type InteractionHandle } from '@qoniai/qoni'

// Initialize on your app server only; never ship the AccessKey to a browser or phone
const qoni = new Qoni({
  accessKey: process.env.QONI_ACCESS_KEY!,
  secretKey: process.env.QONI_SECRET_KEY!,
})

// The user is signed in through GenAuth: read their user ID from the session you saved
const userId = '<genauth-user-id>'

Integration guide ​

1. Delegate scoped access ​

This step obtains a delegation token for the user on your server. Silent delegation needs no consent page: the user is already signed in to your app, and your server issues the token with its AccessKey.

ts
const { data: grant } = await qoni.delegateToken({
  mode: 'silent',
  userId, // the user's GenAuth user ID
  agent: 'shopping-assistant', // audit label recorded with the delegation
  products: ['doAnything'],
  scopes: [
    QoniScopes.SITE_LOGIN_REQUEST, // ask the user to sign in to a site
    QoniScopes.SITE_LOGIN_CONFIRM, // save the user's sign-in
    QoniScopes.BROWSER_USE_TAKE_CONTROL, // ask the user to take over the browser
  ],
  expiresIn: '30m',
})
console.log(grant.grantId, grant.auditId)
  • products: ['doAnything'] expands to webagent.do_anything:read and webagent.do_anything:manage. No products shorthand includes the three sign-in and takeover scopes: request them explicitly in scopes.
  • A successful silent delegation returns grant.token in the response. expiresIn sets its lifetime (60 seconds to 24 hours); when it expires, call again.
  • To record the scopes actually granted in your audit trail, call qoni.genauth.introspectDelegationToken({ token: grant.token }). Do not record what the AccessKey allows as what was granted.
  • When the user must approve each scope on a consent page themselves, use mode: 'interactive'; see Qoni SDK for the callback and exchange.
  • When your platform serves several apps that hold no AccessKey, the platform's server issues a token with the same scopes through qoni.webAgentGrant(), and the app runs step 2 with only that token; see Apps that hold no AccessKey.

Checkpoint:

  • You have grant.token, valid for 30 minutes.
  • Your server recorded grant.grantId and grant.auditId for later audit.

2. Run DoAnything and handle interactions ​

This step hands the user's sentence to Web Agent. DoAnything opens Amazon in a controlled browser, searches, compares prices and checks out; when it needs the user, it pauses and raises an interaction, waiting for your app to submit the user's decision.

Interactions are grouped by what the user has to do, independent of the business:

TypeMeaningSDK methods
site_loginSign-in: the user signs in to a site themselves in the controlled browseropenLogin(), confirmSignedIn()
ask_userAsk the user: one question, with the answer's shape described by answerType and optionsanswer(), skip()
fill_formFill in details: a generic form rendered from fields for information this task needssubmit(), skip()
confirmationConfirmation: allow or deny, nothing elseconfirm(), reject()
take_controlHuman takeover: anything other than sign-in that needs the user's own hands on the browser, such as payingconnectControl(), refreshControl(), releaseControl()

This scenario meets the five interactions in this order:

  1. AgentOpens amazon.com in a controlled browser; checkout needs a signed-in account
  2. site_loginSign-inWaits for the user
    Sign in to Amazon
    The user signs in to the site themselves in the live browser. Neither the Agent nor your app sees the password.
    SDK methodshandle.openLogin()handle.confirmSignedIn()
  3. AgentSearches “MacBook Neo 512GB” and finds it comes in two colors
  4. ask_userAsk the userWaits for the user
    Pick a color
    One question with a structured answer. Here answerType is single_choice and options lists both colors.
    SDK methodshandle.answer()handle.skip()
  5. AgentKeeps the chosen color, compares item + shipping, adds the cheapest to the cart and reaches checkout without a shipping address
  6. fill_formFill in detailsWaits for the user
    Fill in the shipping address
    A generic form rendered from fields; the values are used for this order.
    SDK methodshandle.submit()handle.skip()
  7. AgentFills in the address and prepares the order summary: item, color, seller and total
  8. confirmationConfirmationOrder gate
    Confirm the item and total
    Allow or deny, nothing else. Only after the user allows it does the Agent go on to payment.
    SDK methodshandle.confirm()handle.reject()
  9. AgentOpens the payment step; payment details are entered by the user, never by the Agent
  10. take_controlHuman takeoverWaits for the user
    Pay and place the order
    The Agent hands the browser over; the user enters the payment details and places the order themselves, then hands it back.
    SDK methodshandle.connectControl()handle.releaseControl()
  11. AgentOnce the user hands the browser back, checks that the order went through and returns the order number and total

Start the run with the delegation token:

ts
const run = await qoni.doAnything.run({
  token: grant.token,
  taskScopes: ['webagent.browser_use:take_control'],
  prompt: `
    Open https://www.amazon.com and search for "MacBook Neo 512GB".
    If the same model comes in several colors, ask me which one first.
    Compare only items with exactly the same model, capacity and color, and find the lowest total of item price plus shipping.
    Ask me to sign in to Amazon when needed; ask me for the shipping address if it is missing.
    Before payment, ask me to confirm the item and total; leave the payment step to me.
    Return only JSON: { orderId, title, color, seller, totalPrice, currency, deliveryEstimate }.
  `,
})

taskScopes explicitly requests takeover for this run, and it must already be within the valid grant of grant.token. The SDK always requests webagent.do_anything:manage as well; without taskScopes it requests only manage, and the run cannot ask for human takeover. It accepts only specific webagent.* scopes and never widens an existing token. If a scope is missing, complete authorization and start a new run; refreshing or replaying an old run cannot add it.

To choose a model, pass model; list the values with qoni.doAnything.api.listModels({ token: grant.token }) (items[].value). Without it, the platform default is used.

Then handle interactions by type in run.wait(). The handler's skeleton is the same for any business: five branches for five types, each listing the SDK methods it uses. The comments use this scenario as the example: This scenario says what the payload looks like and how often it appears, and → marks what your app does, such as drawing the UI and waiting for the user. For your own business, keep the skeleton and replace those two kinds of comment.

ts
const handled = new Set<string>() // interaction IDs already handled

async function handleInteraction(handle: InteractionHandle) {
  const request = handle.interaction
  // The same interaction calls back on creation, status updates and event replay: handle pending ones only, deduplicated by ID
  if (request.status !== 'pending' || handled.has(request.id)) return
  handled.add(request.id)

  // Branches in the order this scenario meets them
  switch (request.type) {
    // Sign-in: the user signs in themselves to the sites in request.payload.sites
    // This scenario: once per site that needs sign-in, here only Amazon; once saved, the user's later runs skip it. sites is
    //   [{ siteId: 'amazon', displayName: 'Amazon', loginUrl: 'https://www.amazon.com/ap/signin' }]
    case 'site_login': {
      const login = await handle.openLogin() // opens the controlled login browser and returns the live view at login.liveUrl
      // → open login.liveUrl in your app; the user enters their Amazon account and password, then taps "I'm signed in"
      await handle.confirmSignedIn() // call after the user taps "I'm signed in": saves the sign-in; the Agent rechecks and continues searching
      break
    }

    // Ask the user: request.payload.question is the question; answerType and options describe the answer's shape
    // This scenario: once for every choice the Agent is unsure about. Here it is the color: question is "Which color?",
    //   answerType is 'single_choice', options is
    //   [{ value: 'space-gray', label: 'Space Gray' }, { value: 'silver', label: 'Silver' }]
    case 'ask_user': {
      // → your app draws a single choice by answerType; the user picks Space Gray and you submit that option's value
      await handle.answer('space-gray')
      // await handle.skip() // the user would rather not choose; the Agent continues on its own judgment
      break
    }

    // Fill in details: render a form from request.payload.fields and submit values keyed by field.name
    // This scenario: appears only when checkout has no shipping address. fields is
    //   [{ name: 'shippingAddress', label: 'Shipping address', type: 'address', required: true }]
    // An address value has the keys line1, line2, city, region, postalCode, country
    case 'fill_form': {
      // → your app renders the address inputs from fields and submits what the user enters
      await handle.submit({
        shippingAddress: {
          line1: '500 Howard St', city: 'San Francisco', region: 'CA', postalCode: '94105', country: 'US',
        },
      })
      // await handle.skip() // the user declines: the Agent does not continue checkout
      break
    }

    // Confirmation: request.payload.summary states what the user is asked to allow; the only outcomes are allow or deny
    // This scenario: once before payment; if the price changes after that, the Agent asks again. summary is
    //   "Buy Apple MacBook Neo 512GB in Space Gray on Amazon.com for $1,299.00"
    case 'confirmation': {
      // → your app shows summary with Allow and Deny buttons
      await handle.confirm() // the user allows: the Agent moves on to payment
      // await handle.reject() // the user denies: the Agent does not order and the run ends
      break
    }

    // Human takeover: anything other than sign-in that needs the user's own hands; request.payload.reason says why
    // This scenario: once, for payment. The user enters the payment details and places the order; the Agent never handles them
    case 'take_control': {
      await handle.connectControl() // take over the browser
      // → open request.payload.liveUrl in your app; the user enters payment details and places the order
      // await handle.refreshControl() // refresh when the live view expires
      // Call after the user taps "Done": hands the browser back to the Agent, which checks the order
      await handle.releaseControl()
      break
    }
  }
}

const order = await run.wait({ onInteraction: handleInteraction })
console.log(order.status, order.output) // output.answer is the agent's answer text; the JSON the task asked for is inside it

The same kind of interaction can appear more than once:

  • Every interaction has its own request.id and payload. One type can appear several times in a run: one site_login per site that needs sign-in, one ask_user per uncertain choice, one take_control each time the user's own hands are needed. The color and payment here are just examples; with another product, the Agent might also ask about the configuration or the seller, or ask the user to solve a CAPTCHA while signing in.
  • Interactions come one at a time: the run pauses at an interaction, and only after the user handles it does the Agent continue and the next interaction appear.
  • One interaction also calls back several times: creation, status changes from pending to active and resolved, and event replay after a reconnect all call onInteraction again. That is why the handler starts by handling only pending and remembering each request.id, so it never shows a dialog or submits twice. Your UI should likewise update one card per request.id rather than create a new card on every callback.

A few notes:

  • Passwords and payment details never pass through the Agent: sign-in and payment are done by the user in the live browser; neither the Agent nor your app handles them.
  • Sign-ins are kept per user: a sign-in saved by confirmSignedIn() is reused by the user's later runs, including new conversations; other users in the same workspace cannot see it.
  • A finished run is not a done job: status only means the run ended normally. When the Agent could not get it done (the user did not sign in or hand the browser back, nothing matched, the site kept blocking), isTaskSuccessful is false and output says what was missing. Judge success by isTaskSuccessful, not by status or whether output is empty.
  • Waiting and expiry: interactions need the user and may wait for minutes. Call the matching method only after the user acts; when an interaction expires, the SDK method throws, and the Agent decides whether to retry based on the task.

Show the Agent's work ​

Your app can show the user the Agent's work directly through the SDK:

  • Replies as they are written: every message event of one reply shares data.id, and data.text is the whole text so far. Update one bubble by id; the reply is complete when data.done is true.
  • The Agent's browsers: the browsers event and qoni.doAnything.browsers.list() list the browsers open now; put url in an iframe for an interactive live view. When a sub-agent needs the user to sign in or help, need is set; answer it with browsers.control() once the user is done. For a view the user operates on a phone, add &fit=1 to the address.
  • Conversations and cost: qoni.doAnything.sessions.list() lists the user's conversations, and sessions.credits() says what each run cost. When Credits run out, the run's failureReason is insufficient_credits; check what is left with qoni.workspace.credits() and send the user to qoni.workspace.billingUrl() to top up.
  • The Agent's files: qoni.doAnything.files.* reads and writes the files on a conversation's computer, even while it sleeps.
  • Follow-ups: qoni.proactive.list() shows the follow-ups the Agent scheduled, and your app can schedule one with proactive.create().
  • Keeping watch: qoni.track.create() has the Agent check on a schedule (for a price drop, say), and findings appear in qoni.notifications.list(); delegate products: ['track'] for it.

For the full code, see Qoni SDK: conversations, browsers and files.

Checkpoint ​

When the run ends, confirm that:

  • order.status is succeeded, order.isTaskSuccessful is true, and order.output.answer is the agent's answer text, holding the order JSON the task asked for (the cheapest item in the user's chosen color). Parsed, it looks like:

    json
    {
      "orderId": "112-4839201-5528261",
      "title": "Apple MacBook Neo 512GB",
      "color": "Space Gray",
      "seller": "Amazon.com",
      "totalPrice": 1299,
      "currency": "USD",
      "deliveryEstimate": "2026-10-09"
    }
  • In step 2 the user handled sign-in, a question, a form, a confirmation and the payment takeover in turn; denying any step stops the run at that step.

  • The next order from the same user does not ask them to sign in to Amazon again: the sign-in is kept per user.

  • Your server saved grant.grantId, grant.auditId and order.runId, so the Qoni Console can trace this order back to this grant.

Next steps ​