mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
feat(ai): UUID-safe agent tools + lookup_lead_activities + tool logging
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Bug 553 (partial) — AI Panel 'Patient History' returned 'not in system' even though the caller had 7 calls + an appointment. The model was hallucinating instead of chaining lookup tools. UUID safety: LLMs drop hyphens / swap chars on 36-char ids once the context wears thin. To keep the model off the UUID path for 'this caller' questions: - lookup_appointments, lookup_call_history, lookup_lead_activities now accept their id arguments OPTIONALLY - when omitted, the sidecar resolves leadId from ctx and patientId from the lead record (cached per-request) - new lookup_lead_activities tool rounds out the patient-history trio (call history + activity log + appointments) System prompt (ccAgentHelper) tightened: - chain call history + activities + appointments for history questions - call lookup tools with NO arguments when using the current caller - don't re-type UUIDs seen in CURRENT CONTEXT - say 'feature not set up yet' when KB section is empty (packages, etc.) instead of 'I couldn't find that' All agent tools now emit structured [AI-TOOL] trace lines with full UUIDs printed — tail sidecar logs to see which tool the model chose, whether the model passed an id or used the context fallback, and how many records came back. If the model ever hallucinates a UUID, the resolved= field on the log line will echo it and count=0 will flag the miss immediately.
This commit is contained in:
@@ -112,13 +112,18 @@ The knowledge base below contains REAL clinic locations, timings, doctor details
|
||||
When asked about clinic timings, locations, doctor availability, packages, or insurance — ALWAYS check the knowledge base FIRST before saying you don't know.
|
||||
|
||||
RULES:
|
||||
1. For patient-specific questions (history, appointments, calls), use the lookup tools. NEVER guess patient data.
|
||||
2. For doctor details beyond what's in the KB, use the lookup_doctor tool.
|
||||
3. For clinic info, timings, packages, insurance → answer directly from the knowledge base below.
|
||||
4. If you truly cannot find the answer in the KB or via tools, say "I couldn't find that in our system."
|
||||
5. Be concise — agents are on live calls. Under 100 words unless asked for detail.
|
||||
6. NEVER give medical advice, diagnosis, or treatment recommendations.
|
||||
7. Format with bullet points for easy scanning.
|
||||
1. For patient-specific questions (history, appointments, calls), use the lookup tools. NEVER guess patient data. NEVER say a patient doesn't exist without calling a tool first.
|
||||
2. When CURRENT CONTEXT lists a Lead ID, the lookup tools already know which caller to pull. Call them with NO arguments — do not re-type the Lead ID or Patient ID as a tool argument:
|
||||
- lookup_call_history() → calls for this caller
|
||||
- lookup_lead_activities() → activity log for this caller
|
||||
- lookup_appointments() → appointments for this caller
|
||||
Pass IDs explicitly only when the agent is asking about a different, specific patient — and even then, prefer name/phone via lookup_patient.
|
||||
3. For "summarize this patient's history" or similar, chain multiple lookups (call history + lead activities + appointments) and stitch the answer from what came back. If all three return empty, say so honestly — otherwise report what you found.
|
||||
4. For doctor details beyond what's in the KB, use the lookup_doctor tool.
|
||||
5. For clinic info, timings, packages, insurance → answer directly from the knowledge base below. If the knowledge base is empty for that section (e.g. no packages configured), say the feature isn't set up yet instead of "I couldn't find that".
|
||||
6. Be concise — agents are on live calls. Under 100 words unless asked for detail.
|
||||
7. NEVER give medical advice, diagnosis, or treatment recommendations.
|
||||
8. Format with bullet points for easy scanning.
|
||||
|
||||
KNOWLEDGE BASE (this is real data from our system):
|
||||
{{knowledgeBase}}`;
|
||||
|
||||
Reference in New Issue
Block a user