pratikmurali/FDA_Regulatory_Assistant_For_SaMD
FDA Regulatory Assistant
A sophisticated AI-powered assistant for FDA regulatory compliance analysis, built with LangGraph multi-agent workflows and Chainlit for an interactive user experience.
๐ Features
๐ค Multi-Agent System
- Supervisor Agent: Intelligent routing and response compilation as FDA auditor
- Document Processor: Advanced ZIP file extraction and document parsing
- Cybersecurity Specialist: FDA cybersecurity guidance and SOUP documentation analysis
- Regulatory Affairs Expert: CFR510K, PMA, and FDA regulatory compliance review
- Compliance Auditor: FDA Auditor like, Comprehensive gap analysis and readiness assessment
- Report Generator: Detailed compliance reports with actionable recommendations
๐ฌ Interactive Capabilities
- Intelligent Q&A: Context-aware routing to appropriate specialist agents
- Document Gap Analysis: Upload ZIP files containing regulatory submission packages
- Real-time Streaming: Word-by-word response streaming with agent identification
- Source References: All responses include original FDA document citations
- File Processing: Support for PDF, Word, TXT, and ZIP file uploads
๐๏ธ Advanced Architecture
- Simplified LangGraph Workflow: Clean state management with message passing
- 24+ Specialized Tools: Comprehensive toolkit for document processing and compliance analysis
- RAG Integration: Pre-warmed chains for instant access to FDA knowledge base
- Streaming Configuration: Customizable streaming speeds and formatting preservation
- Error Handling: Graceful degradation and comprehensive error reporting
๐ ๏ธ Technology Stack
- Multi-Agent Framework: LangGraph with simplified state management
- UI Framework: Chainlit for interactive chat interface with file uploads
- LLM: OpenAI GPT-4o-mini with function calling
- Vector Database: Qdrant for efficient knowledge base storage and retrieval
- Document Processing: PyMuPDF (fitz) for PDF parsing, python-docx for Word documents
- RAG System: Custom chain manager with pre-warming and caching
- Package Management: UV for fast, reliable dependency management
- Testing: Pytest with comprehensive test suite
- Code Quality: Ruff for linting and code formatting
- Tracing: LangSmith for monitoring and debugging
- Offline Evals: RAGA for offline evaluation and testing
๐ Prerequisites
- Python 3.12+
- OpenAI API key
- UV package manager (recommended) or pip
๐ง Installation
- Clone the repository
git clone <repository-url>
cd fda-regulatory-assistant- Install dependencies
# Using UV (recommended)
uv sync
# Or using pip
pip install -r requirements.txt- Set up environment variables
cp .env.example .env
# Edit .env and add your OpenAI API key
OPENAI_API_KEY=your_api_key_here- Initialize the knowledge base (if needed)
python setup_env.py๐ Usage
Start the Application
chainlit run main.py -wThe application will be available at http://localhost:8000
Using the Assistant
Question Answering
Simply ask questions about FDA regulations or cybersecurity requirements:
- "What are the FDA cybersecurity requirements for medical devices?"
- "How do I submit a 510(k) application?"
- "What are the SOUP requirements for medical device software?"
Document Analysis
- Upload documents (PDF, TXT, or ZIP files)
- Ask for compliance gap analysis
- Receive detailed reports with findings and recommendations
Example Interactions
Cybersecurity Question:
User: What are the key cybersecurity controls for Class II medical devices?
Assistant: Based on FDA guidance, Class II medical devices should implement...Gap Analysis:
User: [Uploads device specification PDF]
User: Please analyze this document for regulatory compliance gaps
Assistant: **Cybersecurity Agent**: Analyzing cybersecurity compliance...
**Regulatory Agent**: Reviewing regulatory requirements...
**Auditor Agent**: Performing gap analysis...
**Report Generator**: Generating comprehensive report...๐ Project Structure
fda-regulatory-assistant/
โโโ main.py # Chainlit application entry point
โโโ graph/ # LangGraph multi-agent workflow
โ โโโ agents.py # 6 specialized agents with tool bindings
โ โโโ graph.py # Workflow orchestration and streaming
โ โโโ state.py # Simplified state management
โโโ tools/ # Comprehensive agent toolkit (24+ tools)
โ โโโ __init__.py # Tool exports
โ โโโ tools.py # Core tool implementations
โ โโโ README.md # Tool documentation
โ โโโ example_usage.py # Usage examples
โโโ ragchains/ # RAG chain implementations
โ โโโ chain_manager.py # Centralized chain management
โ โโโ fda_cybersecurity_rag.py # Cybersecurity knowledge base
โ โโโ fda_regulatory_rag.py # Regulatory knowledge base
โ โโโ tools/ # Legacy tool compatibility
โโโ utils/ # Utility functions
โ โโโ document_parsers.py # Advanced document processing
โ โโโ streaming_config.py # Streaming configuration
โ โโโ langgraph_utils.py # LangGraph helper functions
โโโ prompts/ # LLM prompts and templates
โโโ tests/ # Comprehensive test suite
โโโ examples/ # Usage examples and demos
โโโ loaders/ # Document loaders
โโโ pyproject.toml # UV package configuration๐ Workflow Architecture
The application implements a simplified LangGraph multi-agent system with intelligent routing and streaming responses:
๐ฏ Workflow Types
1. Question Answering Flow
User Question โ Supervisor โ Route to Specialist โ Tool Execution โ Streaming Response2. Gap Analysis Flow
ZIP Upload โ Document Processor โ Cybersecurity Agent โ
Regulatory Agent โ Auditor Agent โ Report Generator โ Final Report๐ง Agent Specialization
- Supervisor Agent:
- Intelligent routing based on question keywords
- Final response compilation as FDA auditor
- Workflow orchestration and error handling
- Document Processor:
- ZIP file extraction and validation
- Multi-format document parsing (PDF, Word, TXT)
- Document chunking and metadata extraction
- Cybersecurity Specialist:
- FDA cybersecurity guidance analysis
- SOUP (Software of Unknown Provenance) documentation
- Vulnerability assessment and security controls
- Regulatory Affairs Expert:
- 510K submission requirements
- PMA and regulatory compliance
- FDA guidance interpretation
- Compliance Auditor:
- Gap analysis and readiness assessment
- Compliance scoring and prioritization
- Risk assessment and mitigation
- Report Generator:
- Comprehensive compliance reports
- Executive summaries and recommendations
- Actionable improvement plans
๐ง Key Architecture Features
- Simplified State: TypedDict with message passing using
operator.add - Tool Integration: 24+ specialized tools for document processing and analysis
- Streaming Support: Real-time word-by-word response streaming
- Error Handling: Graceful degradation with recursion limits
- Source References: Automatic extraction and formatting of source citations
- Pre-warmed Chains: Instant response times through chain pre-loading
๐งช Testing
Run the test suite:
# Run all tests
python -m pytest tests/
# Run specific test categories
python -m pytest tests/test_streaming_*.py
python -m pytest tests/test_tools_integration.py๐ Performance Features
๐ Optimized Performance
- Pre-warmed RAG Chains: Instant response times after startup initialization
- Streaming Responses: Real-time word-by-word streaming with configurable delays
- Concurrent Processing: Thread-safe multi-agent execution
- Memory Efficiency: Shared vector stores and optimized document processing
- Caching: Intelligent caching of frequently accessed regulatory information
๐ Scalability Features
- Session Isolation: Independent user sessions with shared resources
- Error Recovery: Graceful degradation and automatic retry mechanisms
- Resource Management: Automatic cleanup and garbage collection
- Load Balancing: Efficient distribution of agent workloads
๐ง Configuration
Environment Variables
# Required
OPENAI_API_KEY=your_api_key_here
# Optional
CHAINLIT_AUTH_SECRET=your_secret_here
LANGSMITH_API_KEY=your_langsmith_key # For tracingStreaming Configuration
Customize streaming behavior in utils/streaming_config.py:
# Streaming modes
STREAMING_MODE = "word" # Options: "character", "word", "sentence"
WORD_DELAY = 0.05 # 50ms delay between words
ADAPTIVE_STREAMING = True # Adjust speed based on content
# Speed presets
SPEED_PRESETS = {
"instant": 0.0,
"fast": 0.005,
"normal": 0.01,
"slow": 0.02
}Agent Configuration
Customize agent behavior in graph/agents.py:
# Routing keywords for intelligent agent selection
CYBERSECURITY_KEYWORDS = ["cybersecurity", "SOUP", "vulnerability", "security"]
REGULATORY_KEYWORDS = ["510k", "PMA", "regulatory", "submission"]
AUDITOR_KEYWORDS = ["gap", "analysis", "compliance", "audit"]Tool Configuration
Adjust tool parameters in tools/tools.py:
# Document processing settings
DEFAULT_CHUNK_SIZE = 1000
DEFAULT_CHUNK_OVERLAP = 80
# Compliance thresholds
COMPLIANCE_THRESHOLDS = {
"critical": 0.9,
"major": 0.7,
"minor": 0.5
}๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
For questions or issues:
- Check the Issues page
- Review the test files for usage examples
- Consult the architecture documentation in
ARCHITECTURE.md
๐ฎ Roadmap
๐ฏ Near-term Enhancements
- [ ] Enhanced Document Support: Excel, PowerPoint, and additional file formats
- [ ] Advanced Analytics: Compliance trend analysis and historical tracking
- [ ] Batch Processing: Multiple document package analysis
- [ ] Custom Templates: User-defined compliance checklists and report formats
๐ Future Features
- [ ] FDA Database Integration: Real-time access to FDA guidance updates
- [ ] Visualization Dashboard: Interactive compliance dashboards and charts
- [ ] Multi-language Support: Support for international regulatory frameworks
- [ ] API Integration: RESTful API for enterprise integration
- [ ] Advanced AI Features: Predictive compliance analysis and risk scoring
๐ง Technical Improvements
- [ ] Performance Optimization: Enhanced caching and parallel processing
- [ ] Security Enhancements: Advanced authentication and data encryption
- [ ] Monitoring & Observability: Comprehensive logging and metrics
- [ ] Deployment Options: Docker containers and cloud deployment guides
Built with โค๏ธ using LangGraph, Chainlit, OpenAI, and PyMuPDF
Empowering regulatory compliance through intelligent multi-agent systems
