Regolamento IA Art. 14: approvazione umana prima che un agente agisca
Metti in pausa rimborsi, cancellazioni o invii esterni finché una persona non decide: spurvikInterrupt (LangGraph), createSpurvikNeedsApproval (OpenAI Agents), link firmati Slack/Teams o spurvik_guard.py — solo approved esegue il tool.
Blocca una chiamata tool sensibile prima dell’esecuzione
spurvik@1.0.16 · MIT · solo approved proseguenpx spurvik gateInvia a CTO / CISO // graph.ts · npm i spurvik@1.0.16 @langchain/langgraph
import { spurvikInterrupt } from "spurvik/langgraph";
const config = {
apiKey: process.env.SPURVIK_API_KEY!,
signingSecret: process.env.SPURVIK_SIGNING_SECRET!,
contentHash: { mode: "keyed" as const, secret: process.env.SPURVIK_CONTENT_HASH_SECRET! },
baseUrl: process.env.SPURVIK_BASE_URL ?? "https://console.spurvik.com",
riskTier: "limited_art50" as const, // your own classification
};
export async function refundNode() {
// Sends field names + keyed digest to Frankfurt queue, waits up to 120 s.
const decision = await spurvikInterrupt(
{ actionName: "issue_refund", payload: { order_id: "1042", amount_eur: 420 } },
config,
);
if (!decision.approved) return { status: decision.status }; // rejected / overridden: never runs
// ... execute refund only on approved ...
return { status: "approved" };
}
// agents.ts · npm i spurvik@1.0.16 @openai/agents zod
import { Agent, run, tool } from "@openai/agents";
import { z } from "zod";
import { createSpurvikNeedsApproval, resolveAgentInterruptions } from "spurvik/openai-agents";
const config = {
apiKey: process.env.SPURVIK_API_KEY!,
signingSecret: process.env.SPURVIK_SIGNING_SECRET!,
contentHash: { mode: "keyed" as const, secret: process.env.SPURVIK_CONTENT_HASH_SECRET! },
baseUrl: process.env.SPURVIK_BASE_URL ?? "https://console.spurvik.com",
riskTier: "limited_art50" as const,
};
const issueRefund = tool({
name: "issue_refund",
description: "Refund an order",
parameters: z.object({ order_id: z.string(), amount_eur: z.number() }),
needsApproval: createSpurvikNeedsApproval(config, { actionName: "issue_refund" }),
execute: async ({ order_id, amount_eur }) => `Refunded €${amount_eur} on ${order_id}`,
});
const agent = new Agent({ name: "ops", tools: [issueRefund] });
let result = await run(agent, "Refund order 1042 for €420");
if (result.interruptions.length > 0) {
// Only "approved" calls state.approve; "rejected" and "overridden" call state.reject.
await resolveAgentInterruptions(result.interruptions, config, { state: result.state });
result = await run(agent, result.state);
}
// approval/request.ts · signed Slack & Microsoft Teams links (no Spurvik account needed)
import { createMultiChannelApprovalRouter } from "spurvik/channels";
const router = createMultiChannelApprovalRouter({
signingSecret: process.env.SPURVIK_SIGNING_SECRET!, // >= 16 chars
channels: [
{ type: "slack", webhookUrl: process.env.SLACK_WEBHOOK_URL! },
{ type: "teams", webhookUrl: process.env.TEAMS_WEBHOOK_URL! },
],
});
await router.requestApproval({
gateId: crypto.randomUUID(),
actionName: "issue_refund",
summary: "Refund on order 1042", // sent as written: keep personal data out
context: { amountEur: 420, currency: "EUR" },
callbackBaseUrl: "https://your-app.example/api/spurvik/callback", // your own GET endpoint
});
// Your callback endpoint checks verifyChannelApprovalToken() and records the nonce.
Nessun gestore ospitato: callbackBaseUrl è obbligatorio e punta al tuo endpoint GET (verifyChannelApprovalToken + registro nonce).
# gate.py · curl -fsSLO https://spurvik.com/r/spurvik_guard.py (Python 3.10+ stdlib, 0 pip deps)
import json, os, time, urllib.request
from spurvik_guard import request_human_approval
BASE = os.environ.get("SPURVIK_BASE_URL", "https://console.spurvik.com").rstrip("/")
HEADERS = {"Authorization": f"Bearer {os.environ['SPURVIK_API_KEY']}", "Accept": "application/json"}
# Sends sorted field names only (spurvik.payload_summary.v1), never raw values.
gate = request_human_approval("issue_refund", {"order_id": "1042", "amount_eur": 420})["data"]
deadline = time.time() + 120
while gate["status"] == "pending" and time.time() < deadline:
time.sleep(2)
req = urllib.request.Request(f"{BASE}/api/v1/hitl/{gate['id']}", headers=HEADERS)
with urllib.request.urlopen(req, timeout=5) as resp:
gate = json.loads(resp.read().decode("utf-8"))["data"]
if gate["status"] == "approved":
issue_refund("1042", 420) # rejected, overridden or timeout: never runs
Free 0 € (link firmati Slack/Teams self-hosted, 10k eventi/mese) · Pro 19 €/mese (190 €/anno, coda di approvazione ospitata, 250k, 90 gg) · Team 79 €/mese (790 €/anno, 2M eventi, conservazione 12 mesi e bozza Allegato IV) · Setup 24h 199 € una tantum (include 1 anno Pro) · IVA escl. · solo B2B.
Due pattern architetturali per la sorveglianza umana (Art. 14)
Quando un agente IA può emettere rimborsi, modificare permessi, cancellare record o inviare messaggi esterni, i DPO, i CISO e l’Art. 14 del Regolamento Europeo sull’IA richiedono un blocco deterministico nel codice prima dell’esecuzione — non una semplice istruzione nel prompt.
Con spurvik@1.0.16 (MIT) puoi scegliere tra A. link Approva/Blocca firmati con HMAC-SHA256 per Slack e Microsoft Teams verificati sul tuo server senza account Spurvik, oppure B. la coda di revisione ospitata a Francoforte (fra1, da Pro 19 €/mese) che riceve esclusivamente i nomi dei campi (spurvik.payload_summary.v1, 0 byte di valori personali).
Garanzie deterministiche del gate (SDK 1.0.16)
| Meccanismo | Comportamento deterministico |
|---|---|
decision.approved | Restituisce true solo con status === "approved"; rejected, overridden e timeout fermano l’azione. |
payloadSummary (v1) | Invia solo le chiavi ordinate (es. ["amount_eur", "order_id"]), mai importi, IBAN o testo del prompt. |
spurvik/channels | Link firmati per Slack, Microsoft Teams, Discord, Telegram, Linear, Jira ed e-mail (callbackBaseUrl sul tuo dominio). |
Nonce e scadenza | Verifica a tempo costante con verifyChannelApprovalToken() (24 ore predefinite); salva il nonce per impedire il replay. |
hitlStatus a Francoforte | Ogni decisione è concatenata con SHA-256 nel registro ospitato a Francoforte (eu-central-1). |
Team · 79 €/mese | 2.000.000 di eventi/mese, conservazione 12 mesi a Francoforte, export webhook e bozza tecnica Allegato IV. |
Domande frequenti (DPO e sicurezza)
Serve un account Spurvik per i link su Slack e Teams?
No. createMultiChannelApprovalRouter e verifyChannelApprovalToken (spurvik/channels) girano interamente nel tuo codice sotto licenza MIT. La coda ospitata per LangGraph, OpenAI Agents e Python è inclusa da Pro (19 €/mese).
Cosa succede in caso di decisione overridden?
Dalla versione 1.0.7 gli helper proseguono esclusivamente su approved. Sia rejected sia overridden bloccano l’esecuzione.
Gli importi o i dati dei clienti vengono inviati alla coda ospitata?
No. Lo schema spurvik.payload_summary.v1 trasmette solo i nomi ordinati dei campi e opzionalmente un’impronta HMAC con chiave segreta.
Un link di approvazione può essere usato due volte?
Il link resta valido fino alla scadenza (24 ore per impostazione predefinita). Registra il nonce di ogni clic nel tuo database e rifiuta i riutilizzi.