Skip to content
askdareDocumentation

    ADR-0039: Prompt versions and A/B tests in defineBot

    • Status: Accepted on 2026-11-30 by the maintainer, with every open question settled as recommended ("Settled with the maintainer"). Built in 0.8 by v1 to v4; each task's "As built" section below amends it where the code differs.
    • Date: 2026-11-29
    • Extends: ADR-0012 (onUsage and the other reports gain a version) and ADR-0032 (the admin records, daily rows and the dashboard gain one, with a Postgres migration and new Upstash keys). Both stay accepted.
    • Lines up with: ADR-0035 (askdare eval), Proposed at the same time. What this ADR needs from eval is under "How this fits askdare eval".

    Context

    A team that changes a bot's instructions today can't tell what the change did. The reports and the admin store say which bot and model answered, not which instructions, so a rewrite shows up only as a shift in the dashboard's daily lines, mixed with whatever else changed that week. Comparing two wordings on live traffic means two bots with two IDs and two embed snippets, and the site splitting visitors itself.

    Three things are needed:

    • Names: a bot carries more than one version of its instructions, each with a name that reports, records and askdare eval (ADR-0035) share.
    • A split: the owner sends a share of new conversations to each version, and a conversation keeps its version for its whole life, so no visitor sees the bot change its manner halfway through.
    • Results: onUsage, the admin store and the dashboard say which version answered, so cost, ratings, unanswered questions and handoffs can be compared per version.

    The constraints come from earlier decisions:

    • The client never chooses instructions (ADR-0004). A visitor can't pick a version, not even for testing.
    • No cookies and no raw IDs. The stable thing askdare knows about a visitor is the pseudonym onUsage reports: an HMAC of the visitor ID, or of the user ID when someone is signed in (ADR-0009, ADR-0012).
    • Conversations live in a store the app chooses (ADR-0024), OpenAI's by default, whose metadata we don't own. Adding a field to every store is a port change for Postgres, memory and OpenAI alike.
    • Admin queries are fixed and answered from counters kept at write time, so Upstash can serve them (ADR-0032, decision 2). Every new dimension is a schema change and new keys.
    • No model IDs in the library, and ADR-0036 (model settings) changes defineBot's model options in the same release. bot/define-bot.ts is a hot file: model settings, then prompt versions, then tool presets.

    Decision

    1. A version is a named set of instructions; nothing else in 0.8

    export const support = defineBot({
      id: 'support',
      model: 'gpt-…',
      instructions: supportV1,          // the bot's own version
      version: 'v1',                    // optional name for it; default 'default'
      versions: {
        shorter: { instructions: supportShorter },  // string or (context) => string, as `instructions`
      },
      experiment: { name: 'shorter-answers', split: { v1: 80, shorter: 20 } },
    });
    • versions maps a name to { instructions }, with the same type as the top-level instructions: a string or a function of BotContext. A version replaces the instructions only. The model, tools, knowledge, limits, forms, handoff and widget are the bot's and are the same for every version.
    • version names the bot's own instructions, 'default' when absent. It's useful without any experiment: bump it when you edit the instructions, and the dashboard shows when the new text took over and how it compares with the weeks before.
    • Names match ^[a-z][a-z0-9-]{0,31}$. They start with a letter, so JavaScript keeps the object's order (integer-like keys would be sorted first), and they are safe in a CLI flag, a Postgres column and an Upstash key. A name is unique within the bot: version and the keys of versions must all differ. At most 10 versions per bot.
    • A version without traffic is still useful. With no experiment, or a share of 0, it answers nobody, but askdare eval --version shorter and the console's playground can run it. The intended flow is to draft a version, run eval on it, give it 10 % of new conversations, then promote it.
    • A name stands for its text. askdare can't tell when a version's text changed under the same name (a function's output can't be fingerprinted), so the docs give one rule: change the text, change the name. Promoting a version means moving its text to instructions and its name to version.
    • Validation is in defineBot's schema, so a bad split fails at startup, not mid-conversation: names, uniqueness, the split's keys naming existing versions, and integer shares from 0 to 100 that add up to 100.

    Scope is open question 1: the shape is an object so that model (with ADR-0036's settings) can be added later without a breaking change.

    2. Assignment: by visitor, sealed into the conversation

    • When: once, when a turn creates a conversation. Every later turn uses the version that conversation got.
    • Which: without an experiment, the bot's own version. With one, a bucket from 0 to 99: the first four bytes of SHA-256 over bot, experiment.name and the visitor's pseudonym (the value onUsage reports), as an unsigned integer modulo 100. The split's shares become ranges in the split's order (v1 0–79, shorter 80–99), and the bucket falls in one of them.
    • By visitor, not by conversation: the same visitor lands in the same version in each new conversation, and a signed-in user does on every device, since their pseudonym is the HMAC of their user ID. A visitor who clears the widget's storage gets a new visitor ID and may land elsewhere. That is accepted: every version is one the owner wrote.
    • Sealed: the version's name goes into the conversation's resume grant (ADR-0004's encrypted tokens, in security/tokens.ts), and into the grants minted inside the conversation: the feedback and form grants. A handoff request names its conversation through the resume grant, so it has the version too. The server reads it from there on each request. The client holds an opaque token, so it can't pick a version and can't see which one it got. The protocol doesn't change: the tokens' contents are internal. Re-issuing the handle when a visitor signs in (ADR-0009, "adopts it") carries the version over.
    • No conversation store change. The version isn't written to the ConversationStore. A handle sealed before 0.8 has none and reads as the bot's own version.

    When versions change mid-experiment:

    ChangeNew conversationsExisting conversations
    Shares changeFollow the new shares. With ranges in a fixed order, only the visitors whose bucket crosses a moved boundary change version.Keep their version.
    Experiment renamedEveryone is re-bucketed: it is a new experiment.Keep their version.
    experiment removedThe bot's own version. This is the off switch, and it takes a deploy.Keep their version, while it still exists.
    A version removed from versionsNot assigned.Continue on the bot's own version, and report that name: records say what answered. The server warns once per name and process, naming the version (not personal data).
    A version's text edited under the same nameNot detectable.The docs rule in decision 1 applies.

    3. Recording: a version everywhere a turn is reported

    Every record carries the version that answered, always, 'default' included, so filters and groupings never need a "no version" case.

    Reports (ADR-0012, ADR-0016, ADR-0030, ADR-0031):

    • ChatUsageReport.version: string;
    • ChatTranscriptReport.version;
    • ChatFeedbackReport.version, from the feedback grant, so a rating counts for the version that wrote the answer;
    • ChatHandoffReport.version and ChatLeadReport.version, from their grants.

    The admin store (ADR-0032, decision 2):

    • Records core writes: AdminTurnRecord, AdminRatingRecord and AdminTranscriptRecord get version: string, and so does AdminCountEvent (handoffs and leads), so handoffs per version need no conversation in the counter. Core always sets it.
    • Rows a store returns: AdminDayRow is keyed by day, bot, version and model, and AdminBotDayRow by day, bot and version. AdminConversationSummary gets the version of the conversation's first turn. On returned rows version is optional, and a missing one reads as 'default', so a store written against 0.7 still type-checks and its old rows still show.
    • Queries: AdminRange.version?: string filters days, conversations and ratings. A version filter needs a bot, since names are per bot. adminStoreContract checks the grouping, the filter and that a record without a version reads as 'default'.

    Postgres (@boldare/askdare-postgres): a second migration of the admin part, since released migrations are never edited. It adds version text collate "C" not null default 'default' to the turns, ratings, transcripts and conversations tables and to both day tables, whose primary keys become (day, bot, version, model, source) and (day, bot, version, source). Existing rows become 'default', which is what answered them. The conversation list gets an index for (bot, version, first_at).

    Upstash (@boldare/askdare-upstash):

    • Daily rows: a daily-row field's JSON key gains the version as a last element ([kind, source, bot, model, version]). Fields written before 0.8 have no last element and read as 'default', so no backfill.
    • Lists: the conversation and rating indexes gain a per-version variant next to the per-bot one: <p>i:<src>:<n>:<t|l|d>:<bk>:<vk> and <p>q:<src>:<n>:<all|up|down>:<bk>:<vk>, with <vk> the version name. That is one more sorted-set write per index family per record. The lists filter by version from 0.8 on: conversations recorded earlier show up only without the filter. That is ADR-0032's "from this version on" note.
    • No key name holds anything but the owner's own labels, as before.

    memoryAdminStore() follows the same rules.

    4. Results: a comparison table, with no statistics engine

    The dashboard (@boldare/askdare-admin) gets:

    • A version filter next to the bot filter, on every view: cost, ratings, conversations and the lists.

    • A "Versions" table for one bot and the chosen range, one row per version, from days:

      • new conversations (the n);
      • turns and failed turns;
      • cost, and cost per conversation (priced by the app's prices, as now);
      • 👍 and 👎, with the share of 👎 among rated answers;
      • the share of turns counted as unanswered (ADR-0032's heuristic);
      • the handoff rate: handoffs in a final state other than limited, over new conversations;
      • leads per 100 conversations;
      • the first day in the range that version answered.

      Only source: 'chat': playground turns are left out.

    What it deliberately doesn't do in 0.8: p-values, confidence intervals, "winner" badges, stopping rules or automatic promotion. Ratings are sparse and come from visitors who chose to rate, the unanswered count is a heuristic, and handoff rates are daily ratios (ADR-0032, decision 5). A statistics engine on top of those numbers would look more certain than they are.

    How a team reads significance is in the docs, not the dashboard:

    • Every rate sits next to its n.
    • Compare over a range that starts after the split last changed. The "first day" column shows when a version started answering.
    • Wait for a few hundred conversations per version before reading anything into a difference.
    • Run a quick two-proportion check: a difference between rates p₁ and p₂ is worth acting on when it is larger than 2·√(p₁(1−p₁)/n₁ + p₂(1−p₂)/n₂). The docs show it worked through on one example. Teams that need more export the table.
    • Before promoting a version, run askdare eval on both versions, so a cheaper or better-rated version doesn't also cite worse.

    5. Eval, the console and doctor

    • askdare eval --version <name> runs the same cases against that version, chosen by the names of decision 1, with no assignment. It is a flag of the eval command. askdare --version as the first argument still prints the CLI's version (cli/index.ts). The rest of eval is ADR-0035's. How the flag reaches the server is under "How this fits askdare eval".
    • The console shows each version's instructions and the split in the configuration view: server/explain.ts resolves every version, and the allowlist gains version, versions and experiment. The playground gets a version picker. That is the owner choosing, behind the console's sign-in (ADR-0032, decision 8), and playground turns are recorded with source: 'console' and that version. The review shows a conversation's version.
    • doctor lists each bot's versions and split, and resolves every version's instructions with a sample context, so a function that throws for one version fails there and not on a visitor's first message.

    6. Public surface

    Added to ADR-0006 when the implementation lands, in a minor release with a changeset, with names final there:

    • @boldare/askdare:
      • version, versions and experiment in defineBot, with their types;
      • version on the admin record and row types;
      • AdminRange.version.
    • @boldare/askdare/next: version on ChatUsageReport, ChatTranscriptReport, ChatFeedbackReport, ChatHandoffReport and ChatLeadReport.
    • The add-ons: the Postgres migration (run by the existing migrate), Upstash's keys, and the dashboard's filter and table.
    • The CLI: --version on askdare eval (ADR-0035).

    The OpenTelemetry add-on doesn't change in 0.8. The GenAI conventions have no attribute for this, and an askdare.* attribute can come when someone asks for it.

    How this fits askdare eval (ADR-0035)

    ADR-0035 was Proposed on 2026-11-29. It runs eval through the running app: the CLI sends one run of one case to POST <basePath>/eval, authenticated with an eval token minted from CHAT_SECRET, and compares results with a baseline file. Its decision 7 leaves "A/B of prompts" out of 0.8 and says a later change can run the same cases against two versions. --version is that change, and this ADR puts it in 0.8, built by the prompt versions task after eval's own tasks:

    1. The CLI's --version <name> (repeatable, or all) adds an optional version to each eval request. The server checks the name against the bot's versions, using the names of decision 1, and answers invalid_input listing them for an unknown name. The CLI then stops before any further case. The version is chosen by the holder of the eval token, never by a visitor, so ADR-0004's rule holds. Without the flag, eval runs the bot's own version, the one that answers when there is no experiment.
    2. Eval turns skip assignment and, as ADR-0035 decides, write no admin store records. onUsage gets source: 'eval' (ADR-0035) and the version of decision 3.
    3. Results and baselines are keyed by bot, version and case, and the reports name the version. A baseline recorded for v1 isn't compared with a run of shorter. Several versions in one run are reported side by side.
    4. The console's Tests view (ADR-0035, decision 6) takes the playground's version picker (decision 5).

    This adds version to ADR-0035's eval request, report and baseline formats (version 1). It is additive if it lands before those formats ship, as the ROADMAP orders. If it lands after, it is an optional field.

    Settled with the maintainer (2026-11-30)

    The open questions of the first draft, all settled as recommended:

    1. Scope: a version replaces the instructions only in 0.8. A version's own model, with ADR-0036's settings, can come in 0.9 after ADR-0036 is built, and the object shape keeps that additive. Tools stay out, since they change what the client renders.
    2. Naming the bot's own version: the optional version, default 'default', on every report and record.
    3. Where a conversation's version lives: in the sealed grants, not in the ConversationStore. Turn records and summaries carry it for the dashboard.
    4. Bucketing: by visitor pseudonym and experiment name, not a fresh draw per conversation.
    5. A removed version's live conversations continue on the bot's own version and are reported as such.
    6. No experiment name on records. The docs ask for version names unique within a bot over time, and the "first day" column stands in for the experiment's start.
    7. No confidence intervals in the 0.8 dashboard. Revisit with per-conversation metrics (ROADMAP, Later).
    8. No way for the page to force a version. QA uses the console's playground and askdare eval --version.

    Consequences

    • A team can compare wordings on real traffic, in one bot, with no second embed snippet, and see per version what each costs, how it is rated, how often it misses and how often it hands off.
    • The same names work offline and online: eval before a split, the dashboard during it.
    • Every report and record grows by one short string, and two report types that sites already consume change additively.
    • The admin schema changes: Postgres sites run migrate once. Upstash needs no migration, but list filters by version start at the upgrade.
    • The daily tables grow by the number of versions per bot, at most 10, and in practice two or three during an experiment.
    • No protocol change: the version rides inside tokens the client already treats as opaque.
    • The experiment is code, so changing a split or stopping it takes a deploy. That is accepted for 0.8: the dashboard reads over days, not minutes.
    • The dashboard shows numbers, not verdicts. Teams that act on a small difference can be wrong. The docs say how to check, and the table shows every n.
    • bot/define-bot.ts changes after ADR-0036's model settings, as the ROADMAP orders, and the implementation task is written once this ADR is accepted.

    Alternatives considered

    • Two bots with two IDs, split by the site. It works today, but the site has to split visitors itself, and each bot has its own limits and budgets. The dashboard would compare two bots that differ in more than wording.
    • Assignment in the browser (the loader draws a version and sends it). The client would choose instructions, against ADR-0004.
    • A version passed by the site's backend in the identity JWT (ADR-0009). Anonymous visitors would be left out, and splitting would become the site's job again.
    • Recomputing the bucket on every turn, with nothing sealed. A share change, or the visitor signing in (which changes the pseudonym), would move a conversation to another version mid-way.
    • One instructions function that branches on a context.version. It is fewer options, but there would be two ways to define a version. The console and doctor couldn't list versions without calling the function, and a version's model (open question 1) would have nowhere to go.
    • A content fingerprint as the version (a hash of the resolved instructions). It is automatic for strings, impossible for functions, and gives names no one can type into askdare eval --version.
    • A statistics engine in the dashboard (significance, sequential testing, automatic promotion). Over sparse, self-selected ratings and daily ratios it would look more certain than the data is. It is out of scope for a library dashboard in 0.8.
    • Feature-flag services (LaunchDarkly, GrowthBook and others) as the source of the split. An instructions function can't consult one today: it is synchronous and sees only the locale and identity. Even if it could, the version wouldn't reach the reports or the admin store. A later experiment.assign hook could take an external assignment and keep the recording of decision 3.

    As built in 0.8-v1

    Amended on 2026-11-30 (task v1, core), where the code differs from or adds to the decision above:

    • Decision 1, experiment names: experiment.name follows the rule of version names (^[a-z][a-z0-9-]{0,31}$). version and experiment are their own, documented options; the public types are BotVersion ({ instructions }) and BotExperiment ({ name, split }). A version or an experiment with an unknown key is refused, so a version's model fails at startup until it exists. A share of 0 is allowed and never assigned.
    • Decision 2, the bucket: SHA-256 over the UTF-8 of <bot>\n<experiment name>\n<pseudonym>; none of the three can hold a newline. The handler assigns the version before the turn starts, by the same pseudonym onUsage reports, and the turn's input estimate for the budget uses that version's instructions.
    • Decision 2, the grants: the claim is ver in the resume, feedback and form grants; a claim that isn't a version name is refused like any forged handle (not_found). The handler takes the version from the form grant on a submission, else from the resume grant, else the bot's own; re-issuing the handle at sign-in carries it with the rest of the grant. A removed version warns once per bot and name and process (instructionsFor, bot/versions.ts).
    • Decision 3, the types: version is required on the records only core writes and no store returns, AdminTurnRecord and AdminCountEvent. On AdminRatingRecord and AdminTranscriptRecord, which ratings() and transcript() also return, it is optional like on the rows, so a store written against 0.7 still type-checks; core always sets it. AdminRange.version without a bot is invalid_input from checkRange (admin/bounds.ts), also for a console session scoped to several bots.
    • Decision 3, the contract: adminStoreContract writes version: 'default' and compares rows without their version, so the Postgres and Upstash stores pass it unchanged. Its version checks (grouping, the filter, a record without a version) come with those stores in 0.8-v2; memoryAdminStore() has them in its own tests now.
    • Decision 5, the console: the allowlist is consoleBotView in server/admin-console.ts, not server/explain.ts: it adds version, versions (every version, the bot's own first, as { name, share, instructions }, share null without an experiment) and experiment (its name or null). The playground's version is checked against the bot's versions (invalid_input naming them) and sealed into the console's conversation reference, so a playground conversation keeps its version as a visitor's does; the picker starts a new conversation. The review shows a conversation's version from its list entry or its first transcript record.
    • Decision 5, doctor: the checks run in the app (server/version-checks.ts), where the instructions functions are, and reach the CLI as bot checks: a line listing the versions and shares for a bot with named versions or an experiment, and a failure for any version whose instructions throw (named by the error's class only) or are empty, for an anonymous visitor in the bot's language. A bot with one unnamed version gets a line only when its instructions fail.
    • Eval: eval turns run the bot's own version until --version (0.8-v4), and report it.
    • Not yet (when v1 merged; each is done in 0.8, below): Postgres and Upstash (0.8-v2), the dashboard's filter and Versions table (0.8-v3), askdare eval --version and the Tests view's picker (0.8-v4), and the names in ADR-0006 (0.8-z1).

    As built in 0.8-v2

    Amended on 2026-11-30 (task v2, the Postgres and Upstash admin stores), where the code adds to decision 3:

    • The contract: adminStoreContract checks the daily rows kept apart per version (and a replaced rating moving off its version's row), the version filter of days, conversations and ratings, its refusal without a bot, a conversation having its first turn's version, and records written without a version reading as default. It reads a row or record without version as default, so a store may leave it out.
    • Both stores write a record without a version as default, as core's memory store does. A conversation's version is its first turn's, else its first record's.
    • Postgres: migration 2 of the admin part, as decided. The daily tables' keys are rebuilt and the summaries' index built in the migration's transaction, blocking admin writes for a moment; askdare writes them after the response, so no answer waits. Once it has run, 0.7's store can't write the daily rows (its on conflict names the old keys, which can't stay unique once rows split by version), so its turns, new ratings and counts are lost until the new code is live, each failure reaching onError, and a rating it removes comes off every version's row of its day; the README says to migrate just before the deploy.
    • Upstash: besides the daily-row fields, a turn's stored value gains the version as a last token, so a conversation's version is recomputed from its remaining turns as Postgres and memory do; a turn stored before 0.8 has none and reads as default. A rating's stored value gains the version as a part before its JSON (at␟rating␟bk␟src␟row␟vk␟json); one stored before 0.8 has six parts and no per-version index entry. A conversation without turns has the version of the record written to it first (iv), kept through sweeps, where Postgres takes its earliest remaining record's. A conversation recorded before 0.8 joins its version's list at its next record, as default when its first turn is from before.
    • Live checks: both stores ran the contract against Postgres 17 and against Redis behind Upstash's REST proxy (the CI services). A run against an Upstash database is left to the release, as in 0.7.

    As built in 0.8-v3

    Written at the release (task y1, 2026-12-01) from v3's hand-over: the dashboard's filter and Versions table (decision 4), all in @boldare/askdare-admin, no change to core.

    • The filter: once a bot is chosen (or a user's scope has one bot), a Version select narrows every view; its options come from the versions the store has rows for. It resets when the bot changes. The dashboard's range() checks the name's pattern and refuses a version without a bot, as core's checkRange does.
    • The Versions view, for viewer and up like the other daily totals: one row per version from the chat daily rows of the chosen days and bot: new conversations, turns and failed turns, cost and cost per conversation (none when a model has no price or a version had no turn), 👍 and 👎 with the 👎 share of rated answers, the unanswered share, the handoff rate (handoffs capped at one per conversation, as the resolution rate counts them), leads per 100 conversations, and the first day the version answered. Each rate sits next to its n; there are no p-values or winner badges, and docs/prompt-versions.md ("Reading a comparison") shows how to check a difference by hand. Rows are sorted by first day, then name, with versions that had no turn last. The view ignores a version filter.
    • Size: the dashboard is 9,179 of its 12,288 bytes gzipped. Its wide table scrolls in a focusable, named region, which axe asked for on CI's fonts.

    As built in 0.8-v4

    Amended on 2026-11-30 (task v4, askdare eval --version), where the code adds to "How this fits askdare eval":

    • The request: version on the eval request is optional and must match the names' pattern; the route checks it with hasVersion and answers invalid_input with Unknown version "<name>". This bot has: <names>. before any turn or reservation. Without it the run is the bot's own version. The turn and the grader call both report the run's version to onUsage, and the result carries version, which the CLI checks against the one it asked for.
    • A versions request: the CLI doesn't know a bot's versions, or even its own version's name, so before any case it sends { protocol: 1, kind: 'versions', bots } to the same route, with the same eval token, and gets each bot it has with its versions, the bot's own first (unknown bots left out). That is how it keys the baseline by the own version's name without --version, expands all, and stops on an unknown bot or version before any run spends tokens (exit 2). The estimate comes after it, so it needs the app running. When the request itself fails (the app unreachable, another CHAT_SECRET, no eval option), the run stops as it did at a first case: exit 2, the reason in the pretty summary, and the JUnit and JSON reports written with no case run. It sends the version on every run, the own one included. The route still checks each run, for an app redeployed during a run.
    • The baseline (version 1, not yet shipped) gains a required version on each entry, and the key is bot, version and case. --update-baseline replaces the entries of the versions it ran, keeps the others', and drops entries of versions the app's bot no longer lists (a bot the app didn't list keeps its entries). The estimate takes each version's own tokens per run.
    • Side by side: with --version, a case line names its version as bot@version; the summary gives each bot's version its own pass rate and noise band against its own entries (no rate over all versions), and a case run in several versions gets one line with each version's result. JUnit has a suite per bot and version (support@shorter). The JSON report (version 1) has version on every result and summary.versions, one entry per bot and version, always, even for one.
    • askdare --version as the first argument still prints the CLI's version; after eval it is the flag.
    • The site: the docs bot has a draft version, brief, with no experiment, so the e2e runs the site's set against two versions with the OpenAI mock.
    • The Tests view (decision 4 of "How this fits"): the console's run-case action takes an optional version, checked by the eval path as the CLI's is, and the view has the playground's picker (shown for a bot with more than one version; the bot's own by default). Picking another version clears the page's results; each result names its version.
    • ADR-0006 lists the names since 0.8-z1 (2026-11-30).