AI Agent with Human Escalation
The AI handles the conversation but can escalate to a human agent when it detects it cannot help, with full context handoff.
Overview
This use case demonstrates:
- AI-first handling with continuous conversation
- Intelligent escalation detection
- Saving full conversation context to a database for the human agent
- Seamless handoff via
connect()andclose()
State flow: PENDING -> ANSWERED -> CONNECTED -> DISCONNECTED
Example
How It Works
- The AI answers the call and begins a normal conversation
- Each turn is transcribed and added to a running conversation summary
- After each AI response, the model evaluates whether it should escalate (e.g., the caller is frustrated, the request is outside the AI’s capabilities, or the caller explicitly asks for a human)
- If escalation is triggered:
- The full conversation summary is saved to a database, keyed by
call.call_id - The caller hears a brief transition message
- The call is connected to the original callee using
connect(), then the agent leaves withclose()
- The full conversation summary is saved to a database, keyed by
- The human agent can retrieve the conversation context from the database to continue seamlessly
- If the AI handles the call successfully, it ends the call with
disconnect()
Key Commands Used
answer()- Answer the incoming callaudio_stream()- Receive caller audiosend_audio()- Play AI responsesconnect()- Connect to the original calleeclose()- Leave the call after connecting the caller to the calleedisconnect()- End the call when the AI fully handled it
Related
- AI Receptionist with Database Lookup - Route based on caller identity
- Call Monitoring and Coaching - Human-AI collaboration during calls
