feat: structured JSON output + suggestion rules in AI system prompt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 11:11:13 +05:30
parent 2d18110786
commit e03b1e6235
2 changed files with 17 additions and 0 deletions

View File

@@ -105,6 +105,9 @@ export class AiChatController {
const callerCtx = await this.callerContext.getOrBuild(ctx.leadId, '', auth); const callerCtx = await this.callerContext.getOrBuild(ctx.leadId, '', auth);
if (callerCtx) { if (callerCtx) {
systemPrompt += `\n\n${this.callerContext.renderForPrompt(callerCtx)}`; systemPrompt += `\n\n${this.callerContext.renderForPrompt(callerCtx)}`;
if (callerCtx.suggestionTriggers?.length) {
systemPrompt += this.callerContext.renderSuggestionsForPrompt(callerCtx.suggestionTriggers);
}
} }
} else if (ctx?.callerPhone) { } else if (ctx?.callerPhone) {
systemPrompt += `\n\nCURRENT CONTEXT:\nCaller phone: ${ctx.callerPhone}\nNew caller — no prior records.`; systemPrompt += `\n\nCURRENT CONTEXT:\nCaller phone: ${ctx.callerPhone}\nNew caller — no prior records.`;

View File

@@ -125,6 +125,20 @@ RULES:
7. NEVER give medical advice, diagnosis, or treatment recommendations. 7. NEVER give medical advice, diagnosis, or treatment recommendations.
8. Format with bullet points for easy scanning. 8. Format with bullet points for easy scanning.
RESPONSE FORMAT (STRICT):
You MUST respond with valid JSON in this exact format — no markdown fences, no extra text, just raw JSON:
{"message": "your response text here", "suggestions": [{"id": "s1", "type": "upsell", "title": "short title", "script": "2-3 sentence script the agent reads aloud", "priority": "high"}]}
Response format rules:
- "message" contains your conversational response to the agent. Use plain text, no markdown.
- "suggestions" contains 0-4 contextual suggestions based on the SUGGESTION RULES section below (if present).
- Each suggestion needs a personalized "script" using the caller's name, doctor, department from the context.
- type must be one of: upsell, crosssell, retention, operational
- priority must be one of: high, medium, low
- On the first response (patient summary), always include suggestions from the rules.
- On subsequent responses, update suggestions based on conversation — remove acted-on ones, add new if relevant.
- If no suggestion rules are provided, return an empty suggestions array.
KNOWLEDGE BASE (this is real data from our system): KNOWLEDGE BASE (this is real data from our system):
{{knowledgeBase}}`; {{knowledgeBase}}`;