Decisions and approvals
An agent built on the SuperOrgs SDK can ask a person and wait for the answer. The person approves, rejects, edits, or replies in SuperOrgs or in Slack, and the decision comes back to your code.
Update your agent
Decisions need @superorgs/sdk 0.2.1 or newer. The credential and the run stay as they are in Agent activity streaming.
pnpm add @superorgs/sdk@latestAn agent reports an ask in one of two ways. The difference is who holds the decision.
| Call | What happens |
|---|---|
| Your agent holds the decision | |
run.ask() then run.resolveAsk() | SuperOrgs lists the ask and links to your own page. The person decides there, and your agent reports what they chose. Nobody can decide it in SuperOrgs. |
| SuperOrgs holds the decision | |
run.question() | Your agent chooses to ask. A person answers in SuperOrgs, and the answer comes back to the agent. |
run.guard() or run.gate() | A rule in the workspace decides when to ask. A person decides in SuperOrgs before the action runs. |
An agent that calls run.ask() keeps working: its asks are listed on the Decisions page in SuperOrgs with a link to the agent's own page, and they are decided there. To let people decide in SuperOrgs, change that call to run.question() or to a gate.
// The ask is listed in SuperOrgs with a link. The person decides on your page.
await run.ask({
askId: 'brief-42:v1',
kind: 'approve',
title: 'Send the brief to Dana?',
reason: 'First sends to an enterprise account wait for the owner.',
url: 'https://agent.example.com/briefs/42',
})
// Later, from your own page or Slack handler, once the person decides.
await run.resolveAsk({ askId: 'brief-42:v1', decision: 'approved', via: 'slack' })The agent needs no public address. The SDK holds one request open to SuperOrgs and decisions arrive over it, so the agent works behind a firewall, in a container, and on a laptop.
Ask a question
Call run.question() when your agent chooses to ask. It needs no rule. The run shows as waiting in SuperOrgs, and the call resolves when a person decides. A question that expires resolves as expired within about five minutes of its expiry.
const proposed = { ticket: '4821', text: 'Your refund was issued today.' }
const review = await run.question({
title: 'Post this reply to ticket 4821?',
kind: 'approve',
reason: 'Replies to refund tickets wait for a person.',
// What the person reads.
draft: proposed.text,
// What is about to happen. The person may edit its input before they approve.
action: { tool: 'post_reply', input: { ...proposed } },
expiresAt: new Date(Date.now() + 60 * 60 * 1000),
})
if (!review.proceed) {
// Rejected, answered with other instructions, or expired. Nothing is posted.
await run.finish({ summary: 'The reply was not posted.' })
} else {
// After an edit, the text is the person's. The ticket stays the agent's own.
const edited = review.input?.text
const text = typeof edited === 'string' && edited.trim() ? edited : proposed.text
await postReply({ ticket: proposed.ticket, text })
await run.finish({ summary: 'Posted the reply.' })
}| Option | Use |
|---|---|
| run.question(options) | |
title | The question, as a person reads it. Required. |
kind | approve, choose, or input. |
reason | Why the agent asks. |
options | The choices of a choose question. The first 12 are kept. |
draft | What the person reads before they answer. |
action | What is about to happen, as { tool, input }. The person can edit the input before they approve. |
assignee | The email of the person to ask. The default is the agent's owner. |
anyone | Set true to let anyone who can see the agent answer. |
expiresAt | When the question stops waiting. |
askId | Your own id for the ask, so that you can find its decision later. A UUID when omitted. |
The question shows on the Decisions page in SuperOrgs, and the person asked is told in Slack, or by a Microsoft Teams card or an email when Slack cannot reach them. In Slack the message has Approve and Reject, or the first four options of a choose question, with a Reply button. An input question has Reply only.
A draft or an action larger than 256 KB rejects with EventTooLargeError. Nothing is sent, and the call does not wait for an answer that no person can give.
What comes back
A question and a gate resolve with the same shape. decision is the word for what the person chose, proceed says whether the action may run, input is what to run with after an edit, and note is what the person said. decidedBy and decidedAt say who decided and when.
| Decision | What to do |
|---|---|
| proceed is true | |
approved | Run the action. |
edited | Run the action with input. It is the input of the person. |
| proceed is false | |
rejected | Do not run the action. note gives the reason, if there is one. |
answered | Do not run the action. note holds what the person said: the option they picked, the text they typed, or what to do instead. |
expired | No person decided in time. Do not run the action. |
For a choose or an input question, answered is the result to expect. Read the answer from note.
Put an action behind a rule
A gate is a rule that a person sets, so the rules decide when to ask and not the model. A rule names a tool, and can name text that the input must contain. It says who decides: the agent's owner, one person, or anyone who can see the agent. It can also set a time limit for the ask.
Rules are set on the agent's page in the SuperOrgs console, for one agent or for every agent. Before a rule is saved, the console shows how many of the tool calls from the last 7 days it matches. Ask your SuperOrgs contact to turn the console on for your workspace.
Put every action that a person may need to stop behind run.guard(). With no rule on the tool, the action runs at once, so a rule can be added later with no change to the agent.
import { refusalWords } from '@superorgs/sdk'
type Email = { to: string; subject: string; body: string }
const text = (value: unknown, fallback: string) =>
typeof value === 'string' ? value : fallback
// A person can edit any field SuperOrgs shows.
// This agent keeps its own recipient and takes the subject and the body.
const approvedEmail = (approved: Record<string, unknown>, draft: Email): Email => ({
to: draft.to,
subject: text(approved.subject, draft.subject),
body: text(approved.body, draft.body),
})
const draft: Email = {
to: 'dana@example.com',
subject: 'Your weekly brief',
body: 'Three accounts moved to renewal this week.',
}
const result = await run.guard(
{
tool: 'send_email',
input: draft,
title: `Send "${draft.subject}" to ${draft.to}?`,
},
// Runs only after a person approves, and with what they approved.
(approved) => sendEmail(approvedEmail(approved, draft)),
)
if (result.ran) {
await run.finish({ summary: 'Sent the weekly brief.' })
} else if (result.outcome.decision === 'expired') {
// Nobody decided in time. Do not retry: the brief waits for a person.
await run.finish({ summary: 'Nobody approved the brief in time, so it was not sent.' })
} else {
// Rejected, or answered with other instructions. A normal result, not an error.
tellTheModel(refusalWords(result.outcome))
}With a rule on the tool, the run shows as waiting in SuperOrgs and the action runs only after a person approves it. If the person edits the input, the action runs with their input. The SDK reads the rules again after one minute. If that read fails, it keeps the rules it has. If it has never read them, guard() rejects, so an action that can need a person never runs without a check.
run.gate() is the same check without the action. Use it when you run the action yourself. With no rule on the action, it resolves at once with gated: false.
Tools in a framework
When a model calls the tools, wrap them one time. The rules then decide which calls wait.
| Use | For |
|---|---|
| Choose how to connect | |
run.guard() | Code that runs an action. |
gated() | Tools in any framework, such as the OpenAI Agents SDK, LangChain, and LangGraph. |
gatedTools() | A Vercel AI SDK toolset. Import it from @superorgs/sdk/ai-sdk. |
claudeGateHook() | The Claude Agent SDK, as a PreToolUse hook. Import it from @superorgs/sdk/claude-agent-sdk. |
run.openGate() and onDecision() | A process that stops and resumes later. |
The HTTP contract | An agent with no Node runtime. |
import { gated } from '@superorgs/sdk'
type Refund = { order: string; amount: number }
const refundOrder = ({ order, amount }: Refund) => stripe.refund(order, amount)
// The result takes the same arguments. Use it as the execute function of a tool.
const refund = gated(run, 'refund', refundOrder, {
title: ({ order, amount }) => `Refund ${amount} on order ${order}?`,
})
// Tools built one time for many runs: pass a function that returns the current run.
const execute = gated(() => currentRun(), 'refund', refundOrder)
// OpenAI Agents SDK
tool({ name: 'refund', description, parameters, execute })
// LangChain and LangGraph
tool(execute, { name: 'refund', description, schema })If a person does not approve, a gated tool returns a sentence for the model. The sentence says that the action did not run and what to do instead. The tool does not throw. With the Claude Agent SDK a gated call is deferred: the query ends, the tool does not run, and no process waits. Resume the session when the decision arrives.
Instructions and stops
The same open request carries two more things from people to your agent. From a run's page in the SuperOrgs console, a person can tell the run what to do while it works or waits, and can ask a run in progress to stop. SuperOrgs sends the request, and your agent ends the work.
const off = run.onInstruction((instruction) => {
queueForTheModel(`${instruction.from ?? 'A person'} says: ${instruction.text}`)
})| Use | For |
|---|---|
| Instructions | |
run.onInstruction() | What a person tells this run to do while it works or waits. It returns a function that removes the listener. |
onInstruction() on the client | The instructions for every run of the agent. |
| Stops | |
run.stopSignal | An AbortSignal that aborts when a person stops the run. Pass it to a model call, a fetch, or a child process. |
run.onStop() | A function of yours that receives the request: who asked, and why. |
run.stopRequest | The request, or null if nobody asked. |
run.stopped() | Ends the run. SuperOrgs then shows who stopped it. It throws if nobody asked. |
onStop() on the client | The requests for every run of the agent, for a process that keeps its runs by id. |
SuperOrgs does not deliver an instruction that is more than 15 minutes old. After a stop, guard(), gate() and question() reject with RunStoppedError, and a gated tool does not run. A tool that is in progress when the request arrives can finish, unless you pass the signal to it.
A person can send an instruction or a stop only while the agent is connected. The SDK holds its request open while a listener is registered or a call waits for a decision, and reading run.stopSignal starts listening too. Register the listeners when the run starts.
Suspend and resume instead of waiting
guard(), gate() and question() wait in your process. If a person may take hours, use the two halves, so that no process waits.
const opened = await run.openGate({ tool, input, askId: toolCallId })
if (opened) return suspend(toolCallId)
// registered one time, when the process starts
superorgs.onDecision(async (decision) => {
await resume(decision.askId, decision)
})- 1
Open the gate
run.openGate()records the ask and returns its id and the rule that applied. It returns null if no rule applies. - 2
Pass your own ask id
Use an id that you keep, such as a tool call id, so that you can find the decision later. - 3
Listen when the process starts
RegisteronDecision()on the client. It receives the decisions for every run of the agent. - 4
Make the listener safe to run two times
A decision repeats until the SDK gives it to your listener.
run.openQuestion() does the same for a question. Keep the run open while an ask waits: when a run ends, SuperOrgs withdraws its asks that still wait, and no decision follows.
Decisions are delivered to the agent, not to one process. When several processes share a credential, a decision reaches the process that reads it first, so a question() that waits in another process can miss it. Wait in one process, or use onDecision() and find the work by its ask id in storage that every process shares.
Without Node
No Node runtime? The same contract is JSON over HTTPS, with the same bearer credential as the streaming endpoint. Open the ask on a run that you already started.
- 1
Read the rules
GET https://app.superorgs.com/api/agent-stream/v1/policyanswers{ "gates": [{ "id", "name", "tool", "input_contains", "expires_after_minutes" }] }. - 2
Find the gate that applies
Before an action, take the first gate whosetoolequals the name of the action exactly, where*stands for any characters, and whoseinput_contains, if set, is in the JSON input. Compareinput_containswithout case. - 3
Open the ask and do not run the action
Send anask.openedevent on the run withawaits: true,source: "gate",action: { tool, input }andrule_id. When the gate hasexpires_after_minutes, add anexpires_atthat many minutes from now. - 4
Or ask a question
Sendask.openedwithawaits: trueandsource: "question". Put what the person reads inartifactand what they may edit inaction. Addassigneeto name the person by email, oranyone: trueto let anyone who can see the agent answer. - 5
Hold a request open for the decision
GET https://app.superorgs.com/api/agent-stream/v1/signals?wait=25answers when there is a signal, or with an empty list afterwaitseconds. 25 is the longest wait. - 6
Acknowledge what you handled
Sendack=<id>on the next request. It marks every signal up to that id as delivered. A signal repeats until you acknowledge it.
curl -X POST https://app.superorgs.com/api/agent-stream/v0/events \
-H "Authorization: Bearer $SUPERORGS_STREAM_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"events": [
{
"event_id": "job-42:ask:reply-4821",
"run_external_id": "job-42",
"type": "ask.opened",
"occurred_at": "2026-11-24T15:04:00Z",
"payload": {
"ask_id": "reply-4821",
"source": "question",
"awaits": true,
"kind": "approve",
"title": "Post this reply to ticket 4821?",
"reason": "Replies to refund tickets wait for a person.",
"action": {
"tool": "post_reply",
"input": { "ticket": "4821", "text": "Your refund was issued today." }
}
}
}
]
}'Send the current time in occurred_at. To set a time limit, add an expires_at in the future: an ask that arrives already expired cannot be decided.
Run the action only for approved or edited. For edited, use input. A decision also carries decided_at, and note when the person wrote one. An ask that expires arrives as a decision of expired.
The same request delivers instructions and stops. An instruction is { id, kind: "instruction", run_external_id, text, from? }. A request to stop is { id, kind: "stop", run_external_id, text?, from? }, where text is the reason. End the work, then send run.finished with stopped: { "signal": <id> } in the payload, and SuperOrgs shows who stopped the run.
The npm package ships examples/http/ledger.py, a complete agent on this contract that uses the Python standard library only.
Good practice
- 1
Ask for one decision at a time
A decision covers the whole ask. Put two actions in two asks, so that a person can approve one and reject the other. - 2
Show the exact action
Prefer a gate on the tool over a free-text question. A gate carries the tool name and its input. Use a question for what a rule cannot name: a choice, a missing fact, a draft to read. - 3
Set an expiry, and decide what happens when time runs out
A question takesexpiresAt. A gate takes its time limit from the rule. Onexpired, do not run the action and do not ask again in a loop. Leave the work undone, take a safe default, or say that the work waits for a person. - 4
Run with the input the person approved
After an edit, readinputfrom the decision and not from the value that you proposed. Check it as you would the model's own output, and keep the fields a person must not change, such as a recipient, from your own draft. - 5
Act one time per approval
One approval covers one run of the action. Do not retry after a rejection or an expiry. A decision can arrive more than one time, so key the work on the ask id and skip an ask that you already handled. - 6
Treat a rejection and a stop as normal results
guard()resolves withran: falsefor a rejection, an answer, or an expiry. It does not throw. When a person stops the run,guard(),gate()andquestion()reject withRunStoppedError. End the run withrun.stopped().