Governance
Governance in Ailu answers three questions about every run: who allowed each sensitive action, what the agent saw and did, and can we prove it later. The building blocks:
| Need | Tool |
|---|---|
| A person decides before an agent acts | Tool approval and human gates |
| A record of each decision that can't be edited unnoticed | Signed decisions |
| Proof that a run happened as recorded | Replay |
| No secrets or personal data sent to a model or written to logs | Redaction and noLog |
Sign approval decisions
An approval engine keeps the approval requests and who resolved them. An attestor signs each decision with Ed25519 and links it to the previous one, so removing or editing a record breaks the chain.
import { Ed25519Attestor, InMemoryApprovalEngine, verifyChain, type NodeId, type RunId } from "@ailu-ai/graph-sdk";
const approvals = new InMemoryApprovalEngine();
// Keep the private key in your secret store; publish the public key to your auditors.
const attestor = new Ed25519Attestor();
// An agent asked to refund; a named human approved it.
const request = await approvals.request({
runId: "run-42" as RunId,
nodeId: "assistant" as NodeId,
requestedBy: "assistant",
subject: { description: "refund order ORD-8830" }
});
const approved = await approvals.approve(request.id, "alice@example.com");
// Sign each decision, chained to the previous one.
const first = attestor.attest(approved, null);
const records = [first];
// Anyone holding the records can check them. Also check that record.publicKey is your key.
console.log(verifyChain(records)); // true
approvals.approve(id, user)refuses a user who is also the requester (ApprovalSelfApprovalError), and refuses to resolve a request twice.verifyChain(records)checks the links and every signature. It checks each signature against the public key stored in the record, so also compare that key with the one you published.new Ed25519Attestor(keys, { signCallKey: true })also signs, for a gated tool call, itscallKeyand thegrantthe signature gave: the call key when the grant is the call, else the tool's name. Turn it on once you store both fields with the record: a record kept without them no longer verifies.InMemoryApprovalEngineis for development. In production, implement theApprovalEngineinterface over your database.
To file approval requests automatically when a run stops, run the graph with the catalog runner
and pass the engine: runCatalogGraph(app.definition, { approvalEngine, tools }). Each gated
tool call and each human gate gets a request you can list with approvalEngine.getPending(runId);
their ids are also saved in the run's state.
Pass the same engine to resumeCatalogGraph. It checks the engine before anything runs, and
throws ApprovalNotGrantedError if a request the run waits on is still pending, a human gate or
a gated tool was rejected (since 2.7.0 a refused tool gate ends the run: end it on your side, the
engine feeds the model no « rejected » answer), a request was approved by the agent or gate that
asked for it, or a tool in approvedTools isn't approved by the person the grant names. Since
2.7.1, every grant must answer a request the run filed and someone approved: a grant is refused
when the run filed no request, and when the run isn't suspended at all (it waits on no approval).
An approval-gated tool inside a subgraph's child run is refused with ApprovalRefusedError (no
grant can reach a child run yet): fail the run with its reason.
Resume across processes shows it.
What to file and whether a resume may go on are decided by the Ailu engine itself; your
ApprovalEngine only stores the requests and returns them by id.
Without approvalEngine, resumeCatalogGraph doesn't check anything: it continues past a human
gate.
Audit exports from Ailu Studio can be checked by anyone, offline:
npx @ailu-ai/verify capsule.json --key <published public key>.
Replay a run
With AILU_LLM_RECORD=1, the catalog runner records every model call and timestamp of the run.
Store the recording with the run. Later, replay it: the engine re-runs the graph from its first
state, feeding it the recorded model outputs instead of calling a model, and must reach the same
result.
import { docQaReferenceDefinition, replayCatalogGraph, runCatalogGraph } from "@ailu-ai/graph-sdk";
const definition = docQaReferenceDefinition();
// 1. Record: with AILU_LLM_RECORD=1 the engine journals every model call and timestamp.
process.env.AILU_LLM_RECORD = "1";
const recorded = await runCatalogGraph(definition, {
initialData: { question: "How does Ailu resume a run?", documents: "Ailu checkpoints after every node." }
});
delete process.env.AILU_LLM_RECORD;
// Store these two with the run: they are the evidence.
const { entryState, replayJournal } = recorded;
// 2. Replay, later and elsewhere: the run is re-derived from its entry state
// using the recorded model outputs. No model is called.
const replayed = await replayCatalogGraph(definition, entryState!, "audit-1", replayJournal!);
console.log(JSON.stringify(replayed.state.channels.answer) === JSON.stringify(recorded.state.channels.answer)); // true
A replay never calls your own code either: tools and the steps you bind with nodes get their
recorded results. Nor does it call the personal-data redaction service: the recording keeps what
the service returned (the redacted texts, never the originals), and the replay reuses it, so a run
recorded with AILU_PII_REDACTOR_URL replays offline without it. A recording made before 2.8.3
does not keep it: replay it with the service configured.
To compare the approval decisions of a replay with the signed chain, use
verifyReplayDecisions(attested, replayed): it returns ok and the list of mismatches. The
engine makes the comparison, so Python gets the same answer from
ailu.verify_replay_decisions(attested, replayed).
Build the replayed side with replayedDecisions(replay, graph) (Python:
ailu.replayed_decisions(replay, graph)). A replay files nothing, so its pendingApprovals never
name the human gate it stopped at; replayedDecisions returns what a run files where the replay
stopped: the agents' tool requests, each with its callKey, then the human gate (gate:<node id>).
Build the attested side with attestedDecisions(records): one decision per request, its last
link, so a request signed by several members (a quorum) counts once. Links are the same request
only when their run, request id, subject and call all match.
Redact secrets and personal data
Before any text reaches a model, the engine scans it for secrets (API keys, tokens, private keys)
and masks them. This is always on. Set AILU_SECRETS_POLICY=block to fail the call instead of
masking.
For personal data (names, emails, account numbers), point the engine at a redaction service with
AILU_PII_REDACTOR_URL. The service receives the outgoing texts and returns them redacted. If it
is unreachable, the text is sent unredacted unless you set AILU_PII_REDACTOR_FAIL_CLOSED=1,
which is what you want in production.
Keep secrets out of logs
A channel marked noLog: true is masked in every run event, so it never reaches your logs or
traces. It is still checkpointed, so the run can resume.
import { createGraph, type RunEvent } from "@ailu-ai/graph-sdk";
const app = createGraph({ name: "kyc" })
// noLog: the value is checkpointed as usual but masked in every run event and log.
.channel("passport", { type: "string", default: "", noLog: true })
.channel("verified", { type: "boolean", default: false })
.node("check", async (_input, state) => ({ verified: state.channels.passport.length > 0 }))
.compile();
const events: RunEvent[] = [];
app.onEvent((event) => events.push(event));
const out = await app.run({ passport: "X1234567" });
console.log(out.channels.verified); // true
console.log(JSON.stringify(events).includes("X1234567")); // false
Next
- Send traces and costs to your observability stack: Observability.
- Production settings: Deploy to production.