Cogitator
Tools

Approvals

Pause an agent before it runs a sensitive tool, let a person decide — now or hours later — and continue the run where it stopped.

Overview

A tool with requiresApproval never runs without a person's say-so. When the model calls it, the run either asks right away (onApproval) or pauses: it returns with status: 'paused' and the calls that wait, keeps its state, and goes on with cogitator.resume() once someone decided — a minute later, after a Telegram reply, or after the server restarted.

const refund = tool({
  name: 'refund',
  description: 'Refund an order',
  parameters: z.object({ order: z.string(), amount: z.number() }),
  requiresApproval: ({ amount }) => amount > 100, // small refunds need no one
  sideEffects: ['external'],
  execute: async ({ order, amount }) => payments.refund(order, amount),
});

const result = await cog.run(support, {
  input: 'Refund order A-1, it arrived broken',
  threadId,
  userId,
});

if (result.status === 'paused') {
  for (const call of result.pendingApprovals!) {
    console.log(`${call.toolName}(${JSON.stringify(call.arguments)}) needs approval`);
  }
}

Nothing of the paused turn has run: if the model asked for several tools at once, all of them wait, so a decision never comes after side effects already happened.

requiresApproval is true (always ask) or a function of the model's arguments as sent — before schema parsing and defaults. A function that throws counts as "needs approval". Each waiting call in pendingApprovals is a ToolApprovalRequest: { toolCallId, toolName, arguments, description, sideEffects? }, where description is the tool's description.

With permissions set up, rules decide many calls before anyone is asked, and a request that asks also carries reason (why it asks), rule (the ask rule that made it ask, if one), suggestedRule (what an "always allow" answer saves) and mode.

Resuming

The runtime keeps the paused run per thread. Resume it with a decision for each call — declined calls answer the model with the reason, so it can tell the user or try something else:

const done = await cog.resume(support, threadId, {
  userId,
  decisions: {
    [callId]: { approved: true },
    // or { approved: false, reason: 'refunds over $100 need a manager' }
  },
});

A decision may also change the call, { approved: true, updatedArguments }, which runs once the new arguments pass the schema and the permission rules again, and save an allow rule for next time, { approved: true, remember: true } ("always allow"), see Permissions.

defaultDecision answers every waiting call at once ({ approved: true } for "approve all"). Calls without a decision keep the run paused. Resuming by thread id checks the caller: only the user the run belongs to may resume it (THREAD_ACCESS_DENIED otherwise), and a thread with nothing paused answers RUN_NOT_PAUSED.

If the user writes something new instead of deciding, the waiting calls are answered as declined ("the user moved on") and the new run starts from a consistent history.

Deciding Inline

When a person can answer while the run waits — a CLI prompt, a confirm dialog over a WebSocket — decide inline. Return 'pause' to fall back to pausing:

await cog.run(agent, {
  input,
  onApproval: async (call) => {
    const ok = await confirm(`Run ${call.toolName} with ${JSON.stringify(call.arguments)}?`);
    return ok ? { approved: true } : { approved: false, reason: 'declined in the CLI' };
  },
});

Without onApproval, or when it returns undefined for a call, guardrails.onToolApproval ((toolName, args, sideEffects) => Promise<boolean>) decides when it is set, otherwise the run pauses. With guardrails strictMode, every call of a tool with sideEffects goes through the same flow, as if the tool had requiresApproval. onApproval is a run option, so it also works for cog.resume(), where it decides calls the model makes after resuming.

Agents wrapped with agentAsTool() cannot pause: unless you pass onApproval to agentAsTool, their calls that need approval are declined (as they are when that onApproval returns 'pause') and the inner agent is told why.

Where Paused Runs Live

SetupPaused runs are kept in
memory configuredthe thread's metadata — as durable as the memory (Redis, Postgres, SQLite, MongoDB)
no memoryprocess memory
runCheckpoints: myStoreyour RunCheckpointStore (save, load(threadId), delete(threadId))

