Human-in-the-Loop — Escalation Infrastructure for Autonomous Agents
This document describes the architecture powering the Human-in-the-Loop (HITL) system — webhook-based approval workflows delivered via Telegram, designed for autonomous agent systems that need human oversight at critical decision points.
The HITL system operates as a lightweight middleware layer between autonomous agents and human reviewers. When an agent encounters a decision that exceeds its confidence threshold or requires external authorisation, it sends an escalation request via webhook. The system routes this request to the appropriate human reviewer through Telegram, captures the response, and returns it to the calling agent.
Accepts POST requests from autonomous agents containing escalation payloads. Each request includes: agent ID, confidence score, context data, proposed action, and required reviewer role. Requests are validated against a schema and queued for processing.
Determines which human reviewer should handle each escalation based on:
Delivers escalation notifications to human reviewers via a dedicated Telegram bot. The bot presents structured approval cards with action buttons (Approve / Reject / Request Info). Reviewers can respond inline without leaving Telegram.
All escalations, decisions, and metadata are recorded in PostgreSQL for compliance, debugging, and performance analysis. Each record includes timestamps, reviewer identity, decision rationale, and response latency.
The HITL system is configured via environment variables or a hitl.json configuration file:
{
"telegram_token": "your_bot_token",
"reviewers": {
"operations": ["@user1", "@user2"],
"compliance": ["@user3"]
},
"timeout_seconds": 300,
"fallback_action": "reject",
"pg_connection": "postgresql://..."
}
The HITL middleware can be deployed as a standalone Node.js service or as a serverless function on Vercel. The Telegram bot component runs as a persistent process with webhook polling.
For more details, visit the main HITL product page.