AI Control & Human Handoff
Toggle AI mode, transfer to human operators, and manage conversation context
Overview
Every chat in Happ has an AI control toggle. When AI is on, the assistant automatically responds. When AI is off, the chat waits for a human operator. This gives you full control over when AI handles conversations and when humans step in.
Toggling AI Mode
From the Dashboard
- Open any chat in Chats
- Click the AI toggle button
- AI switches on or off immediately
Via API
PATCH /api/chats/{chatId}
X-Access-Token: happ_your_token_here
Content-Type: application/json
{
"isUnderAiControl": false
}See the full API reference at api.happ.tools/reference.
From Mobile App
Open any chat and use the AI control toggle.
How AI Control Works
| State | Behavior |
|---|---|
AI On (isUnderAiControl: true) | Assistant automatically responds to new messages |
AI Off (isUnderAiControl: false) | Assistant pauses. Messages appear in the dashboard for human response |
When AI is disabled, the aiDisableReason field indicates why:
| Reason | Description |
|---|---|
manual | A human operator manually disabled AI from the dashboard or API |
auto | The AI itself triggered turnOffAiMode to hand off to a human |
Human Handoff (Transfer to Operator)
The AI can automatically transfer a conversation to a human when it determines it can't help.
How It Works
- The built-in
turnOffAiModetool is always available to your assistant - When the AI decides human help is needed, it calls this tool
isUnderAiControlis set tofalse- The chat appears in the dashboard as needing human attention
- A
CHAT_MODE_CHANGEDWebSocket event notifies all connected clients in real-time
Getting Notified
To get instant notifications when AI hands off a conversation:
- Set up Telegram Push Notifications
- When the AI disables itself, your team's Telegram group receives a notification
- A team member can respond from the dashboard or mobile app
Guiding the AI to Hand Off
Include instructions in your assistant's prompt:
If the customer asks to speak to a human, or if you cannot resolve
their issue after 2 attempts, use the turnOffAiMode tool to transfer
the conversation to a human operator. Tell the customer that a team
member will respond shortly.Auto-Resume AI
After AI hands off a conversation (via turnOffAiMode), the system automatically re-enables AI after approximately 10 minutes of inactivity.
How It Works
- A cron job runs every minute
- It finds messages older than 10 minutes that haven't been archived
- These messages are moved to a context archive (assigned a
contextId) - If the chat was auto-disabled (reason =
auto), AI mode is re-enabled - The conversation gets a fresh context — the AI starts a new interaction without the old messages
Why This Exists
This prevents conversations from being "stuck" in manual mode. If a human doesn't respond, the AI picks back up with a clean slate.
Manually Disabled Chats
If AI was disabled manually (reason = manual), auto-resume does NOT apply. The human must explicitly re-enable AI.
Conversation Context Window
The AI doesn't see the entire chat history forever. Messages older than 10 minutes are archived and excluded from the AI's context.
What This Means
- The AI "remembers" only the recent conversation (last ~10 minutes of messages)
- Older messages are preserved in the database but not sent to the AI model
- This keeps the AI focused and prevents token overflow for long conversations
Practical Impact
- Short conversations (under 10 min): The AI sees everything
- Long conversations: The AI may not remember details from earlier in the chat
- Returning customers: If a customer comes back after a pause, the AI treats it as a fresh conversation
Transferring Between Assistants
You can transfer a chat to a different assistant:
PATCH /api/chats/{chatId}
X-Access-Token: happ_your_token_here
Content-Type: application/json
{
"assistantId": "new-assistant-uuid"
}The new assistant continues the conversation from the latest message. All message history is preserved.
Message Debouncing
When a customer sends multiple messages quickly (e.g., in a Telegram chat), Happ batches them:
- 4-second debounce: Waits 4 seconds after each message for more
- 7-second maximum: After 7 seconds, processes what's been received
- Only the last message in a burst triggers the AI response
This prevents redundant AI calls and ensures the assistant sees the customer's full thought before responding.
WebSocket Events
Real-time events are broadcast when AI mode changes:
{
"type": "CHAT_MODE_CHANGED",
"payload": {
"chatId": "uuid",
"isUnderAiControl": false,
"aiDisableReason": "auto"
}
}Connect to wss://api.happ.tools/ws for real-time updates.