Plugin-Based Architecture for Intelligent Diagnostic Consultation: A Practical Workflow Design
This article presents a practical design for an intelligent consultation workflow built on an "everything is a plugin" architecture. It explains how an orchestration engine, capability plugins, and an evidence layer work together through explicit input/output contracts, and how a six-stage closed loop with three independent gates enforces formula-pattern matching, literature verification, and prescription review. It also covers confidence thresholds, option-card interactions, traceability, safety and compliance boundaries, and engineering recommendations such as contract-first design, externalized state, and observability.
1. Background: Why “Everything Is a Plugin” Fits High-Rigor Consultation
As intelligent coding tools and agent platforms become more common, an architectural approach known as “everything is a plugin” has gained attention. The idea is to split capabilities into pluggable plugins, let an orchestration engine schedule them, and have plugins collaborate through explicit input/output contracts. This approach is especially valuable in high-rigor scenarios such as healthcare and TCM classical formula study: the workflow can be defined explicitly, every step has admission and rejection conditions, and any conclusion can be traced back to specific evidence.
The traditional approach puts all logic into one long prompt and lets the model improvise. The problems are clear: the workflow is uncontrollable, thresholds cannot be verified, and outputs cannot be traced. Once the model skips key steps and jumps to a conclusion, errors amplify along the chain. A plugin-based architecture turns “ask clearly first, then differentiate the pattern, and output only when evidence is found” into an engine-level constraint rather than a suggestion buried in a prompt.
2. Overall Architecture: Engine, Plugins, and Contracts
A typical plugin-based consultation system has three layers:
- Orchestration engine: maintains the session state machine and decides which plugin to call next, what parameters to pass, and how to handle rejection and retry.
- Capability plugins: each plugin does one thing, with a fixed input/output structure, and can be implemented internally as rules, retrieval, or model inference.
- Evidence and knowledge layer: built-in classical text database, literature retrieval interface, and formula knowledge base for plugins to query.
An illustrative plugin list and responsibilities:
intake collect basic information (name/age/gender/chief complaint/course/special conditions)symptoms collect symptoms, temperature, blood pressure, pulse (multi-select + numeric ranges)signs collect tongue and pulse signsdifferentiate formula-pattern matching and differentiation; output candidate formulas or continue askingevidence verify classical texts and literature; return supported / unsupportedprescribe issue a formula after review, including dosage conversion and safety notesdefense defend the position: cite original text and numbering when holding firm, revise the formula on the spot when wrong
Plugins do not call each other directly; all interactions are orchestrated by the engine. This ensures replaceability and testability: any single plugin can be replaced or rolled out gradually without affecting the overall workflow.
3. Workflow Design: A Six-Step Loop and Three Gates
The consultation is split into six stages that form a closed loop:
- Basic information collection: show a small set of structured questions at a time to avoid long questionnaires.
- Chief complaint collection: use multiple-choice options covering common complaint categories, with room for free-form additions.
- Symptom and sign collection: grouped multi-select covering symptoms, tongue signs, and pulse signs; temperature, blood pressure, and pulse use range options plus numeric input.
- Differentiation and candidate formulas: first show a multi-select of differentiation points, then a single-select of candidate formulas, each with a match score and formula-pattern summary.
- Evidence verification: search the built-in classical texts and real-time literature, and return a supporting conclusion.
- Issue or change the formula: if verification fails, refuse to issue a formula, return alternative directions, and send the workflow back to step 4.
The three independent gates are the safety core: the formula-pattern matching gate, the literature verification gate, and the prescription review gate. If any gate fails, no formula is output. This “AND” logic rather than “OR” logic is the baseline for a high-rigor system.
4. Confidence Threshold: Better to Ask More Than Conclude Early
The differentiation plugin has a built-in quantitative threshold to avoid premature convergence when information is insufficient:
if insufficient key symptoms matched or highest match < 60% or (first choice - second choice) < 8%:return the next round of differentiation questions (up to 3 automatic follow-ups)else:return the candidate formula list
In high-match scenarios, the score-gap threshold can be relaxed to 4%. The point of these rules is to express uncertainty explicitly instead of letting the model hide it behind vague language. The cap on automatic follow-ups prevents infinite loops; once exceeded, the flow escalates to a human or prompts for additional information.
5. Interaction Design: Option Cards Over Long Questionnaires
What patients see is not a long questionnaire requiring typing, but option cards. This has three benefits: first, it lowers input cost and improves completion rates; second, it turns natural language into structured data that is easier to validate with rules; third, it reduces ambiguity, since enumerating terms such as pulse and tongue signs as options is more reliable than free text. Free-form fields remain as a fallback, but structured fields are always the main channel.
6. Traceability and Position Defense
When challenged, the system provides a defense tool: when it can hold its position, it gives the original source and literature numbering; when it should admit an error, it revises the formula on the spot and records the reason for the change. This requires every output to carry evidence citations and version information, forming an auditable chain. From an engineering perspective, it is advisable to save a state snapshot for each session, along with plugin inputs/outputs and the list of evidence hits, to support review and responsibility definition.
7. Safety and Compliance Boundaries
Such a system must be clearly positioned as a learning and assistance tool; its output cannot replace in-person diagnosis or prescriptions from licensed physicians. Dosage conversion should use conservative conversion with prominent warnings, and formulas containing toxic medicinal materials must be used under physician guidance. In engineering terms, hard interception rules and a disclaimer template can be added to the prescription plugin, with a notice shown once at the start and once at the end of the session.
8. Engineering Recommendations
- Contracts first: define plugin input/output schemas before implementing internal logic.
- Externalize state: the engine holds session state and plugins are side-effect free, making replay and testing easier.
- Pluggable evidence: make the knowledge base and retrieval interface replaceable plugins for easier updates and review.
- Observability: record the result of each gate decision, connect to logging services and monitoring alerts, and keep abnormal flows traceable.
- Elastic deployment: stateless plugins can be containerized and scaled horizontally, while session state is externalized to cache or object storage to support high concurrency.
The essence of “everything is a plugin” is not to fragment code, but to turn business rules into explicit assets that are orchestrable, verifiable, and replaceable. For high-rigor consultation scenarios, this architecture turns “ask clearly first, then differentiate the pattern, and issue a formula only with evidence” from a slogan into an engine-level guarantee.
