Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GxP Multi-Agent Batch Record Review Engine

An enterprise multi-agent system designed for automated Electronic Batch Record (eBR) review, deterministic quality control verification, and CAPA deviation triage in regulated pharmaceutical manufacturing. Built with LangGraph, LangChain, Google Gemini 3.6 Flash, Pydantic v2, and Langfuse.


📌 Architecture & Orchestration Flow

               [ Raw Manufacturing Batch Log (Unstructured Text) ]
                                      │
                                      ▼
                      ┌───────────────────────────────┐
                      │    Node 1: Data Extractor     │
                      │  (Pydantic Schema Validation) │
                      └───────────────┬───────────────┘
                                      │
                                      ▼ [State: Extracted JSON]
                      ┌───────────────────────────────┐
                      │  Node 2: QC Rule Checker Tool │
                      │  (Deterministic SOP Limits)   │
                      └───────────────┬───────────────┘
                                      │
                     ┌────────────────┴────────────────┐
                     │   Conditional Routing Engine    │
                     └────────────────┬────────────────┘
                                      │
                 ┌────────────────────┴────────────────────┐
                 │                                         │
     [ Violations Detected ]                       [ 100% Compliant ]
                 │                                         │
                 ▼                                         ▼
 ┌───────────────────────────────┐         ┌───────────────────────────────┐
 │   Node 3: Deviation Triager   │         │  Node 4: Release Authorizer   │
 │   (CAPA Root-Cause Ticket)    │         │ (Certificate of Analysis QP)  │
 └───────────────────────────────┘         └───────────────────────────────┘
                 │                                         │
                 └────────────────────┬────────────────────┘
                                      ▼
                          [ Langfuse Cloud Tracing ]
                     (Tamper-Evident GxP Audit Trail)

✨ Key Capabilities

  • Stateful Graph Orchestration (LangGraph): Employs a typed StateGraph where intermediate agent states, tool outputs, and execution logs are tracked on a central state dictionary.
  • Deterministic Parameter Verification: Separates math and tolerance checking from generative LLMs. SOP limits (temperature bounds, hold durations, yield thresholds) are checked by deterministic Python tools to guarantee zero-hallucination compliance checking.
  • Conditional Branching: Dynamically routes batches between release certification pathways and deviation quarantine workflows based on boolean violation flags.
  • Defensive Pydantic Validation: Enforces strict type contracts at agent boundaries with fallback defaults to handle missing data fields without crashing.
  • Immutable 21 CFR Part 11 Audit Trail: Appends timestamped execution events across every node to maintain an immutable log of all automated decisions.
  • OpenTelemetry Distributed Tracing: Integrates Langfuse to monitor latency, token usage, and execution telemetry for every agent node.

📋 Regulatory Compliance & SOP Specifications (SOP-QA-042)

The system audits batches against rigid parameter specifications:

Critical Process Parameter (CPP) Registered Acceptance Criteria / Specification Severity / Action
Sterile Filter Integrity (Bubble Point) $\ge 38.0\text{ psi}$ CRITICAL (Loss of Sterility Assurance)
Bulk Storage Temperature $2.0^\circ\text{C}$ to $8.0^\circ\text{C}$ CRITICAL (Cold Chain Excursion)
Bulk Formulation Hold Time $\le 6.0\text{ hours}$ MAJOR (Microbial / Degradation Risk)
Final Product Harvest Yield $95.0%$ to $102.0%$ MAJOR (Process Inefficiency / OOS)
Visual Inspection Reject Rate $\le 2.0%$ MAJOR (Particulate Alert Limit)
Environmental Monitoring (Grade A) $0\text{ CFU}$ / ISO 5 Compliant CRITICAL (Cleanroom Contamination)

📊 Live Execution Results

Batch 1: Compliant Run (BATCH-2026-001)

  • Product: Lyophilized Vaccine Antigen
  • QC Violations: 0 (100% Compliant)
  • Routed Node: release_authorizer
  • Disposition: COMMERCIALLY_RELEASED
  • Artifact: Certificate of Analysis (COA-BATCH-2026-001) with storage directives ($2.0^\circ\text{C}$ to $8.0^\circ\text{C}$).

Batch 2: Out-of-Specification Excursion (BATCH-2026-002)

  • Product: Sterile Injectable Monoclonal Antibody
  • QC Violations: 3 Out-of-Specification parameters detected:
    • Bulk Storage Temp: $11.4^\circ\text{C}$ (Spec: $2.0^\circ\text{C}$–$8.0^\circ\text{C}$) — CRITICAL
    • Hold Time: $7.8\text{ hrs}$ (Spec: $\le 6.0\text{ hrs}$) — MAJOR
    • Harvest Yield: $91.4%$ (Spec: $95.0%$–$102.0%$) — MAJOR
  • Routed Node: deviation_triager
  • Disposition: REJECTED
  • Artifact: CAPA Ticket (DEV-BATCH-2026-002) initiating immediate quarantine, sensor recalibration, and thermal degradation root-cause analysis.

📂 Project Structure

gxp-multiagent-workflow/
├── data/
│   └── sample_batch_records.json   # Compliant & non-compliant batch test fixtures
├── src/
│   ├── __init__.py
│   ├── state.py                    # TypedDict graph state & Pydantic schemas
│   ├── agents.py                   # Extractor, QC tool, Triager, and Authorizer nodes
│   └── graph.py                    # LangGraph StateGraph & conditional routing logic
├── .env.example
├── .gitignore
├── requirements.txt
└── run_pipeline.py                 # Master execution & Langfuse reporting runner

⚡ Quickstart

1. Setup Environment

git clone https://github.com/GAMhackER/gxp-multiagent-workflow.git
cd gxp-multiagent-workflow

python3 -m venv venv
source venv/bin/activate

pip install -r requirements.txt

2. Configure Credentials

Create .env file:

cat << 'EOF' > .env
GOOGLE_API_KEY=your_gemini_api_key
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_HOST=https://cloud.langfuse.com
EOF

3. Run Multi-Agent Audit Engine

python3 run_pipeline.py

About

Enterprise multi-agent GxP batch record review system orchestrating schema validation, deterministic QC rule tools, and CAPA deviation triage using LangGraph, Gemini, and Langfuse tracing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages