Approvals

A method listed with .callsWithApproval runs only after the user approves it.

List every value the method depends on with .sees. Approval applies to those values, and changing any of them permanently invalidates the request. The agent must request approval again. Changes outside .sees, such as the selected tab, leave the request pending.

Tandem also compares the screen with what the agent saw at the start of the run. A change during that run invalidates its approval requests before they appear, even if one of the agent's own calls made the change.

Ask again after an edit

Invalidating a visible request does not by itself start a new run. The agent receives the invalidation with the next run, normally after the user's next message. Your app can call session.wake() to let the agent ask again without another user message.

The example's order desk waits for one second after the last edit before waking the agent. It does so only when the latest request came from the in-app agent, was invalidated and has no later user or app message:

bool agentMustAskAgain(TandemSession session) => switch ([
  for (final item in session.items)
    if (item is ApprovalRequest || item is UserMessage) item,
].lastOrNull) {
  ApprovalRequest(status: .invalidated, caller: .inAppAgent) => true,
  _ => false,
};

The example implements this debounce and wake. Add equivalent handling in your app if it should ask again automatically.

Choose the approval UI

approvals: on the scope controls how the screen asks the user:

approvals:For
.fromState()Render requests from session.items or AwaitingApproval(request) in your own UI.
.callback((context, request, session) async { ... })Open a dialog, bottom sheet or another UI from a callback.
.none()Refuse calls that need approval and report them in debug. Use this for a screen without .callsWithApproval.

The example's order screen passes approvals: const .callback(confirmOrder) to show a dialog:

Future<void> confirmOrder(
  BuildContext context,
  ApprovalRequest request,
  TandemSession session,
) async {
  final draft = context.read<OrderCubit>().draft;
  final place = await showDialog<bool>(
    context: context,
    builder: (context) => _PlaceOrderDialog(draft),
  );
  session.decide(request, approved: place ?? false);
}

The dialog shows the draft from the Cubit, because approval applies to what .sees lists. If the draft changes while the dialog shows, the request is invalidated and decide returns false without placing the order. If several methods need approval, switch on request.tool, such as OrderCubitTool.placeOrder, to choose the dialog's wording.

Track a request

request.status is an ApprovalStatus:

StatusMeaning
pendingThe request awaits the user's decision.
approvedThe user approved it, and the method is running or has run.
rejectedThe user rejected it.
invalidatedA value listed with .sees changed, so this request can no longer be approved.
cancelledThe request was cancelled, such as when the user sent a message instead of deciding.

Several requests from one turn appear one at a time. The next appears after the previous decision and, if approved, after its method returns. Rejecting a request cancels the remaining calls of that turn and lets the agent plan again.

session.decide(request, approved:) records the decision and returns false when the request can no longer take it. session.approve(request) and session.reject(request) throw ApprovalNotPending in that case. Repeating the same decision has no effect, so a double tap is harmless. Use session.isPending(request) to check whether the request still awaits a decision.

A new user message cancels the visible pending request. If the callback returns without deciding, the request stays pending until a later decision or cancellation.

Requests from a coding agent or a button in a drawn view use the same approval UI. request.caller identifies who asked: Caller.inAppAgent, Caller.codingAgent or Caller.view. A decision on a coding agent's or view's request does not by itself start an in-app agent run. Use that caller when an invalidated card tells the user what to do next.