A hierarchical, supervisor-based Multi-Agent System (MAS) for complex medical diagnosis consultation, implemented using LangChain's deepagents package.
This system models the workflow of a clinical team consultation by decomposing the diagnostic process into distinct, specialized tasks, each handled by a dedicated agent, with a central supervisor managing the overall strategy and synthesizing the final output.
The main agent and entry point for new cases. It:
- Receives initial patient presentation
- Creates high-level diagnostic plans
- Dynamically assembles a consultation team by delegating to specialist sub-agents
- Coordinates the workflow and ensures all specialists complete their tasks
- Delegates final synthesis to the SynthesizerAgent
- EHR_AnalystAgent: Retrieves and analyzes structured data from the patient's electronic health record
- Radiology_ReportAgent: Parses and extracts key findings from unstructured text in radiology reports
- Pathology_ReportAgent: Interprets structured lab data, flagging abnormal values and trends
- Literature_ReviewAgent: Searches biomedical literature for evidence relevant to the patient's presentation
Integrates findings from all specialist agents, weighs conflicting information, and formulates a comprehensive differential diagnosis report with confidence scores and supporting evidence.
- Case Reception: CaseManagerAgent receives a case with patient presentation and available data
- Planning: CaseManagerAgent creates a diagnostic plan using
write_todos - Delegation: CaseManagerAgent delegates specific analytical tasks to specialist sub-agents using the
tasktool - Specialist Analysis: Each specialist performs its task and writes findings to the shared workspace
- Synthesis: Once all specialists have contributed, CaseManagerAgent tasks SynthesizerAgent to review the complete case file and generate the final diagnostic report
- Install dependencies:
pip install -r requirements.txt
# or if using uv
uv sync- Set up environment variables in
.env:
TAVILY_API_KEY=your_tavily_api_key_here
OPENAI_API_KEY=your_openai_api_key_here # or configure your model provider
from consultation_system import ConsultationSystem
# Create the consultation system
consultation_system = ConsultationSystem()
# Process a case
result = consultation_system.process_case(
patient_presentation="45-year-old male with chest pain and shortness of breath...",
ehr_data="Vital signs and medical history...",
radiology_reports="X-ray and imaging findings...",
lab_data="Blood work and lab results...",
case_id="case_001"
)
# Access results
print(result['final_diagnosis'])
print(result['specialist_findings'])
print(result['workspace_path'])python main.pyThe example includes a complete case with all data types for demonstration.
.
├── agents/
│ ├── __init__.py
│ ├── case_manager.py # CaseManagerAgent (supervisor)
│ └── specialists.py # All specialist agents and tools
├── consultation_system.py # Main system class
├── main.py # Entry point with example
├── workspace/ # Shared workspace for agent findings (auto-created)
├── pyproject.toml # Project dependencies
└── README.md # This file
- Hierarchical Architecture: Supervisor-based MAS with specialized agents
- Shared Workspace: Agents communicate through a persistent file-based workspace
- Dynamic Delegation: CaseManagerAgent dynamically assigns tasks based on case needs
- Specialized Tools: Each agent has domain-specific tools for their expertise
- Literature Search: Integration with Tavily for biomedical literature search
- Comprehensive Reporting: Final diagnostic reports with confidence scores and evidence
All agents have access to:
write_todos: Create and manage task planstask: Spawn and delegate to subagents- File system tools:
ls,read_file,write_file,edit_file
- EHR_AnalystAgent:
analyze_ehr_data - Radiology_ReportAgent:
parse_radiology_report - Pathology_ReportAgent:
analyze_lab_data - Literature_ReviewAgent:
search_biomedical_literature
To add new specialist agents:
- Create the agent function in
agents/specialists.py - Define the agent's tools and system prompt
- Register the agent in the
create_case_manager_agent()function inagents/case_manager.py
- The system uses
deepagentsfrom LangChain, which provides built-in task management and file system tools - Agents communicate through the shared workspace directory (
./workspace/) - Each case gets its own subdirectory in the workspace
- Final diagnostic reports are saved to
workspace/case_{id}/final_diagnosis.txt
- Python >= 3.11
- deepagents >= 0.2.4
- langchain >= 1.0.3
- tavily-python >= 0.7.12