Skip to content
hitl-approval logo

Human-in-the-Loop Approval

hitl-approval

Implement human-in-the-loop approval flows. Use when adding Slack approvals, dashboard review queues, action gating, or trust-based auto-approval.

SKILL.md

Full skill instructions

Human-in-the-Loop Approval

Core differentiator: agent proposes, human approves. Every sensitive action requires human approval until trust is established.

Architecture Overview

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│  Agent Tool     │ ──▶ │ requestApproval  │ ──▶ │  Slack Message  │
│  proposes       │     │ workflow         │     │  with buttons   │
└─────────────────┘     └──────────────────┘     └─────────────────┘
                                                          │
                                                          ▼
┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│  Action         │ ◀── │ executeApproved  │ ◀── │  Interactions   │
│  executed       │     │ Action workflow  │     │  handler        │
└─────────────────┘     └──────────────────┘     └─────────────────┘

Approval Surfaces

SurfaceUse CaseCapabilities
SlackReal-time push notificationsApprove/​reject buttons, rejection reason modal
DashboardBulk review, audit trailQueue view, search, bulk actions
Front PluginIn-context approvalView customer data, quick actions

Inngest Events

EventTriggerData
support/​approval.requestedAgent proposes actionactionId, conversationId, appId, action, agentReasoning
support/​approval.decidedHuman clicks buttonactionId, decision, decidedBy, decidedAt
support/​action.approvedHuman approvesactionId, approvedBy, approvedAt
support/​action.rejectedHuman rejectsactionId, rejectedBy, rejectedAt, reason?

IMPORTANT: The waitForEvent match uses data.actionId - ensure all events use actionId consistently (not approvalId).

Slack Block Kit Builder

Build approval messages with buildApprovalBlocks:

import { buildApprovalBlocks } from '@skillrecordings/​core/​slack/​approval-blocks'

const blocks = buildApprovalBlocks({
  actionId: 'action-123',
  conversationId: 'conv-456',
  appId: 'total-typescript',
  actionType: 'issue_refund',
  parameters: { orderId: 'order-789', amount: 99.00 },
  agentReasoning: 'Customer within 30-day refund window',
})
// Returns: header, reasoning section, parameters, approve/​reject buttons

Button metadata structure (embedded in value):

{ actionId, conversationId, appId }

Slack Client (Lazy Init)

import { postApprovalMessage, updateApprovalMessage } from '@skillrecordings/​core/​slack/​client'

// Post approval message to channel
const { ts, channel } = await postApprovalMessage(
  process.env.SLACK_APPROVAL_CHANNEL,
  blocks,
  'Approval needed for Issue Refund'
)

// Update message after decision
await updateApprovalMessage(channel, ts, updatedBlocks, 'Approved')

Slack Interactions Handler (Next.js App Router)

// apps/​slack/​app/​api/​slack/​interactions/​route.ts
import { verifySlackSignature } from '../​../​../​../​lib/​verify-signature'
import { inngest, SUPPORT_APPROVAL_DECIDED, SUPPORT_ACTION_APPROVED } from '@skillrecordings/​core/​inngest'

export async function POST(request: Request) {
  const body = await request.text()
  const signature = request.headers.get('x-slack-signature') ?? ''
  const timestamp = request.headers.get('x-slack-request-timestamp') ?? ''

  // Verify signature (HMAC-SHA256, 5-min replay protection)
  if (!verifySlackSignature({ signature, timestamp, body })) {
    return new Response('Invalid signature', { status: 401 })
  }

  // Parse URL-encoded payload
  const params = new URLSearchParams(body)
  const payload = JSON.parse(params.get('payload') ?? '{}')

  if (payload.type === 'block_actions') {
    const action = payload.actions[0]
    const metadata = JSON.parse(action.value)

    if (action.action_id === 'approve_action') {
      await inngest.send([
        { name: SUPPORT_APPROVAL_DECIDED, data: { approvalId: metadata.actionId, decision: 'approved', ... } },
        { name: SUPPORT_ACTION_APPROVED, data: { actionId: metadata.actionId, ... } },
      ])
    }
  }

  return new Response('OK', { status: 200 }) // Slack requires quick 200
}

Signature Verification

import { verifySlackSignature } from 'apps/​slack/​lib/​verify-signature'

// Returns true if valid, false if invalid/​expired
// Throws if SLACK_SIGNING_SECRET missing
const isValid = verifySlackSignature({
  signature: request.headers.get('x-slack-signature'),
  timestamp: request.headers.get('x-slack-request-timestamp'),
  body: rawRequestBody,
  // secret defaults to process.env.SLACK_SIGNING_SECRET
})

Key features:

  • HMAC-SHA256 with timing-safe comparison (prevents timing attacks)
  • 5-minute replay protection
  • Validates v0= signature prefix

Authority Levels

// AUTO-APPROVE (execute immediately)
- Magic link requests
- Password reset requests
- Refunds within 30 days of purchase
- Transfers within 14 days of purchase
- Email/​name updates

// REQUIRE-APPROVAL (draft action, wait for human)
- Refunds 30-45 days after purchase
- Transfers after 14 days
- Bulk seat management
- Account deletions

// ALWAYS-ESCALATE (flag for human, do not act)
- Angry/​frustrated customers (sentiment detection)
- Legal language (lawsuit, lawyer, etc.)
- Repeated failed interactions
- Anything uncertain

Draft Comparison (HITL Scoring)

Track how much humans modify agent drafts to build trust:

function diffScore(draft: string, sent: string): 'unmodified' | 'edited' | 'rewritten' {
  const draftTokens = new Set(tokenize(draft))
  const sentTokens = new Set(tokenize(sent))
  const intersection = [...draftTokens].filter(t => sentTokens.has(t))
  const overlap = intersection.length / Math.max(draftTokens.size, sentTokens.size)

  if (overlap > 0.95) return 'unmodified'  // Trust++
  if (overlap > 0.50) return 'edited'       // Trust neutral
  return 'rewritten'                         // Trust--
}

Trust Decay

Trust score uses exponential decay with 30-day half-life. High-trust agents can auto-send drafts.

File Locations

FilePurpose
packages/​core/​src/​slack/​approval-blocks.tsBlock Kit message builder
packages/​core/​src/​slack/​client.tsSlack WebClient singleton (lazy init)
packages/​core/​src/​inngest/​workflows/​request-approval.tsApproval request workflow
packages/​core/​src/​inngest/​workflows/​execute-approved-action.tsExecute after approval
apps/​slack/​app/​api/​slack/​interactions/​route.tsButton click handler
apps/​slack/​lib/​verify-signature.tsHMAC signature verification
packages/​database/​src/​schema.tsApprovalRequestsTable, ActionsTable

Environment Variables

VariablePurpose
SLACK_BOT_TOKENSlack WebClient authentication
SLACK_SIGNING_SECRETRequest signature verification
SLACK_APPROVAL_CHANNELChannel ID for posting approvals

Reference Docs

For full details, see:

  • docs/​support-app-prd/​66-hitl.md

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View