The checkpoint holds the whole conversation, so it stays on the server. You can also keep it yourself, result.checkpoint is plain JSON, and pass it back: cog.resume(agent, checkpoint, { decisions }). It also keeps the run's parallelToolCalls, maxParallelToolCalls and timeouts (checkpoint.toolExecution), which the resume reuses unless its own options set them.

Servers and Chats

  • Server adapters answer a paused run with status: 'paused' and pendingApprovals, stream an approval-required event, and take decisions on POST /agents/:name/resume ({ threadId, decisions?, defaultDecision? }), or on POST /agents/:name/resume/stream with the same body to stream the rest of the run.
  • Channels ask in the chat ("reply approve or deny") and resume when the user answers — see Gateway approvals.

A Pause Is Never an Answer

A paused run's output is whatever the model said before it asked for the tools, not its answer. Everything that hands a run on keeps the pause visible, and isPausedRun(result) from @cogitator-ai/core tells the two apart in your own code:

import { isPausedRun, AgentRunPausedError } from '@cogitator-ai/core';

if (isPausedRun(result)) {
  await approvals.ask(result.pendingApprovals, result.checkpoint);
}

Where a caller has no way to wait for a decision, the pause becomes an AgentRunPausedError (code RUN_PAUSED, HTTP 409) with agentName, threadId, pendingApprovals and the checkpoint to resume from. findAgentRunPausedError(error) finds it behind errors that wrap it.

The run result wire format (toAgentWireRunResult, used by queue jobs and distributed swarm turns) carries status, pendingApprovals and checkpoint, so a run that paused on one process resumes on any other: cog.resume(agent, wire.checkpoint, { decisions }).

Approvals Are Interrupts

A pending approval is also listed in result.interrupts as an interrupt of kind: 'approval', its id the tool call id. resume() takes its decision in responses as well ({ [toolCallId]: { approved: true } }), so a UI that answers the questions tools ask with context.interrupt() handles approvals the same way. decisions and defaultDecision keep working. See Interrupts.

Tool Calls Outside a Run

Code that runs tools without an agent run, like an MCP server or a self-modifying agent, uses cogitator.invokeTool() to treat them the way a run does: the arguments are validated against the schema, a call that needs approval is decided by onApproval (else guardrails.onToolApproval), the guardrails apply, sandboxed tools run in the runtime's sandbox, tool.timeout holds and the Cogitator's wrapToolCall middleware wraps the call. There is no run to pause, so a call nobody approves does not run: the result's error says so and pendingApproval holds the request. The guardrails need a model: guardrails.model, else the agent's model as in a run when you pass the agent ({ agent }), else llm.defaultModel, or calls through invokeTool skip them until a run has built the guardrails with its agent's model (the runtime warns once). With agent the call also gets the agent's own wrapToolCall middleware after the Cogitator's, and its id and name, as a run of that agent would. The request onApproval gets names the call's agentId, threadId and userId when the options set them.

const result = await cog.invokeTool(
  exec,
  { command: 'ls -la' },
  {
    onApproval: async (call) => ((await confirm(call)) ? { approved: true } : { approved: false }),
  }
);

A Cogitator is a ToolInvoker (invokeTool(tool, args, options)), the interface those packages take. Every path that runs tools for a model outside a run goes through it:

PathWho decides a call that needs approval
MCPServerThe person at the MCP client, through elicitation (a round of the call on 2026-07-28)
Realtime voicecreateRealtimeTools(cogitator, tools, { onApproval })
AI SDK toolsThe AI SDK approval flow (ai@6, ai@7), else onApproval of toAISDKTool(tool, { invoker })

Tools imported from an MCP server need approval when the server marks them destructive, see Approval for Destructive Tools.

When the arguments were already parsed with the tool's own schema (by the MCP SDK or the AI SDK), pass withParsedArguments(tool) from @cogitator-ai/core: the call keeps the tool's approval, sandbox, timeout and limits, and the schema's transforms apply once instead of twice.

On this page