[feat]: generalize decision callback requests

SE
1d ago
+3817-1001

why

the decision callback currently answers one question: pick an id from a list. this pr lets a request carry several questions over shared evidence, starting with choice & boolean questions.

for prompt locators, this replaces the made-up “none of these” choice with a separate question asking whether any eligible element matches. getByPrompt() & get_by_prompt() keep the same public api.

what changed

  • replaced choose with decide in both sdks & decision.choose with decision.request on the wire. requests contain shared state, typed questions, & optional metadata; results contain one answer per question, matched by id. the old, unreleased contract is removed.
  • choice questions expose criteria & return a supplied id, with optional probabilities & confidence. boolean questions return a probability; either question can receive a refusal. validation checks answer coverage, types, criterion ids, duplicate probability ids, & probability bounds against the original request.
  • added optional supports & limits to callback configuration. support defaults to choice & boolean questions. prompt actions check configuration, supported types, & capacity for two questions before scope resolution or capture; candidate counts are checked against maxChoices before dispatch.
  • prompt locators now ask which element to select & whether any element marked with an id in the tree matches. a match probability below stagehand's threshold means no match, regardless of the selected target's confidence. refusal on either question fails as a refusal; provider failures remain errors.
  • added structured source metadata with an optional operation. prompt operations use the same action names in both languages, such as click, select, & upload. python callbacks receive concrete question & state models directly, & both sdks export the concrete decision types, including DecisionCriterion.
  • retained deadline propagation, cancellation, cleanup, & original target identity. updated generated schemas, callback examples, reference docs, & sdk parity checks for the revised contract.

test plan

added & extended tests covering:

  • mixed question requests, answers in a different order, per-question refusals, missing/duplicate/unknown answers, invalid scores, & rejection of ids outside each question's criteria.
  • wire casing that preserves supplied ids, source-only metadata, concrete python callback models, public types, & validation against callback mutation.
  • default & explicit capabilities, exceeded limits, & configuration errors before resolving an empty scope or capturing a page.
  • selected, no-match, & refused prompt results, including low match probability with high target confidence & language-neutral operations for all eight actions.
  • callback registration, public sdk & batch dispatch, cancellation, expired deadlines, late results, & cleanup in both sdks.

Summary by cubic

Generalizes the decision callback from answering one "pick an id" question to answering multiple typed questions over shared evidence. Prompt locators now ask which element to select and whether any eligible element matches; the fabricated "none of these" choice is gone, and getByPrompt() / get_by_prompt() keep the same public API.

Breaking changes

  • choose becomes decide in both SDKs, and decision.choose becomes decision.request on the wire; the unreleased old contract is removed.
  • Requests carry shared state, typed questions keyed by ID, and optional metadata; results contain one answer per question, matched by question ID.
  • Choice answers return a supplied criterion id with optional probabilities and confidence; boolean answers return a probability; either question can be refused.
  • Provided probabilities must include every criterion and sum to 1.
  • Callback configuration adds optional supports and limits; prompt actions validate configuration and capacity before scope resolution or capture.

Prompt locators

  • Candidate IDs are now short integers, and the request includes the scoped page tree as shared evidence.
  • A match probability below 0.5 means no match, regardless of the selected target's confidence.
  • Refusals fail the prompt; provider failures remain errors; deadline, cancellation, and cleanup behavior is unchanged.