Files
helix-engage-server/src/caller/caller-resolution.controller.ts
saridsa2 a576552f8a feat: pre-fetched caller context replaces tool-based patient lookups
- CallerContextService: fetches lead profile, appointments, call history,
  activities in parallel. Caches in Redis (5 min TTL). Renders as
  human-readable KB section — no UUIDs exposed to the LLM.
- Caller resolution controller: prewarms context cache on resolve
  (fire-and-forget) so the AI stream has a cache hit.
- AI chat stream: injects caller context into system prompt KB instead
  of raw Lead ID. LLM answers patient questions from context, no tool
  calls needed for current caller data.
- Eliminates UUID hallucination: LLM never sees leadId or patientId,
  can't pass wrong ID to wrong tool parameter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:56:18 +05:30

37 lines
1.2 KiB
TypeScript

import { Controller, Post, Body, Headers, HttpException, HttpStatus, Logger } from '@nestjs/common';
import { CallerResolutionService } from './caller-resolution.service';
import { CallerContextService } from './caller-context.service';
@Controller('api/caller')
export class CallerResolutionController {
private readonly logger = new Logger(CallerResolutionController.name);
constructor(
private readonly resolution: CallerResolutionService,
private readonly callerContext: CallerContextService,
) {}
@Post('resolve')
async resolve(
@Body('phone') phone: string,
@Headers('authorization') auth: string,
) {
if (!phone) {
throw new HttpException('phone is required', HttpStatus.BAD_REQUEST);
}
if (!auth) {
throw new HttpException('Authorization header required', HttpStatus.UNAUTHORIZED);
}
this.logger.log(`[RESOLVE] Resolving caller: ${phone}`);
const result = await this.resolution.resolve(phone, auth);
// Pre-warm caller context cache so the AI chat has it ready
if (result.leadId) {
this.callerContext.prewarm(result.leadId, result.patientId, auth);
}
return result;
}
}