Plugin-Driven Architecture for Reliable Clinical Consultation Workflows
This article explores how a plugin-driven architecture can support high-reliability clinical consultation workflows, particularly in Traditional Chinese Medicine (TCM) pattern differentiation and prescription assistance. It outlines a minimal core engine responsible for plugin registration, state management, and auditing, while domain-specific capabilities—such as symptom collection, pattern matching, evidence retrieval, and prescription review—are implemented as independent plugins. The discussion covers contract-based plugin design, a process state machine, three independent quality gates, evidence traceability, and practical engineering recommendations for production deployment.
From “Everything Is a Plugin” to Controlled, Auditable Workflows
“Everything is a plugin” is often understood as simply decomposing functionality into pluggable modules. In high-risk domains, however, the real challenge is not whether a system can be decomposed, but how to ensure process control, evidence traceability, and the ability to reject conclusions after decomposition. Consider a TCM pattern differentiation and prescription assistance workflow: the system must first collect basic patient information, then gather symptoms, tongue and pulse findings, and differential diagnostic points; only then can it perform formula-pattern matching, literature verification, and prescription review. At any stage, if information is insufficient or evidence is incomplete, the system should not prematurely output a conclusion. The value of a plugin-driven architecture lies in encapsulating domain capabilities, interaction patterns, quality gates, and evidence services separately, while a minimal core engine handles registration, orchestration, state management, and auditing.
I. Minimal Core Engine, Plugin-Based Domain Capabilities
“Everything is a plugin” does not mean scattering all logic across plugins. A more sound layering is: the core engine is responsible only for plugin registration and discovery, workflow state management, context storage, permission validation, call auditing, and failure rollback. Domain plugins handle specific question sets, differentiation rules, evidence retrieval, and prescription review capabilities. This approach preserves extensibility while ensuring that each plugin does not maintain its own process control logic.
Plugins should declare clear contracts, including input/output schemas, preconditions, side effects, rejection conditions, and fallback strategies. For example:
{"plugin": "differential_assessment","stage": "differentiate","input_schema": {"intake": "object","symptoms": "array","signs": "object"},"preconditions": ["intake.completed == true","symptom_coverage >= min_required"],"guards": [{"type": "confidence", "min_score": 0.60},{"type": "separation", "min_gap": 0.08}],"on_reject": {"action": "ask_more_questions","max_rounds": 3}}
The thresholds above are for illustrative purposes only; production systems should calibrate them based on domain expert consensus. The benefit of contract-based design is twofold: plugins can be independently tested, gradually rolled out, and rolled back; and the orchestrator can detect insufficient information and return follow-up questions, rather than letting the model improvise freely.
II. Workflow State Machine: Gather First, Then Decide
Clinical consultation workflows naturally fit a state machine model. Typical stages can be abstracted as: basic information collection, chief complaint and symptom collection, physical signs and tongue-pulse assessment, differential evaluation, evidence verification, and prescription review. Each stage has clear entry and exit conditions. When information is insufficient, the state machine returns to the questioning stage; when evidence is insufficient, it returns to the differentiation stage; when review fails, it rejects the output and returns candidate alternative paths.
The interaction layer should favor option-based cards over large blocks of free-text questionnaires. Option-based input reduces ambiguity, increases data structure, and simplifies downstream rule-based computation. For example, multi-select for symptoms, single-select for tongue findings, multi-select for pulse patterns, and interval selection for temperature and blood pressure are all provided as schemas by plugins, with the frontend rendering according to those schemas. Patients see tappable cards rather than blank text fields requiring them to organize their own language.
III. Three Independent Quality Gates: Matching, Evidence, Review
High-reliability domains cannot treat “generated text that looks plausible” as a valid conclusion. A more robust approach is to enforce three independent quality gates:
- Formula-pattern matching gate: When primary symptoms do not meet coverage thresholds, the highest match score is too low, or the gap between the top-ranked and second-ranked candidates is too small, the system does not propose a candidate formula; it returns only the next round of differentiation questions.
- Literature verification gate: Before output, the system queries a repository of classical texts and publicly available medical literature interfaces to confirm that traceable supporting evidence exists; if evidence is inadequate, the output is rejected.
- Prescription review gate: The prescription plugin re-verifies context, contraindications, special-population status, and the evidence chain; if any item fails, no prescription is issued.
These three gates operate independently, preventing scenarios where a high matching score bypasses evidence checks, or where the presence of literature overrides individual patient information. The rejection path must be a first-class citizen: the system should return structured alternatives and follow-up questions rather than a simple error message.
IV. Evidence Chains and Traceable Accountability
High-risk scenarios require both “explainable persistence” and “auditable correction.” The evidence service should record retrieval sources, matched classical passages, literature identifiers, retrieval timestamps, plugin versions, and decision paths. When facing scrutiny, the system can initiate an evidence-based accountability process: if evidence is sufficient, it displays original citations and literature identifiers; if evidence is insufficient, it immediately revises the candidate plan and logs the reason for the change. All citations and modifications should be recorded in the audit log for subsequent review.
V. Engineering Recommendations for Production Deployment
The recommended implementation order for a plugin-driven consultation system is: define state machine and rejection policies first, then decompose plugins; build contract tests before optimizing interaction; ensure evidence chains and auditing before expanding coverage. Attention should be paid to plugin version compatibility, permission isolation, sensitive data protection, gradual rollout, monitoring and alerting, and rollback mechanisms. The more plugins there are, the higher the governance cost, so decomposition should not be done for its own sake—only capabilities with clear boundaries and independent verifiability are suitable for plugin-based architecture.
Finally, it must be emphasized: such systems serve as TCM learning and assistance tools, and their outputs cannot replace in-person diagnosis or a licensed practitioner’s prescription. When toxic substances, special populations, or dosage conversions are involved, a licensed practitioner must confirm according to regulations. The value of a plugin-driven architecture is not to make the system “bolder,” but to make it more restrained when information is insufficient, more capable of rejection when evidence is inadequate, and more traceable when disputes arise.
