Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Consultation Multi-Agent System

A hierarchical, supervisor-based Multi-Agent System (MAS) for complex medical diagnosis consultation, implemented using LangChain's deepagents package.

Overview

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.

System Architecture

CaseManagerAgent (Supervisor)

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

Specialist Sub-Agents

  1. EHR_AnalystAgent: Retrieves and analyzes structured data from the patient's electronic health record
  2. Radiology_ReportAgent: Parses and extracts key findings from unstructured text in radiology reports
  3. Pathology_ReportAgent: Interprets structured lab data, flagging abnormal values and trends
  4. Literature_ReviewAgent: Searches biomedical literature for evidence relevant to the patient's presentation

SynthesizerAgent

Integrates findings from all specialist agents, weighs conflicting information, and formulates a comprehensive differential diagnosis report with confidence scores and supporting evidence.

Workflow

  1. Case Reception: CaseManagerAgent receives a case with patient presentation and available data
  2. Planning: CaseManagerAgent creates a diagnostic plan using write_todos
  3. Delegation: CaseManagerAgent delegates specific analytical tasks to specialist sub-agents using the task tool
  4. Specialist Analysis: Each specialist performs its task and writes findings to the shared workspace
  5. Synthesis: Once all specialists have contributed, CaseManagerAgent tasks SynthesizerAgent to review the complete case file and generate the final diagnostic report

Installation

  1. Install dependencies:
pip install -r requirements.txt
# or if using uv
uv sync
  1. 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

Usage

Basic Usage

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'])

Running the Example

python main.py

The example includes a complete case with all data types for demonstration.

Project Structure

.
├── 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

Features

  • 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

Agent Tools

Built-in Deep Agents Tools

All agents have access to:

  • write_todos: Create and manage task plans
  • task: Spawn and delegate to subagents
  • File system tools: ls, read_file, write_file, edit_file

Specialist-Specific Tools

  • EHR_AnalystAgent: analyze_ehr_data
  • Radiology_ReportAgent: parse_radiology_report
  • Pathology_ReportAgent: analyze_lab_data
  • Literature_ReviewAgent: search_biomedical_literature

Extending the System

To add new specialist agents:

  1. Create the agent function in agents/specialists.py
  2. Define the agent's tools and system prompt
  3. Register the agent in the create_case_manager_agent() function in agents/case_manager.py

Notes

  • The system uses deepagents from 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

Requirements

  • Python >= 3.11
  • deepagents >= 0.2.4
  • langchain >= 1.0.3
  • tavily-python >= 0.7.12

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages