Human approval
A human gate is a node that stops the run. Everything before it has run and is checkpointed; nothing after it runs until you resume.
import { createGraph } from "@ailu-ai/graph-sdk";
const app = createGraph({ name: "publish-flow" })
.channel("draft", { type: "string", default: "" })
.channel("published", { type: "boolean", default: false })
.node("write", async () => ({ draft: "Release notes for 2.0" }))
.humanGate("review")
.node("publish", async () => ({ published: true }))
.edge("write", "review")
.edge("review", "publish")
.compile();
const paused = await app.run();
console.log(paused.status); // "suspended"
console.log(paused.currentNodeId); // "review"
// What is the run waiting for? Useful in a UI, a log, or for an AI agent.
console.log(app.explain(paused.runId).summary);
// After a human approves in your app, resume on the same CompiledGraph.
const done = await app.resume(paused.runId);
console.log(done.status, done.channels.published); // "completed" true
The approval flow in an app
- Run.
run()returns as soon as the run reaches the gate, withstatus: "suspended"andcurrentNodeIdset to the gate. Save therunId. - Show. Display what needs review. The channels are on the returned state;
app.explain(runId)describes the wait in words. - Resume. When a person approves, call
app.resume(runId). The run continues from the gate.
resume works on the CompiledGraph instance that started the run, while your process is up.
To resume after a restart or in another process, run the graph with runCatalogGraph and keep
its state: see Long-running runs.
Gate a tool, or gate the run?
| You want to... | Use |
|---|---|
| Review a step's output before the run goes on (a draft, a plan, a price) | humanGate |
| Approve a specific action an agent wants to take (a refund, a deletion) | a tool with requiresApproval. See Tools and approval. |
Several gates
A graph can have as many gates as it needs. Each resume runs until the next gate or the end.
A gate inside a subgraph suspends the parent run
too, and resume on the parent continues the child.
Next
- Wait for a webhook or a date instead of a person: Long-running runs.
- Sign each decision: Governance.