Skip to content

Agent Pipeline Gaps — Identified 2026-04-02

Status: Most gaps resolved on branch feat/ehr-sync-rebuild-reliability (2026-04-04)

The agent conversation quality is significantly improved (asks for medications, allergies, dosages, budget, timeline, preferences). But the data pipeline had gaps where extracted information didn't flow through to the EHR and matching. 5 of 6 gaps are now fixed.


Critical Pipeline Issues

1. Demographics not flowing to patient record — ✅ FIXED

  • Symptom: Patient Information "Not yet collected" in EHR panel
  • Root cause: Clinical extraction prompt now asks for demographics (name, age, gender) from PDF headers, but the extracted demographics object wasn't read by the orchestrator or saved to the patient record
  • Resolution: OCR pipeline now saves demographics to patient record. Chat-provided demographics take precedence over PDF-extracted ones via EHR rebuild service.
  • Location: app/services/ehr_rebuild_service.py, app/agents/case_orchestrator.py

2. Medications from chat not persisting — ✅ FIXED

  • Symptom: Medications "None recorded" despite patient saying "Metformin, Thyronorm, Aspirin"
  • Root cause: The Python attribute case.extra_metadata maps to column metadata in PostgreSQL. Column name mismatch between local and production.
  • Resolution: Chat extractor captures medications on every turn. EHR rebuild service runs at every write point, ensuring medications from extra_metadata flow into EHR medical_history.medications.
  • Location: app/services/chat_extractor.py, app/services/ehr_rebuild_service.py

3. Matching not triggered after conversation — ✅ FIXED

  • Symptom: Agent says "Let me find providers" but nothing happens
  • Root cause: Matching gate was too strict (ehr_completeness >= 0.4 AND medications_asked). Medication save failures prevented the gate from opening.
  • Resolution: Gate relaxed to 50% EHR completeness. Error handling improved around matching to provide graceful fallback instead of crash.
  • Location: app/agents/case_orchestrator.py lines 220-230

4. Document cards showing "Issues" instead of "Provided" — ✅ FIXED

  • Symptom: CBC, Metabolic Panel etc. show amber "Issues" badge with warning text
  • Root cause: Document-level validation issues were overriding per-requirement LLM match status.
  • Resolution: Parameter matching now works for all lab types (CBC, Metabolic Panel, HbA1c, etc.). Per-requirement status uses LLM match confidence, not document-level validation.
  • Location: app/routers/cases.py, app/services/requirement_matcher.py

5. Agent asks for info already in the report — PARTIALLY FIXED

  • Symptom: Asks for HbA1c (5.8% is in the blood work), asks for age/gender (may be in PDF header)
  • Root cause: The LLM generating the conversation doesn't have the full observation list in its context.
  • Resolution: Chat extractor now captures data from conversation, and EHR rebuild includes it. However, the full observation list from documents is still not fully included in agent context — context window is limited.
  • Location: app/agents/case_orchestrator.py patient_context construction

6. Progress tracker stale — ✅ FIXED

  • Symptom: Shows "0 mandatory analyzed" + "Complete" — contradictory
  • Root cause: Progress tracker reads workflow_state which only updates on phase transitions.
  • Resolution: Progress tracker now shows partial status for low completeness instead of contradictory "Complete". Uses actual checklist data for document counts.
  • Location: Frontend src/components/ProgressStrip.tsx

What's Working Well

  • Agent asks for medications, allergies, dosages ✅
  • Agent asks about smoking, alcohol, supplements ✅
  • Agent collects budget, timeline, country preferences ✅
  • 9 conditions extracted with ICD-10 codes ✅
  • 4 comorbidities auto-detected ✅
  • HbA1c context-aware follow-up (asks about levels for diabetes management) ✅
  • Agent doesn't advance prematurely — asks 8 questions before matching ✅
  • LLM requirement matcher matches 4-5/6 lab requirements ✅

Remaining Work

  1. Agent context enrichment — Include full observation list from documents in agent context to prevent redundant questions. Currently partially fixed (chat extractor captures, but document observations are summarized). (~2h)

Completed Sprint Items

  1. Fix medication persistence (column name alignment) — ✅ FIXED via EHR rebuild service
  2. Demographics from PDF to patient record — ✅ FIXED, chat takes precedence
  3. Matching trigger + progress display — ✅ FIXED, gate relaxed to 50%
  4. Document card status (LLM match → green) — ✅ FIXED, parameter matching for all lab types
  5. Include key lab values in agent context — PARTIALLY FIXED
  6. Progress tracker sync with real data — ✅ FIXED, partial status for low completeness