Plugin Architecture for a Structured Consultation System: Everything as a Plugin
Vertical-domain applications often face faster requirement changes than generic platforms. Workflow changes, rule updates, evidence-source replacements, and interaction shifts can quickly turn a hard-coded application into an unmaintainable workflow monolith. An everything-as-a-plugin approach addresses this by splitting domain capabilities into registered, orchestratable, and auditable plugins. The host engine owns lifecycle, permissions, state, and governance, while each plugin owns a narrow stage. Using a structured consultation system as an example, this article discusses the architecture design and engineering points: stage modeling, option-based interaction, confidence and evidence gates, and safety boundaries.
Why “Everything as a Plugin” Fits Flow-Driven Domain Applications
A plugin architecture is not simply about adding more modules; it is about establishing a stable extension contract. The host engine defines plugin interfaces, input/output structures, error codes, timeouts, permissions, and audit requirements. Plugins implement concrete stage capabilities such as information collection, symptom completion, differential follow-up, evidence verification, and prescription advice.
This approach brings several direct benefits:
- Change isolation: When domain rules change, you replace or upgrade the affected plugin without touching the main flow.
- Composable flows: Different scenarios can orchestrate different plugin sequences. For example, initial consultation, follow-up, and post-visit follow-up can use different collection depths.
- Auditability: Every plugin’s input, output, version, and evidence references can be logged for traceability.
- Governability: High-risk plugins can be given stricter permissions, human review, and gradual rollout strategies.
- Testability: Once plugin contracts are stable, replay data can be used for unit testing and flow regression.
However, plugin architecture also has costs. If interfaces are unstable, plugins couple to each other. If there are too many plugins, versioning, dependency management, and governance become complex. Therefore, “everything as a plugin” must be paired with clear stage boundaries and unified host governance. Otherwise, it is just a monolith split into a distributed monolith.
Stage Modeling for a Structured Consultation Flow
A structured consultation process can be modeled as a state machine. It first collects basic information, then chief complaints and symptoms, then observational items such as signs, tongue, and pulse. Next, it performs differential analysis and candidate matching. Finally, it verifies evidence and outputs a recommendation. Each stage is a plugin capability, and preconditions and fallback paths must be explicit.
A simplified flow is:
intake -> symptoms -> signs -> differentiate -> evidence -> prescribe^ ||---- follow-up if information is insufficient -----||---- fall back if evidence is insufficient -----|
The responsibilities for each stage can be defined as:
- intake: Collect basic information such as name, age, sex, chief complaint, duration, and special conditions.
- symptoms / symptoms2: Use multi-select and free-form supplements to collect symptoms across common discomfort categories.
- signs: Collect temperature, blood pressure, pulse range or numeric values, and observational items such as tongue and pulse.
- differentiate: Output differential points and candidate plans, with match scores and summaries.
- evidence: Query a built-in literature library and external literature search adapters to form evidence conclusions.
- prescribe: Re-check evidence and confidence before outputting a recommendation. A recommendation is produced only when the required conditions are met.
The key design principle is the separation between information collection and decision output. Collection plugins only structure the information. The differentiation plugin only returns candidates and follow-up questions. The evidence plugin only verifies evidence. The prescription plugin acts as the final gate. No stage should bypass this boundary and directly output a high-risk conclusion.
Option-Based Interaction: Reduce Free-Text Ambiguity
Consultation plugins should not start by asking users to enter large amounts of free text. A more stable interaction model is option cards plus limited free-text supplements:
- Symptoms use multi-select.
- Signs use ranges or numeric values.
- Tongue and pulse observations use enumerations.
- Differential points use multi-select.
- Candidate plans use single-select.
This reduces user input cost and makes downstream rule matching more stable. A simplified plugin interface can be designed as:
Plugin.execute(context, input) -> ResultResult = {stage: string,questions?: Question[],candidates?: Candidate[],evidence?: EvidenceVerdict,prescription?: Prescription,nextStage?: string,error?: ErrorCode}
The host engine advances the flow based on nextStage. When a plugin returns questions, the front end renders them as option cards. When it returns candidates, the front end shows match scores and summaries. When the evidence verdict is not supported, the prescribe stage must refuse to output a prescription and return alternatives, sending the flow back to the differentiation stage.
Better to Ask More Than to Decide Early: Confidence and Evidence Gates
One of the most important principles for high-risk domain applications is: ask more rather than decide early. The differentiation plugin should have built-in confidence thresholds. If the key symptom match is insufficient, the highest match score is below a threshold, or the gap between the top and second candidate is too small, the system should not present candidate options. Instead, it should return another round of differentiation questions.
Example configurable thresholds: reject candidate output when the highest match score is below 60%, or when the gap between the top and second candidate is below 8% (4% in high-match cases). The system can allow up to three automatic follow-up rounds. These thresholds should be configuration items reviewed by domain experts, not hard-coded into prompts.
The evidence gate should be independent of the matching gate. Formula-syndrome matching, literature verification, and prescription output are three independent gates. If any of them fails, no prescription should be issued. The prescribe stage needs to re-check the evidence conclusion. When the conclusion is unsupported, it should directly reject the output and return alternative directions.
When the system faces challenges, it should provide “evidence defense”: if it should stand firm, it can cite the original literature text and unique identifiers; if it should be corrected, it can roll back to the differentiation stage for re-matching. This preserves explainability and avoids “prescribing for the sake of prescribing.”
Engineering Implementation and Safety Boundaries
From an engineering perspective, the host engine should provide plugin registration, version management, dependency checks, timeout control, audit logs, and observability metrics. Plugin input and output must use structured contracts. Error codes should distinguish between insufficient information, insufficient evidence, insufficient permissions, and internal errors. High-risk plugins should run in restricted environments. External retrieval should be connected through adapter interfaces so that sources can be replaced and rate-limited safely.
Safety boundaries must be enforced in the system, not just documented:
- Consultation plugins are learning and assistance tools. Their output cannot replace an in-person consultation or a licensed physician’s prescription.
- Dose conversion rules need domain expert review and must be declared in configuration.
- Formulas containing toxic substances must prompt users to use them under physician guidance.
Only by engineering process gates, evidence gates, and safety warnings together can a plugin architecture truly support scalable, auditable domain applications.
