Everything-as-a-Plugin Architecture for AI-Powered Medical Consultation Workflows

    This article presents a practical engineering approach to designing AI-driven medical consultation workflows using an "everything-as-a-plugin" architecture. It explains why monolithic pipelines fail in high-stakes domains, how to enforce evidence-based gating in the orchestration engine rather than in prompts, how to define replaceable plugin contracts, and how to structure staged questioning, confidence thresholds, evidence verification, and compliance boundaries. The content is a general engineering methodology and is not tied to any specific product.

    1. Background: Why “Everything-as-a-Plugin” Fits High-Stakes Scenarios

    In AI application development, a common pattern is to mix prompts, business rules, and data queries inside one large pipeline. This works quickly for demos, but once it enters rigorous scenarios such as medical assistance, financial risk control, or industrial diagnostics, three problems surface: the flow becomes uncontrollable, conclusions cannot be traced, and capabilities cannot be swapped out.

    The “everything-as-a-plugin” approach encapsulates every capability that can evolve independently as a plugin: intake collection is a plugin, syndrome differentiation matching is a plugin, literature verification is a plugin, and prescription output is a plugin as well. Plugins communicate through explicit contracts, while the host engine handles orchestration and gating. The direct benefit is that if any stage fails to meet its bar, the flow stops at that stage instead of passing uncertain information downstream.

    Note that this article discusses a general engineering method and does not target any specific product. References to “AI coding tools” and “a certain platform” are neutral by design.

    2. Core Design Principle: Ask More, Conclude Later

    The first principle in rigorous scenarios is not “produce a conclusion fast” but “every conclusion must be grounded.” The engine layer therefore needs three hard constraints built in:

    1. When information is insufficient, only follow-up questions are allowed, never a conclusion.
    2. A conclusion must be supported by evidence; if evidence is insufficient, output is refused.
    3. Questions should be structured as much as possible to reduce ambiguity from free text.

    These three rules must live in the engine, not only in the prompt. A prompt can be ignored by the model; an engine gate cannot.

    Illustrative pseudocode:

    1. if confidence < THRESHOLD:
    2. return ask_next_question()
    3. if evidence.verdict != "supported":
    4. return reject_with_alternatives()
    5. return emit_result()

    3. Plugin Contracts: Turning the Flow into Replaceable Gates

    An executable workflow plugin typically has four stages, each backed by its own plugin:

    • Intake plugin: collects basic information and the chief complaint.
    • Symptom plugin: collects specific symptoms, signs, tongue and pulse findings as structured options.
    • Differentiation plugin: produces candidate options and key differentiating points.
    • Evidence and output plugins: handle literature verification and final output.

    A plugin contract should include four fields: input schema, output schema, confidence, and failure action. The failure action is especially important, because it decides whether the flow falls back, asks more questions, or terminates.

    1. {
    2. "plugin": "differentiate",
    3. "input": "structured_signs",
    4. "output": "candidates_with_score",
    5. "min_confidence": 0.6,
    6. "on_fail": "ask_more"
    7. }

    4. State Transitions: Staged Questioning Instead of Long Forms

    What the patient sees should not be a long form requiring typing, but option cards. The staged design is:

    1. Basic information stage: name form, age, gender, chief complaint, duration, special conditions.
    2. Symptom stage: several groups of multi-select covering common complaint categories, with free-text supplement allowed.
    3. Sign stage: temperature, blood pressure, and pulse collected as ranges plus numeric values.
    4. Differentiation stage: first show a multi-select of differentiating points, then a single-select of candidate options with match scores and summaries.
    5. Evidence stage: search built-in classical passages and live literature.
    6. Output stage: emit only after review passes; otherwise fall back to the differentiation stage.

    This design makes every step verifiable and rollback-friendly, and it also makes it easy to replace the implementation of any single step later.

    5. Confidence Thresholds and Automatic Follow-Up

    The differentiation plugin has a built-in confidence threshold with three trigger conditions: insufficient match on the primary symptom, top match score below the threshold, and a score gap between the first and second choice that is too small. If any condition triggers, the plugin returns no candidates and instead returns the next round of differentiating questions. Automatic follow-up rounds are capped to avoid infinite loops.

    1. if top1 - top2 < 8 and top1 >= 60:
    2. threshold = 4
    3. else:
    4. threshold = 8

    Thresholds can be configured per scenario, but they must be auditable.

    6. Evidence Verification and Defensible Answers

    The evidence plugin performs two kinds of checks: retrieval of built-in classical passages and retrieval of live literature. The output plugin re-verifies once more before releasing a result. When challenged, the system offers a “defense” capability: if a claim holds, it returns the original text and the literature reference number; if it does not hold, it corrects itself on the spot. This turns explainability into a tool rather than a talking point.

    7. Safety and Compliance Boundaries

    Such plugins should be positioned clearly as learning and assistance tools. Their output cannot replace an in-person consultation or a licensed practitioner’s prescription. Any dosage conversion must use conservative conversion. Content involving toxic ingredients must be used only under professional supervision. On the engineering side, add disclaimers, audit logs, and a human review entry point.

    8. Implementation Recommendations

    1. Define contracts first, then write implementations.
    2. Put gates in the engine, not in the prompt.
    3. Structure all questions, while keeping free-text supplements.
    4. Separate evidence from output, and enforce re-verification.
    5. Keep thresholds and rules configurable and auditable.
    6. Log the entire flow to support retrospectives and plugin replacement.

    Following this method, teams can build a logically rigorous, explainable, and replaceable AI consultation workflow without depending on any specific product.