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.
[ 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)
- Stateful Graph Orchestration (LangGraph): Employs a typed
StateGraphwhere 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.
The system audits batches against rigid parameter specifications:
| Critical Process Parameter (CPP) | Registered Acceptance Criteria / Specification | Severity / Action |
|---|---|---|
| Sterile Filter Integrity (Bubble Point) | CRITICAL (Loss of Sterility Assurance) | |
| Bulk Storage Temperature |
|
CRITICAL (Cold Chain Excursion) |
| Bulk Formulation Hold Time | MAJOR (Microbial / Degradation Risk) | |
| Final Product Harvest Yield |
|
MAJOR (Process Inefficiency / OOS) |
| Visual Inspection Reject Rate | MAJOR (Particulate Alert Limit) | |
| Environmental Monitoring (Grade A) |
|
CRITICAL (Cleanroom Contamination) |
- 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}$ ).
- 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
-
Bulk Storage Temp:
-
Routed Node:
deviation_triager -
Disposition:
REJECTED -
Artifact: CAPA Ticket (
DEV-BATCH-2026-002) initiating immediate quarantine, sensor recalibration, and thermal degradation root-cause analysis.
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
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.txtCreate .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
EOFpython3 run_pipeline.py