Skip to main content

HITL Service

Port 4006. Manages operator oversight of AI agent conversations.

Endpoints

Architecture

Redis Pub/Sub Channels

WebSocket Events

All WS broadcasts use the event key (not type).

Key Services

Database Tables

  • escalation_requests — Escalation lifecycle (7 statuses: pending → queued → assigned → active → resolved/expired)
  • operator_sessions — Operator availability, load, agent scope, working hours
  • escalation_events — Append-only audit log
  • approval_queue — Response approval workflow
  • notification_channels — Multi-channel notification config
  • escalation_notes — Internal operator notes

Concurrency

All claim and approval operations use atomic UPDATE ... WHERE status IN (...) RETURNING * to prevent TOCTOU race conditions. If two operators claim simultaneously, only one succeeds.

Bot Service Integration

The bot service connects via hitl-bridge.service.ts:
  • Subscribes to hitl:resolution:*, hitl:message:*, hitl:approved:*
  • Escalation tool (escalate-to-human.ts) has 4 lifecycle hooks: preResponse, postResponse, onToolCall, promptInjection
  • Escalation requests are synchronous — bot waits up to 5s for assignment result to customize user messages
  • All user-facing messages are configurable per-agent via tool config

Environment Variables

  • HITL_SERVICE_PORT (default: 4006)
  • DATABASE_URL
  • REDIS_HOST, REDIS_PORT, REDIS_PASSWORD
  • LOG_LEVEL