[feat]: expose `decisionModel` callback

SE
5h ago
+1395-35

why

prompt locators will need to call a decision model through the user's application. this pr lets users register a callback through Stagehand.create() & connects it to internal runtime requests, including cancellation & cleanup. public prompt locators come in a later pr.

what changed

  • added decisionModel: { choose } in TS & decision_model={"choose": callback} in python. decision callbacks can be configured alongside the existing generation callback
  • the callback receives input, instructions, & choices, then returns answered with a supplied choice id or refused. provider failures remain errors
  • added DecisionContext with the request id & remaining operation budget. typescript supplies an AbortSignal; python cancels the callback task directly
  • connected runtime requests to the registered callback, with result validation & a specific error when no decision callback is configured.
  • deadlines, caller cancellation, disconnect, & disposal stop waiting for the callback. concurrent requests remain independent, & late results cannot resume a stopped operation. handlers & timers are cleaned up when no longer needed.
  • added callback examples & reference docs

test plan

added & extended tests covering:

  • callback registration before initialization, invalid configuration, coexistence with generation callbacks, & cleanup after failed initialization or close in both sdks.
  • runtime-to-sdk requests through an in-memory transport, including valid answers, refusal, provider errors, missing configuration, & rejection of answers outside the original choices.
  • remaining deadline propagation, expired requests skipping inference, unlimited deadlines, & cancellation notifications reaching the correct callback.
  • independent concurrent requests, ignored cancellation for completed requests, & cleanup on unregister, disconnect, close, or disposal.
  • providers that ignore cancellation & later succeed or fail, verifying the operation stops without waiting for them.

Summary by cubic

Lets applications handle choice-based questions with their own model by registering a decisionModel callback in Stagehand.create(), keeping provider credentials and clients in the application process.

  • Added decisionModel: { choose } in TypeScript and decision_model={"choose": callback} in Python alongside the existing generation callback.
  • The callback receives input, instructions, and choices, and returns an answered result with a supplied choice ID or a refused result; provider failures remain errors.
  • DecisionContext provides the request ID and remaining operation budget, with an AbortSignal in TypeScript and task cancellation in Python.
  • Runtime decision requests now route through the registered callback with result validation and a specific error when no callback is configured.
  • Deadlines, caller cancellation, disconnect, and disposal stop waiting for the callback; concurrent requests stay independent and late results cannot resume a stopped operation.
  • Added callback examples and reference docs for both SDKs; public prompt locators arrive in a later PR.