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.
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:
| What | Why | Step |
|---|---|---|
| The user's session | Establishes who is ordering; the token acts for this person only | Before you start |
| A delegation token | Limits what the Agent may do and for how long | 1 |
| A run that works with the user | Opens pages, compares prices and checks out; asks the user to sign in, answer, fill in details, confirm or pay in person when needed | 2 |
How it fits together
The diagram shows the overall logic: the top half is authorization, and the bottom half runs for every order.
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_allowedin 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:
npm install @qoniai/qoni@0.10.1import { 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.
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 towebagent.do_anything:readandwebagent.do_anything:manage. Noproductsshorthand includes the three sign-in and takeover scopes: request them explicitly inscopes.- A successful silent delegation returns
grant.tokenin the response.expiresInsets 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.grantIdandgrant.auditIdfor 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:
| Type | Meaning | SDK methods |
|---|---|---|
site_login | Sign-in: the user signs in to a site themselves in the controlled browser | openLogin(), confirmSignedIn() |
ask_user | Ask the user: one question, with the answer's shape described by answerType and options | answer(), skip() |
fill_form | Fill in details: a generic form rendered from fields for information this task needs | submit(), skip() |
confirmation | Confirmation: allow or deny, nothing else | confirm(), reject() |
take_control | Human takeover: anything other than sign-in that needs the user's own hands on the browser, such as paying | connectControl(), refreshControl(), releaseControl() |
This scenario meets the five interactions in this order:
- AgentOpens amazon.com in a controlled browser; checkout needs a signed-in account
- Sign in to AmazonThe 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()
- AgentSearches “MacBook Neo 512GB” and finds it comes in two colors
- Pick a colorOne question with a structured answer. Here answerType is single_choice and options lists both colors.SDK methodshandle.answer()handle.skip()
- AgentKeeps the chosen color, compares item + shipping, adds the cheapest to the cart and reaches checkout without a shipping address
- Fill in the shipping addressA generic form rendered from fields; the values are used for this order.SDK methodshandle.submit()handle.skip()
- AgentFills in the address and prepares the order summary: item, color, seller and total
- Confirm the item and totalAllow or deny, nothing else. Only after the user allows it does the Agent go on to payment.SDK methodshandle.confirm()handle.reject()
- AgentOpens the payment step; payment details are entered by the user, never by the Agent
- Pay and place the orderThe 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()
- 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:
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.
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 itThe same kind of interaction can appear more than once:
- Every interaction has its own
request.idandpayload. One type can appear several times in a run: onesite_loginper site that needs sign-in, oneask_userper uncertain choice, onetake_controleach 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
pendingtoactiveandresolved, and event replay after a reconnect all callonInteractionagain. That is why the handler starts by handling onlypendingand remembering eachrequest.id, so it never shows a dialog or submits twice. Your UI should likewise update one card perrequest.idrather 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:
statusonly 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),isTaskSuccessfulisfalseandoutputsays what was missing. Judge success byisTaskSuccessful, not bystatusor whetheroutputis 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
messageevent of one reply sharesdata.id, anddata.textis the whole text so far. Update one bubble byid; the reply is complete whendata.doneistrue. - The Agent's browsers: the
browsersevent andqoni.doAnything.browsers.list()list the browsers open now; puturlin an iframe for an interactive live view. When a sub-agent needs the user to sign in or help,needis set; answer it withbrowsers.control()once the user is done. For a view the user operates on a phone, add&fit=1to the address. - Conversations and cost:
qoni.doAnything.sessions.list()lists the user's conversations, andsessions.credits()says what each run cost. When Credits run out, the run'sfailureReasonisinsufficient_credits; check what is left withqoni.workspace.credits()and send the user toqoni.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 withproactive.create(). - Keeping watch:
qoni.track.create()has the Agent check on a schedule (for a price drop, say), and findings appear inqoni.notifications.list(); delegateproducts: ['track']for it.
For the full code, see Qoni SDK: conversations, browsers and files.
Checkpoint
When the run ends, confirm that:
order.statusissucceeded,order.isTaskSuccessfulistrue, andorder.output.answeris 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.auditIdandorder.runId, so the Qoni Console can trace this order back to this grant.
Next steps
- Read Enterprise Agent to see the same interaction types let an Agent work with an employee's own accounts.
- Read User sign-up and sign-in to see how users sign up and sign in to your app through GenAuth's hosted page.
- Read Apps that hold no AccessKey to see how a platform issues one person's token to its own apps.
- Read Delegate token attenuation for how delegated access is designed.