Partner portal monitoring agent
This page explains how a partner portal monitoring agent signs in to a partner portal under the owner's interactive delegation, uses Track to keep long-lived checks on policy, price list, rebate, and announcement pages, and has your app notify the owner with evidence when something changed. After reading it, you will understand why signed-in monitoring should use interactive delegation, how the login state is reused across checks, and why policy baselines belong in a monitoring store rather than Memory.
Use case
Channel, brand, or marketing teams need to monitor product titles, images, pricing, inventory, promotions, and descriptions in partner portals, along with policy documents, price lists, rebate rules, and announcements that are only visible after sign-in. These pages have no public API, and signing in to each portal manually is slow and misses updates.
Typical triggers:
- A partner portal publishes a new rebate rule or price list, and the channel owner must be notified before it takes effect.
- Before a promotion window opens, product presentation across several portals must be checked against brand rules.
- Before renewing a channel agreement, the team must confirm how portal policy documents changed since the last cycle.
Engineering challenges
- Login-state maintenance: portal content sits behind a login wall, and session expiry, MFA, and risk-control pages are the norm. Unattended monitoring stands or falls on whether the login state can be reused safely and escalates to a human on failure instead of dying silently.
- Change grading: portals have routine updates every day; what actually needs escalation is substantive change — "the rebate rule changed," "the policy start date moved up." Without a versioned policy baseline, grading falls back to a human re-reading everything.
- Portal heterogeneity: every portal differs in page structure, terminology, and update style, so baseline conventions are hard to unify; one structural redesign can turn the whole monitoring chain into noise.
Module composition
| Module | Role | Notes |
|---|---|---|
| GenAuth | Core | Portal login state is high-risk delegation: interactive authorization, short-lived credentials, revocation, and auditing are carried by GenAuth. |
| Web Agent | Core | Sign-ins are saved per user: once the owner signs in to the portal in a DoAnything run, later runs and Track checks for the same user reuse that login state. Track checks on a schedule and reports an outcome, a headline and an answer each time. |
| GUMem | Optional | Only stores owner-confirmed long-term risk preferences (for example, "always escalate rebate changes"). Policy and price baselines are business state — they go to the baseline store, managed by version, not to Memory. |
Permission and delegation boundaries
The Agent holds no inherent permissions. The effective authority for each monitoring task is the intersection of three sets: what the user actually holds ∩ what was explicitly delegated ∩ what the enterprise has approved. Applied to this scenario:
- The delegated scope covers only "read policy, pricing, rebate, announcement, and product display pages on the specified partner portals" — no ordering, price changes, listing edits, or contacting partners.
- Portal sign-in is a high-risk operation and should use
mode: 'interactive': the owner approves in Qoni Console, and the credential is exchanged in a server-side callback — it never reaches the browser. - The owner signs in personally: when the agent reaches a login page it raises a
site_logininteraction, and the owner types their own credentials in the live browser; the password never passes through the agent. - Once created, Track checks on schedule on the server, so your app does not re-issue credentials for every check;
monitor.delete()stops the monitoring.
Note: this sample requests track product permissions. Your application and downstream services must configure and enforce business limits such as portal domains, page ranges, action whitelists. Product scopes and prompt rules do not enforce those detailed limits; this sample does not configure them. See Delegate token and attenuation.
Workflow
The owner selects partners, portals, page scope, and how to be notified.
Your app starts interactive delegation; the owner approves in Qoni Console, and the server-side callback exchanges the credential.
Your app first starts a DoAnything run that opens the portal: when a
site_logininteraction comes up, the owner signs in (including MFA) in the live browser, and the login state is saved for this user.Checkpoint: The owner handles login walls, MFA, or risk-control pages personally — no silent bypass.
Your app creates the track: the page URLs, the scope and the grading rules go into the task description. The first check (
first_look) reads the current policy, price list, rebate, and announcement pages, and your app stores the result with its rule version in the baseline store.Checkpoint: Before going live, confirm that the first check's
answershows content only visible after sign-in. If it shows a login page, the login state did not apply; go back to step 3.Every scheduled check afterwards reuses the owner's login state and reports an
outcome, aheadlineand ananswer; whether something changed follows the rules in the task description.When the
outcomeischanged, your app grades the change against the policy baseline (optionally combined with owner-confirmed risk preferences) and pushes the change, source URLs, suggested actions, and audit id to the owner.Checkpoint: Every anomaly should trace back to a source URL; change judgments without supporting evidence should never reach a notification.
When the
outcomeisneeds_you(usually an expired login), notify the owner to sign in again as in step 3; later checks use the new login state.
Example code
Check the answer
Record success only when the check status is done and the JSON in its answer carries a heading and a source URL. A done check whose answer lacks either makes the sample fail. Check the target page and the task description.
This example uses @qoniai/qoni 0.10.1, published on npm. The download includes the same SDK version, installed with npm ci. The demo checks the public Firefox privacy page for a first check; it does not use real partner accounts. The SDK reads real public pages; business inputs in scenarios.ts are labeled public-demo.
The sample creates a track, waits for the first check to finish, checks its answer and the pause/resume state, then deletes the track. This sample does not cover long-running scheduling, change notifications, or signing in to a private portal. Supply your own JSON with --input; use --interactive when the user must consent to delegation. For site sign-in and user responses, see Qoni SDK.
Download the complete runnable examples, or run from the documentation repository:
cd examples/qoni
npm ci
npm run case -- partner-portal-monitoring-agent
# Supply your own inputs
npm run case -- partner-portal-monitoring-agent --input /path/to/input.jsonSet server-side QONI_ACCESS_KEY and QONI_SECRET_KEY. QONI_USER_ID can identify your application's current GenAuth user; the local demo otherwise selects a user from the bound pool. Demonstration Memory writes use an isolated user rather than changing a business user's preferences.
This scenario's executable entry point:
import { cliOptions } from '../runtime.js'
import { inputFile, runScenario } from '../run-case.js'
// Create a Track monitor and inspect its first extraction.
const report = await runScenario('partner-portal-monitoring-agent', cliOptions(), inputFile())
// report.extracted: monitor and run IDs, headings, and sources; empty extraction fails.
// Validated fields: heading, source_url.
console.log(JSON.stringify(report, null, 2))The entry point loads the definition below by scenario ID. The code is included directly from scenarios.ts, with comments shown in the page language: the task, output fields, source field, Web Search queries (if any), whether Memory is used, and the demonstration input. The pipeline appends the input data, search sources, recalled Memory, and shared safety constraints to the task to build the final prompt; see the pipeline below for the full assembly.
// Create a Track monitor and inspect its first extraction.
{ id:'partner-portal-monitoring-agent', products:['track'], task:'Monitor the supplied pages for substantive policy changes. Extract heading and source_url. This demonstration uses a public policy page; authenticated partner portals require approved login and persistent profiles.', fields:[], input:sample([privacy], { watchedSections:['privacy policy'] }) },The sample implements runScenario(), browser(), research(), and sample() as application functions. The pipeline below makes the actual SDK calls: delegation and introspection → required Memory/search → browser task or monitor → validation and saving. fields and sourceField define the application's output checks. The complete application helpers are in the package's runtime.ts.
Inspect the actual SDK pipeline
// browser() uses DoAnything; research() searches first; sample() labels public-demo inputs.
const firefox = 'https://www.mozilla.org/en-US/firefox/new/'
const manifesto = 'https://www.mozilla.org/en-US/about/manifesto/'
const privacy = 'https://www.mozilla.org/en-US/privacy/firefox/'
const support = 'https://support.mozilla.org/en-US/kb/get-started-firefox-overview-main-features'
// These copy rules become prompt context; server permissions and business checks remain separate.
const policy = {
version: 'demo-2026-09',
approvedClaims: ['Describe only features supported by the cited page.'],
forbiddenClaims: ['guaranteed security', '100% private', 'unverified pricing or performance'],
voice: 'concise and warm',
}
const sample = (pages: string[], business: JsonObject = {}): JsonObject => ({
dataset: 'public-demo', pages, policy, business,
notice: 'Business records are synthetic demonstration inputs. Referenced websites and SDK execution are real.',
})
// fields lists required output keys; sourceField identifies URL checks; memory enables GUMem calls.
const browser = (id: string, task: string, fields: string[], sourceField: string | undefined, input: JsonObject, memory = false): Scenario => ({
id, products: ['doAnything'], task, fields, sourceField, input, memory,
})
const research = (id: string, task: string, fields: string[], sourceField: string, queries: string[], input: JsonObject, memory = false): Scenario => ({
id, products: ['webSearch', 'doAnything'], task, fields, sourceField, queries, input, memory,
})import { QoniScopes, type JsonObject, type RunResult } from '@qoniai/qoni'
import { readFileSync } from 'node:fs'
import { getScenario, type Scenario } from './scenarios.js'
import { appendTrace, checkInputCoverage, cleanupDemoUser, createContext, delegate, handleInteraction, inputEntryCount, isolateDemoUser, object, parseJsonOutput, readWithRetry,
save, saveArtifacts, searchHits, settled, settleRun, validateItems, withCleanup, type Context, type Options } from './runtime.js'
export async function runScenario(id: string, options: Options = {}, input?: JsonObject) {
// Load the task definition by ID; --input replaces its business inputs.
const scenario = getScenario(id)
const data = input ?? scenario.input
if (scenario.memory && data.dataset !== 'public-demo' && options.mode !== 'interactive' && !options.userId && !process.env.QONI_USER_ID) {
throw new Error('Business Memory writes require the current QONI_USER_ID; do not select an arbitrary bound user')
}
const context = await createContext(id, { ...options,
skipUserResolution: scenario.memory && data.dataset === 'public-demo' })
return withCleanup(context, async register => {
register('isolated demonstration user', () => cleanupDemoUser(context))
// Isolate demo preferences; business Memory belongs to the identified current user.
if (scenario.memory && data.dataset === 'public-demo') await isolateDemoUser(context)
return await executeScenario(context, scenario, data)
})
}
export async function executeScenario(context: Context, scenario: Scenario, input: JsonObject) {
const pages = input.pages
if (!Array.isArray(pages) || !pages.length || pages.some(page => typeof page !== 'string' || !/^https:\/\//.test(page))) {
throw new Error('Input pages must be an array of HTTPS URLs')
}
if (input.requiresLogin === true && context.mode !== 'interactive') {
throw new Error('Targets that require sign-in need --interactive and user-controlled login')
}
const memoryScopes = scenario.memory
? [QoniScopes.GUMEM_MEMORY_READ, QoniScopes.GUMEM_MEMORY_WRITE, QoniScopes.GUMEM_MESSAGE_WRITE] : []
// delegate() is an application helper around the SDK delegation methods.
const grant = await delegate(context, scenario.id, scenario.products, memoryScopes)
// Read the effective scopes; readWithRetry() retries only retryable read failures.
const { data: tokenInfo } = await readWithRetry(context, 'delegation introspection',
() => context.qoni.genauth.introspectDelegationToken({ token: grant.token }))
const info = object(tokenInfo)
if (info.active !== true) throw new Error('The delegation token is not active')
const audit = { grantId: grant.grantId, auditId: grant.auditId, scopes: info.scope }
let memory: unknown
if (scenario.memory) {
// A Session associates this conversation with the user; the app chooses sessionId.
const sessionId = `${scenario.id}-${Date.now()}`
await context.qoni.gumem.createSession({
token: grant.token, userId: context.userId, sessionId, title: scenario.id,
})
const preferences = object(input.business ?? {}).confirmedPreferences
if (Array.isArray(preferences) && preferences.length) {
// Store confirmed preferences only; sync: true requests synchronous processing.
await context.qoni.gumem.addMessages({ token: grant.token, userId: context.userId, sessionId, sync: true,
messages: [{ role: 'user', content: `Confirmed demonstration preferences: ${preferences.join('; ')}` }] })
}
// Recall relevant preferences for the later task prompt.
memory = (await readWithRetry(context, 'GUMem recall', () => context.qoni.gumem.recall({ token: grant.token, sessionId,
query: 'Confirmed preferences relevant to this task', details: true }))).data
save(context, 'memory.json', { sessionId, context: memory })
if (Array.isArray(preferences) && preferences.length && !preferences.every(value => JSON.stringify(memory).includes(String(value)))) {
throw new Error('Recall did not include the confirmed preferences just written by this demo')
}
}
if (scenario.products.includes('track')) return runMonitor(context, scenario, input, grant.token, audit)
let hits: ReturnType<typeof searchHits> = []
if (scenario.queries) {
// Web Search returns results[]; DoAnything receives these sources to inspect.
const search = await context.qoni.webSearch.run({ token: grant.token, prompt: scenario.queries, maxResultsPerQuery: 3 })
save(context, 'search-ref.json', { runId: search.id, audit })
await withCleanup(context, async register => {
register('Web Search run', () => search.cancel('Documentation demonstration cleanup'))
const result = await settleRun(context, search)
save(context, 'search-result.json', result)
settled(result)
hits = searchHits(result.output)
})
}
// One-per-entry scenarios request exactly one item per input entry; others at most two.
const requiredItems = inputEntryCount(scenario.id, input)
// Assemble the task, inputs, search sources, and Memory as application-defined context.
const prompt = [scenario.task, `Task inputs: ${JSON.stringify(input)}`,
`Search sources: ${JSON.stringify(hits)}`, `Confirmed memory: ${JSON.stringify(memory ?? null)}`,
`Actual collection time: ${new Date().toISOString()}`,
requiredItems === undefined
? 'Inspect the supplied sources. Return at most two items in the requested JSON array, without prose or Markdown.'
: `Inspect the supplied sources. Return exactly ${requiredItems} item${requiredItems === 1 ? '' : 's'} in the requested JSON array, one per input entry, without prose or Markdown.`,
'Keep synthetic demonstration data identified as synthetic. Do not send messages, publish, pay, edit accounts or submit forms.',
input.requiresLogin === true ? 'Request user sign-in through an interaction when required; never enter credentials yourself.' : 'Public demonstration sources only; do not sign in.',
].join('\n\n')
// Start the Agent with this grant.
const run = await context.qoni.doAnything.run({ token: grant.token, prompt })
save(context, 'run-ref.json', { runId: run.id, session: run.sessionRef, audit })
let result: RunResult
const trace = (event: { type: string; data: unknown }) => {
context.eventCounts[event.type] = (context.eventCounts[event.type] ?? 0) + 1
if (['progress','message','done'].includes(event.type)) appendTrace(context, event)
if (event.type === 'browserLiveUrlChanged') {
const liveUrl = object(event.data).liveUrl
if (typeof liveUrl === 'string') context.browserUrl = liveUrl
}
}
return withCleanup(context, async register => {
register('DoAnything run', () => run.cancel('Documentation demonstration cleanup'))
if (context.delivery === 'events') {
// --events streams updates; wrap interaction data in an SDK handle for user handling.
for await (const event of run.events({ signal: AbortSignal.any([context.abort.signal, AbortSignal.timeout(context.timeoutMs)]) })) {
trace(event)
if (event.type === 'interaction') await handleInteraction(context, run.interactionHandle(event.data))
}
result = await settleRun(context, run)
} else {
// Callback mode receives this run's events inside wait; helpers ask the user.
result = await settleRun(context, run, { onEvent: trace,
onInteraction: interaction => handleInteraction(context, interaction) })
}
save(context, 'result.json', result)
settled(result)
await saveArtifacts(context, result)
if (scenario.id === 'landing-page-audit-agent' && context.screenshots === 0) throw new Error('The landing-page audit did not deliver the requested screenshot')
// The app checks required fields and source URL formats; a reviewer still checks facts.
const items = validateItems(result.output, scenario.fields, scenario.sourceField)
// Scenarios that require one item per input entry are checked against the input.
checkInputCoverage(scenario.id, items, input)
const report = { scenario: scenario.id, dataset: input.dataset, passed: true, runId: run.id,
status: result.status, items, audit, screenshots: context.screenshots, interactions: context.interactions,
events: context.eventCounts, artifactIds: result.artifacts.map(artifact => artifact.id) }
save(context, 'report.json', report)
return report
})
}
async function runMonitor(context: Context, scenario: Scenario, input: JsonObject, token: string, audit: JsonObject) {
// A track is created from one task description: the pages go in the prompt, checked hourly; creation starts the first check (first_look).
const pages = input.pages as string[]
const monitor = await context.qoni.track.create({ token, title: scenario.id,
prompt: `${scenario.task}\nPages: ${pages.join(' ')}\nAnswer with one JSON object {"heading": string, "source_url": string} for the page you read.`,
schedule: { kind: 'interval', intervalSeconds: 3600 } })
save(context, 'monitor-ref.json', { id: monitor.id, audit })
return withCleanup(context, async register => {
register('Track monitor', () => monitor.delete())
const definition = await monitor.get()
save(context, 'monitor-definition.json', definition)
if (object(definition.schedule).intervalSeconds !== 3600) throw new Error('Track did not persist the requested schedule interval')
// Wait for the first check by the lastTaskId recorded at creation; no runNow while it runs (that returns 409 task_in_progress).
const runId = definition.lastTaskId
if (typeof runId !== 'string' || !runId) throw new Error('Track did not start its first check')
const check = await waitForCheck(() => monitor.run(runId))
save(context, 'check.json', check)
if (check.status !== 'done') throw new Error(`Track check ended as ${String(check.status)}: ${String(check.failure ?? '')}`)
const extracted = object(parseJsonOutput(check.answer))
if (typeof extracted.heading !== 'string' || !extracted.heading.trim() ||
typeof extracted.source_url !== 'string' || !/^https:\/\//.test(extracted.source_url)) {
throw new Error('The Track check is missing a heading or source URL')
}
const normalizeUrl = (value: string) => { const url = new URL(value); url.hash = ''; return url.href.replace(/\/$/, '') }
if (!pages.some(url => normalizeUrl(url) === normalizeUrl(String(extracted.source_url)))) {
throw new Error('The Track source URL is not a configured target')
}
// Check persisted pause/resume state; withCleanup() deletes the monitor on exit.
await monitor.pause()
if ((await monitor.get()).status !== 'paused') throw new Error('Track did not persist the paused state')
await monitor.resume()
if ((await monitor.get()).status !== 'active') throw new Error('Track did not persist the active state')
const report = { scenario: scenario.id, dataset: input.dataset, passed: true, monitorId: monitor.id,
runId, status: check.status, outcome: check.outcome, extracted, audit }
save(context, 'report.json', report)
return report
})
}
// Read the check every 3 seconds until done / failed / expired / canceled, for up to 5 minutes.
async function waitForCheck(read: () => Promise<JsonObject>): Promise<JsonObject> {
const deadline = Date.now() + 300_000
for (;;) {
const check = await read()
if (['done', 'failed', 'expired', 'canceled'].includes(String(check.status))) return check
if (Date.now() > deadline) throw new Error(`Track check did not finish within 5 minutes (status ${String(check.status)})`)
await new Promise(resolve => setTimeout(resolve, 3000))
}
}
export function inputFile(): JsonObject | undefined {
const index = process.argv.indexOf('--input')
return index >= 0 ? object(JSON.parse(readFileSync(process.argv[index + 1], 'utf8'))) : undefined
}After a successful first check, output/partner-portal-monitoring-agent/report.json contains the track ID, the first check's run ID, the check result and the effective scopes. http.json records redacted request statuses. A done check whose answer lacks the heading or source fails validation; check the target page and the task description before retrying, and never treat an empty answer as a pass.
Data and memory boundaries
This scenario touches four kinds of data; only the last optionally belongs in GUMem:
- Versioned rules: policy baselines, monitored-page lists, grading and escalation rules — managed by version in the baseline store, with every notification referencing the baseline version.
- Business state: page baselines, change records and source URLs — carried by your monitoring store, replayable; Track keeps only the most recent 50 checks.
- Audit records: the behavior chain of interactive authorization — maintained by GenAuth.
- User Memory (optional): owner-confirmed long-term risk preferences (for example, "always escalate rebate changes") — this is where GUMem fits; policy and price baselines never enter Memory.
Failure handling
| Situation | Recommended handling |
|---|---|
| Login state expires | The check's outcome is needs_you; once the owner signs in again in a DoAnything run (site_login), later checks continue. |
| A portal redesign | Send that changed to a human and rebuild the baseline after confirmation; never emit change conclusions without evidence. |
| Three checks in a row produce no report | Track pauses itself; read back the status and failure, fix it, then resume(). |
| A check answer lacks a source | App-side validation drops the entry and records how many were dropped; no evidence, no notification. |
Production notes
The Agent should not place orders, change prices, edit listings, or contact partners. Treat the output as a review report; the owner decides follow-up actions. Monitoring is read-only and notify-only — it never performs changes on a human's behalf. Set the schedule interval from how often the portal actually updates, never below 600 seconds, to avoid load on target sites. When monitoring is no longer needed, monitor.delete() stops later checks.
Next steps
- Read Track for the track's full lifecycle, check records and live events.
- Read the Quickstart to run the shortest path for Agent identity and delegation.
- Continue with the Vendor monitor agent for the adjacent public-page monitoring scenario.