Cortex · API

run.approve

run.approve accepts a pending approval, optionally with replacement arguments, and the tool call is executed. A gate that returns ask pauses the run before the tool function executes and emits approval-required; here the approver passes args that refund one seat of the two. The model’s turns are scripted; no model is called.

Gate and agent
const askFirst: ToolGate = (call) =>
  call.toolId === 'refund' ? { ask: { reason: 'A refund moves money.' } } : { allow: true };

const desk = defineAgent({
  id: 'desk',
  instructions: 'Help the member. Refund a booking when the member asks for it.',
  tools: [refund],
  toolGates: [askFirst],
});

const run = desk.run('Please refund my two seats for Saturday. Grace', { llm });
Run, step by step
Scripted model turn
calls refund {"booking":"B-2041","amount_cents":7600}
Event
{
  type: 'tool-start',
  call: {
    toolId: 'refund',
    args: { booking: 'B-2041', amount_cents: 7600 },
  },
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.