Prompt
How do I add chat that can hand off from bot to human?
Latest observation
Nov 1, 2026
OpenAI APIWeb search: off
To add chat with bot-to-human handoff, you usually build it as a single conversation system with a routing layer:
1) Create a shared conversation thread
Store all messages in one conversation ID so both bot and human can see the same history.
Typical fields:
conversation_iduser_idmessages[]assigned_agent_idormode(bot,human,hybrid)status(open,waiting_human,in_human_chat,closed)
2) Add a “handoff” trigger
The bot should decide when to escalate, for example when:
- user says “agent”, “human”, “representative”
- bot confidence is low
- user asks something outside bot scope
- user is angry / frustrated
- payment, account, or sensitive issue appears
You can implement:
- rule-based escalation
- confidence threshold
- LLM function/tool call like
handoff_to_human
3) Switch the conversation mode
When escalation happens:
- set
mode = human - assign the conversation to an available agent
- notify the agent queue
- tell the user:
“I’m connecting you to a human agent now. Please hold on.”
During human mode:
- the bot stops replying automatically
- human agent messages are sent into the same conversation thread
4) Build an agent inbox
Agents need a dashboard to:
- see incoming handoff requests
- claim or accept chats
- read full conversation history
- send messages
- mark resolved / close case
5) Let the bot resume when appropriate
After the human resolves the issue, optionally switch back:
mode = bot- or keep
mode = humanuntil the agent closes it
Some systems also allow the bot to assist the human privately with suggestions.
Simple architecture
Client UI
- chat widget
- shows bot and human messages the same way
Backend
- message service
- routing service
- handoff logic
- agent assignment
AI layer
- intent detection
- confidence scoring
- suggested reply generation
Human agent service
- inbox
- live chat
- case management
Example flow
- User: “I can’t log in.”
- Bot asks a few questions and suggests password reset.
- User: “That didn’t work. I need a person.”
- System triggers handoff.
- Backend assigns available agent.
- User sees “Connecting you to a human…”
- Agent continues in same thread.
If you’re implementing it with an LLM
Use tool/function calling like:
answer_userask_clarifying_questionhandoff_to_human
Example logic:
- If answer confidence < threshold, call
handoff_to_human - Otherwise respond normally
Important design tips
- Keep the full transcript visible to the agent
- Preserve context across handoff
- Track status carefully to avoid bot and human replying at once
- Add fallback if no agent is available:
- queue user
- collect contact info
- offer callback/email
Minimal state machine
bot_activehandoff_pendinghuman_activeclosed
If you want, I can also give you:
- a database schema
- a sample API design
- a React + Node implementation example
- a Twilio/Intercom-style architecture