feat/chatbot context handoff - #61
Conversation
XuanHanTan-School
commented
Jan 30, 2026
…text to support agent when scheduling call
There was a problem hiding this comment.
Pull request overview
This pull request implements AI context handoff functionality for chatbot escalations to human support agents. When the AI chatbot needs to escalate a customer issue to a human agent, it now captures and passes along three key pieces of context that are invisible to the customer but critical for the support agent.
Changes:
- Added three new nullable database fields to
call_bookingstable:aiSolutionsSummary,escalationReason, andconversationContext - Updated backend types, validation schemas, and execution logic to handle the new AI context fields throughout the data flow
- Modified AI system prompts to instruct the model to provide context when scheduling calls
- Enhanced the admin UI to display AI context information in the call details panel
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
8cbc_backend/drizzle/0017_next_whirlwind.sql |
Database migration adding three new text columns for AI context |
8cbc_backend/drizzle/meta/0017_snapshot.json |
Drizzle snapshot reflecting the new database schema |
8cbc_backend/database/schema.ts |
Schema definition for the three AI context fields in call_bookings table |
shared/types/confirmation.types.ts |
TypeScript interfaces updated to include AI context fields for call scheduling |
shared/types/api.types.ts |
CallBooking interface extended with AI context fields |
8cbc_backend/controllers/calls/calls.controller.ts |
Validation schema updated to accept AI context fields in booking requests |
8cbc_backend/services/langchain/tools/call.tools.ts |
LangChain tool schema extended with AI context parameters |
8cbc_backend/services/langchain/system-prompt.ts |
System prompt updated with instructions for providing AI context during escalations |
8cbc_backend/services/realtime/realtime.config.ts |
Voice assistant instructions updated for AI context handoff |
8cbc_backend/services/langchain/modal.types.ts |
Zod validation schema for schedule call operation includes AI context |
8cbc_backend/services/langchain/execution/operations.ts |
Booking creation logic updated to persist AI context fields |
8cbc_frontend/contexts/ChatbotContext.tsx |
Chat context passes AI context fields from AI responses to backend |
8cbc_frontend/components/voice/voice-overlay.tsx |
Voice overlay passes AI context fields to backend |
8cbc_frontend/components/ui/modals/schedule-call/schedule-call-modal.tsx |
Schedule call modal receives and passes through AI context fields |
8cbc_frontend/components/bookings/CallDetailsPanel.tsx |
UI component displays AI context information with Bot icon for support agents |
8cbc_frontend/app/(admin)/admin/page.tsx |
Minor unrelated whitespace fix and title clarification |
8cbc_frontend/bun.lock |
Bun lockfile update with configVersion field |
8cbc_backend/bun.lock |
Bun lockfile update with configVersion field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Specific amounts, dates, or reference numbers | ||
| - User's main concern or complaint in their words | ||
| - Any urgency indicators | ||
| - Example: "User concerned about 3 unauthorized transactions totaling $450 on 2024-01-15. Transaction IDs: TXN-123, TXN-124, TXN-125. Card ending 4532. User noticed charges this morning, card is still in possession." |
There was a problem hiding this comment.
The example date "2024-01-15" should be updated to use a date from 2026, as we are currently in 2026. Using an outdated year in the example could confuse the AI model or make the examples less relatable.
| - Example: "User concerned about 3 unauthorized transactions totaling $450 on 2024-01-15. Transaction IDs: TXN-123, TXN-124, TXN-125. Card ending 4532. User noticed charges this morning, card is still in possession." | |
| - Example: "User concerned about 3 unauthorized transactions totaling $450 on 2026-01-15. Transaction IDs: TXN-123, TXN-124, TXN-125. Card ending 4532. User noticed charges this morning, card is still in possession." |
| ### AI Context Handoff (REQUIRED when escalating) | ||
|
|
||
| When using schedule_call, you MUST provide context to help the human agent understand the situation. These fields are invisible to the customer but critical for efficient support: | ||
|
|
||
| 1. **aiSolutionsSummary** (REQUIRED): Summarize what you tried before escalating: | ||
| - Tools used (e.g., "Searched knowledge base for 'card replacement', checked account status") | ||
| - Information retrieved and shared with user | ||
| - Answers or partial solutions provided | ||
| - Example: "Searched knowledge base for fraud dispute process. Provided user with general dispute timeline. Could not find specific policy for international transactions." | ||
|
|
||
| 2. **escalationReason** (REQUIRED): Explain why you couldn't resolve this: | ||
| - What specific capability or information is missing | ||
| - Why human judgment is needed | ||
| - Examples: "Requires manual identity verification", "Policy exception needed for transaction over limit", "User reports unauthorized access - needs security team review", "Complex dispute requiring account investigation" | ||
|
|
||
| 3. **conversationContext** (REQUIRED): Include key details the agent needs: | ||
| - Relevant account numbers or transaction IDs mentioned | ||
| - Specific amounts, dates, or reference numbers | ||
| - User's main concern or complaint in their words | ||
| - Any urgency indicators | ||
| - Example: "User concerned about 3 unauthorized transactions totaling $450 on 2024-01-15. Transaction IDs: TXN-123, TXN-124, TXN-125. Card ending 4532. User noticed charges this morning, card is still in possession." | ||
|
|
There was a problem hiding this comment.
There's a discrepancy between the system prompt documentation and the schema implementation. The system prompt states these fields are "REQUIRED" (lines 329, 335, 340) with instructions like "you MUST provide context" (line 327), but the Zod schema defines all three fields (aiSolutionsSummary, escalationReason, conversationContext) as optional() at lines 137-154 in call.tools.ts. This could lead to inconsistent behavior where the AI might not always provide these fields despite the prompt strongly indicating they are mandatory. Consider either making these fields required in the schema, or adjusting the prompt language to say "STRONGLY RECOMMENDED" instead of "REQUIRED" to match the optional schema.