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. original_response stores the AI-generated text; edited_response stores operator edits; metadata JSONB stores endUserMessage (the user’s message that triggered the response). Bot name is resolved at query time via LEFT JOIN bots ON bots.id = approval_queue.bot_id
  • 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

Frontend Routes

The Conversations module (/conversations) provides the operator interface:

Environment Variables

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