- Agentic workflow built using LangGraph
- Planner and Replanner based execution
- Clinical information extraction from discharge documents
- Medication reconciliation support
- Conflict detection and safety validation
- Persistent feedback memory and learning loop
- Traceable execution through observability logs
- Structured discharge summary generation
- Human-review-aware architecture
- Modular and extensible design
This project is an Agentic AI system designed to automatically generate structured discharge summaries from clinical discharge documents.
The system combines document ingestion, clinical information extraction, planning, medication reconciliation, conflict detection, safety validation, feedback-driven learning, and final discharge summary generation using a multi-node LangGraph workflow.
Unlike a traditional linear pipeline, this solution uses an agentic architecture with planning and replanning capabilities, allowing the system to dynamically decide which actions should be executed before generating the final discharge summary.
Discharge summaries are critical clinical documents that communicate a patient's hospitalization details, diagnoses, medications, follow-up plans, pending investigations, and discharge instructions.
Manual preparation can be:
- Time-consuming
- Error-prone
- Inconsistent across providers
- Vulnerable to missing safety information
This project aims to automate discharge summary generation while maintaining safety, traceability, explainability, and clinician oversight.
- Accepts discharge summary PDFs
- Extracts raw clinical text
- Prepares structured content for downstream processing
Extracts:
- Diagnoses
- Past Medical History
- Allergies
- Procedures
- Hospital Course
- Admission Date
- Discharge Date
- Discharge Condition
- Admission Medications
- Discharge Medications
- Follow-Up Instructions
- Pending Results
The Planner Node determines the next action based on extracted information.
Example decisions:
- Run medication reconciliation
- Trigger safety review
- Proceed directly to summary generation
Compares admission and discharge medication lists.
Identifies:
- Started medications
- Stopped medications
- Continued medications
This helps detect medication-related risks during transitions of care.
Detects clinical inconsistencies such as:
- Diagnosis present without expected medication coverage
- Pending investigation results requiring follow-up
Conflicts are escalated for review before final summary generation.
After conflict detection, the agent performs a second planning pass.
The Replanner:
- Reviews detected conflicts
- Reviews escalation flags
- Chooses the next execution path
This creates a true:
Plan → Execute → Observe → Re-Plan
workflow.
Safety validation checks for:
- Missing diagnoses
- Missing follow-up instructions
- Pending investigations
- Other clinically relevant review conditions
Safety findings are incorporated into the final summary.
The system supports persistent reviewer feedback.
Workflow:
Reviewer Feedback
↓
Persistent Storage
↓
Feedback Retrieval
↓
Prompt Conditioning
↓
Improved Future Summaries
Feedback is stored in:
feedback/corrections.json
Example:
{
"error_type": "missing_pending_results",
"correction": "Always prominently highlight pending urine culture follow-up."
}Future summaries automatically load and apply relevant corrections.
START
│
▼
Ingestion Node
│
▼
Extraction Node
│
▼
Planner Node
│
▼
Medication Reconciliation Node
│
▼
Conflict Detection Node
│
▼
Replanner Node
│
▼
Safety Node
│
▼
Feedback Node
│
▼
Summary Node
│
▼
END
PDF
↓
Text Extraction
↓
Clinical Information Extraction
↓
Planning
↓
Medication Reconciliation
↓
Conflict Detection
↓
Replanning
↓
Safety Validation
↓
Feedback Memory Retrieval
↓
Discharge Summary Generation
↓
Final Output
The system maintains a centralized AgentState containing:
- Clinical information
- Medication data
- Safety flags
- Conflicts
- Feedback history
- Trace logs
- Routing decisions
This allows all nodes to communicate through a shared state object.
The system records execution traces throughout the workflow.
Example:
Ingestion completed
Clinical extraction completed
Planner selected action: reconciliation
Medication reconciliation completed
Detected 1 conflicts
Replanner selected action: safety
Generated 1 safety flags
Loaded 1 feedback records
Summary received 1 feedback records
Discharge summary generated
Benefits:
- Auditability
- Workflow transparency
- Easier debugging
- Better explainability
Discharge-Summary-Agent/
│
├── agent/
│ └── graph.py
│
├── nodes/
│ ├── ingestion_node.py
│ ├── extraction_node.py
│ ├── planner_node.py
│ ├── reconciliation_node.py
│ ├── conflict_node.py
│ ├── replanner_node.py
│ ├── safety_node.py
│ ├── feedback_node.py
│ └── summary_node.py
│
├── tools/
│ ├── feedback_tool.py
│ ├── medication_tool.py
│ ├── conflict_tool.py
│ ├── escalation_tool.py
│ └── trace_tool.py
│
├── feedback/
│ └── corrections.json
│
├── state/
│ └── state.py
│
├── data/
│
├── test_summary_v2.py
├── record_feedback.py
├── requirements.txt
├── README.md
└── .env
- Python
- LangGraph
- LangChain
- Groq LLM (Llama 3.3 70B Versatile)
- Tenacity
- JSON Feedback Memory
- PDF Processing Libraries
git clone <repository-url>
cd Discharge-Summary-Agentpython -m venv venvvenv\Scripts\activatesource venv/bin/activatepip install -r requirements.txtCreate a .env file:
GROQ_API_KEY=your_groq_api_keypython test_summary_v2.pypython record_feedback.pyExample:
Error Type:
missing_pending_results
Correction:
Always prominently highlight pending urine culture follow-up.
Pending Results:
Urine culture and sensitivity
Always prominently highlight pending urine culture follow-up.
PENDING RESULTS:
URINE CULTURE AND SENSITIVITY RESULTS PENDING.
FOLLOW-UP IS CRUCIAL.
This demonstrates memory-driven behavior improvement without retraining the model.
- Agentic execution workflow
- Planner and Replanner architecture
- Clinical safety validation
- Medication reconciliation framework
- Persistent learning loop
- Human-review integration
- Transparent trace logging
- Modular node-based architecture
- Admission medications may not always be available in source documents.
- Feedback entries are currently treated equally without ranking.
- Replanning currently performs a single replanning pass.
- Clinical validation rules can be expanded further.
- Feedback memory is JSON-based and not vector-search enabled.
- Multi-step iterative replanning
- Advanced medication reconciliation
- Feedback confidence scoring
- Long-term vector memory
- Clinical guideline validation
- Human review dashboard
- Multi-document patient timeline support
- Evaluation and benchmarking framework
This project demonstrates a complete Agentic AI workflow for discharge summary generation with planning, replanning, safety validation, medication reconciliation, persistent feedback memory, and observable execution traces.
The architecture prioritizes safety, explainability, extensibility, and practical deployment considerations while maintaining a modular and production-oriented design which is suitable for healthcare AI workflows.