Founding 10 · The first ten agencies get the €299 security review free →
NIVORYN

Docs · Agency workspace (pilot)

Agent Gateway

How a workflow you build (n8n, Make or your own code) runs under NIVORYN's control. Three HTTPS calls: ask before acting, poll approvals, report completion.

1. NIVORYN starts the run

When someone clicks Run now (scheduled and API triggers are planned), NIVORYN checks the emergency stop, the client's status, the daily run limit and both monthly budgets. If the run may start, NIVORYN sends a POST to the agent's webhook URL with the agent's credential (bearer token, API-key header or basic auth, decrypted only for this call) and this body:

{
  "nivoryn": {
    "version": 1,
    "run_id": "6f1c…",
    "run_token": "64 hex characters",
    "agent_id": "…",
    "gateway": "https://<your NIVORYN host>/api/agent-gate/v1/runs/6f1c…"
  },
  "input": { "trigger": "manual" }
}

Respond with any 2xx status quickly (for n8n: “Respond immediately”). Any other status, a timeout of 10 seconds, or an endpoint that resolves to a private address ends the run as failed. Webhook URLs must be public https:// on port 443.

2. Ask before every side effect

Before a step that reads or changes client data, sends something or spends money, call the gateway with the run token:

POST {gateway}/tool-calls
Authorization: Bearer {run_token}
Content-Type: application/json

{ "permission": "email.send", "summary": "Reply to ticket #4812 confirming the appointment" }

The answer is always HTTP 200 with a decision your workflow must branch on:

{ "tool_call_id": "…", "decision": "allowed" | "denied" | "pending_approval", "reason": null | "permission_not_granted" | "tool_call_limit" | "agent_stopped" }
  • allowed: go ahead.
  • denied: do not perform the step. Treat it like an error branch.
  • pending_approval: wait, then poll (step 3).

Permissions: crm.read, crm.write, email.draft, email.send, calendar.write, payment.initiate, http.request, data.export. The summary is shown to the approver; keep it factual. Approvers are told it is written by the workflow and is untrusted.

3. Poll approvals

GET {gateway}/tool-calls/{tool_call_id}
Authorization: Bearer {run_token}

→ { "decision": "pending_approval" | "approved" | "rejected" | "expired", "reason": "…" }

Poll every 10–30 seconds. Runs that do not finish within 15 minutes are closed as timed out.

4. Report completion

POST {gateway}/finish
Authorization: Bearer {run_token}

{ "status": "succeeded" | "failed", "input_tokens": 1200, "output_tokens": 300, "cost_cents": 2, "error_code": null }

Token counts and cost are what your workflow reports (for example from your model provider's response); they feed the budgets. After this call the run token stops working.

Security properties

  • The run token is random, stored only as a SHA-256 hash, valid for one run, and revoked by finish, emergency stop, agency halt or a limit breach.
  • A wrong, expired or foreign token gets HTTP 401. A token cannot act on another run.
  • Decisions are made in the database, outside the model. An agent that has been prompt-injected can ask, but it cannot grant itself a permission.
  • The controls apply only to steps your workflow routes through the gateway. Design workflows so side effects are impossible without an allowed or approved answer.

n8n recipe

  1. Webhook node (POST, respond immediately). Store body.nivoryn.gateway and body.nivoryn.run_token.
  2. Before each side-effecting node: HTTP Request node → POST {{gateway}}/tool-calls with header Authorization: Bearer {{run_token}}.
  3. IF node on decision: allowed → continue; pending_approval → Wait + poll loop; anything else → stop branch.
  4. Final HTTP Request node → POST {{gateway}}/finish with status and usage, on both success and error paths.

Questions during the pilot: contact us.