Everything as a Plugin: Making Domain Consultation Workflows Executable

    This article explains how to turn a domain consultation workflow into an executable, auditable, and reversible plugin-based process. It covers structured intake, state-machine orchestration, option-based interaction, confidence thresholds, evidence verification, output review, traceable correction, and the security and compliance controls required for health-related information.

    Everything as a Plugin: Making Domain Consultation Workflows Executable

    In a plugin-based architecture, the core engine should not hard-code domain knowledge. Instead, it should use a unified plugin protocol for capability registration, workflow orchestration, input validation, evidence verification, and audit logging.

    “Everything as a plugin” does not mean putting every piece of code into a plugin. It means separating variable domain capabilities, interaction patterns, and validation rules from the core engine. The core should focus on lifecycle management, permissions, state, and security boundaries.

    Using a domain consultation workflow as an example, this article explores how to make “clarify the situation first, differentiate next, and provide recommendations only when supporting evidence is available” into an executable, auditable, and reversible plugin workflow.

    The stage names, function names, and thresholds in this article are illustrative pseudocode. They describe design constraints and do not represent proprietary interfaces or parameters from any existing product.

    1. From Free-Form Conversation to a Constrained Workflow

    Traditional conversational tools are natural to use, but they also have clear weaknesses: incomplete information collection, inconsistent follow-up ordering, premature conclusions, and poor traceability of supporting evidence.

    These problems are particularly significant in domain consultation. If a model produces a conclusion before enough information is available, the result is difficult to review and may increase risk. The first principle of a plugin-based design is therefore:

    It is better to ask more questions than to reach a conclusion too early.

    A consultation workflow can be divided into several pluggable stages:

    • Identity and basic information collection
    • Chief complaint collection
    • Symptom and sign collection
    • Differential assessment
    • Candidate matching
    • Evidence verification
    • Final output review

    Each stage is provided by an independent plugin that defines its question set, option set, validation rules, and state-transition conditions. The core engine only maintains session state, invokes plugins, records audit events, and blocks transitions when the required conditions are not met.

    This design provides three immediate benefits:

    1. Structured input: Users see option cards instead of a long free-form questionnaire, while still retaining the ability to provide additional details.
    2. Constrained execution: Missing information at any stage can be detected and trigger another round of questions instead of being inferred from conversational context.
    3. Traceable decisions: Every question, candidate match, and evidence check is recorded as an event for replay, testing, and human review.

    2. Plugin Protocol and State-Machine Design

    A plugin architecture needs a stable protocol. At minimum, a domain workflow plugin should declare:

    • Plugin identifier and version
    • Applicable workflow stage
    • Input schema
    • Output schema
    • Error codes
    • Timeout policy
    • Audit event types
    • Knowledge-base dependencies and versions

    The core engine discovers plugins through a registry, invokes them through a capability gateway, and controls stage transitions through a state machine.

    The workflow can be represented with pseudocode like this:

    1. // Illustrative pseudocode: expresses workflow constraints only
    2. state = loadSession(sessionId)
    3. on consult(stage):
    4. require stage in ["intake", "symptoms", "signs"]
    5. plugin = registry.resolve(stage)
    6. questions = plugin.buildQuestions(state)
    7. answers = ui.askAsOptionCards(questions) // Option cards + free-form details
    8. state.merge(answers)
    9. audit.record("consult", stage, answers)
    10. return nextStage(state)

    The key point is not to maximize the number of stages. Each stage needs clear entry and exit conditions. For example:

    • Incomplete basic information should block entry into the differential stage.
    • An unclear chief complaint should block candidate generation.
    • Failed evidence verification should block final output.

    Transition rules should be written as testable conditions rather than scattered across natural-language prompts.

    Plugins should also be separated by responsibility, including:

    • Question-set plugins
    • Knowledge-matching plugins
    • Evidence-verification plugins
    • Output-review plugins
    • Interaction-rendering plugins

    This separation allows the interaction layer to be replaced, knowledge bases to be versioned, evidence sources to be changed, and safety policies to be upgraded independently while the core orchestration logic remains stable.

    3. Option-Based Interaction: Lower Input Cost, Higher Information Density

    One major challenge in domain consultation is that users may not know how to describe their situation. Asking users to freely type “What feels wrong?” often produces vague, incomplete, or highly colloquial answers. Long questionnaires, on the other hand, can lead to abandonment.

    Option cards provide a practical compromise. Common symptoms, signs, timelines, and special-population information can be represented through multiple-choice options, single-choice options, and range selectors, while users can still add free-form details.

    For example, chief-complaint collection can combine multiple selections with an additional description field. The symptom and sign stage can then include:

    • Multiple-choice symptoms
    • Tongue appearance options
    • Pulse-related options
    • Temperature, blood pressure, and pulse ranges
    • Direct numeric input

    Every question should also include options such as “Skip,” “Not sure,” and “Other,” so users are not forced to make inaccurate selections.

    Three interaction principles are important:

    • Separate multiple-choice and single-choice questions: Symptoms are often suitable for multiple selection, while differential factors and candidate plans may require a single selection. Mutually exclusive decisions should not be presented as multiple-choice questions.
    • Support both ranges and numeric values: Temperature, blood pressure, and pulse should offer predefined ranges while also allowing exact values for later validation.
    • Do not let free-form text replace structured fields: Free-form input should be retained for audit and human review, but it should not bypass structured-data gates.

    Option-based interaction does not simplify domain judgment. It makes the information required for that judgment explicit. Users see cards, while the engine receives structured fields that can support consistent matching and evidence verification.

    4. Differential Gates: Continue Asking When Confidence Is Low

    The differential stage is where premature conclusions are most likely to occur. To prevent this, plugins should include configurable confidence thresholds.

    For example, the workflow may withhold a candidate when:

    • The number of matched primary symptoms is insufficient.
    • The highest match score is below 60%.
    • The score gap between the top and second candidate is below 8%.
    • In high-match scenarios, the required gap may be tightened to 4%.

    Automatic follow-up should be limited to a maximum of three rounds to prevent an endless loop.

    1. candidate = matchSyndrome(state.structuredAnswers)
    2. if candidate.primaryHit < config.minPrimaryHit
    3. or candidate.topScore < config.minTopScore // Example: 0.60
    4. or (candidate.topScore - candidate.secondScore) < config.margin:
    5. if state.differentialRounds < config.maxRounds: // Example: 3
    6. return askNextDifferential(state, candidate)
    7. else:
    8. return {status: "insufficient", reason: "information_gap"}
    9. return {status: "candidate_ready", candidate: candidate}

    The important design decision is to treat “insufficient information” as a normal state rather than an error. The tool should clearly tell the user that more information is required instead of producing an uncertain conclusion through vague language.

    Thresholds should be configurable so domain experts can adjust them for different scenarios. The number of follow-up rounds should be bounded so the workflow can always exit. Each round should record both matched factors and information gaps for later evaluation.

    5. Three Gates: Matching, Evidence, and Output Review

    Even when the differential stage produces a candidate, the system should not generate the final result immediately. A safer design uses three independent gates:

    1. Pattern-and-candidate matching gate: The candidate must match the collected structured information and meet the required confidence threshold.
    2. Evidence verification gate: The candidate must have traceable support in a classical literature repository or a public medical literature database. If the evidence cannot be verified, the system must reject the output and return alternative candidates.
    3. Output review gate: Before final generation, the system rechecks the match, evidence status, special-population information, dosage-conversion rules, and risk notices.

    The logic can be represented as follows:

    1. if not matchGate.pass(state, candidate):
    2. return reject("match_gate_failed", alternatives)
    3. evidence = evidencePlugin.verify(candidate, state)
    4. if evidence.verdict != "supported":
    5. return reject("evidence_gate_failed", alternatives)
    6. final = prescribePlugin.recheck(candidate, evidence, state)
    7. if not final.pass:
    8. return reject("prescribe_gate_failed", alternatives)
    9. return final.outputWithSafetyNotice()

    If any gate fails, the system must not produce the final result. When evidence is insufficient, the workflow should return to the differential stage instead of allowing the model to invent a justification.

    This rollback mechanism is a major difference between a plugin-based workflow and ordinary conversational generation. In the plugin workflow, rejection, rollback, and alternative candidates are first-class capabilities. In a conventional text-generation flow, uncertainty is often expressed only through wording.

    6. Evidence-Based Defense and Traceable Correction

    A domain tool needs two capabilities when its conclusion is questioned: it must present supporting evidence when the conclusion remains valid, and it must roll back immediately when an error is found.

    A “defense” plugin can accept a candidate and the user’s challenge, then produce one of two outcomes:

    • Supporting response: List the literature source, original passage, evidence identifier, matched fields, and reasoning chain to explain why the candidate remains valid.
    • Corrective rollback: If evidence is insufficient, fields conflict, or a special-population contraindication is detected, mark the original conclusion as invalid, return alternative candidates, and trigger a new differential assessment.

    This is not open-ended model debate. It is an auditable action constrained by the evidence plugin. Every defense record should be logged with the input, evidence version, conclusion, and timestamp for later review.

    7. Security, Compliance, and Engineering Practices

    Domain consultation may involve health information, so security boundaries must be enforced by the engine rather than left only to prompts. At a minimum, the system should implement the following controls:

    • Disclaimers and role boundaries: Clearly state that the tool is intended for learning and assistance, and that its output does not replace an in-person consultation or a prescription from a licensed clinician.
    • Special-population markers: Pregnancy, postpartum status, breastfeeding, childhood, and older age should be represented as structured fields and trigger additional review.
    • Dosage and toxic-substance rules: Dosage-conversion logic, toxic-substance warnings, and contraindication rules must be reviewed by domain experts and configured explicitly. They must not be freely generated by the model.
    • Privacy and de-identification: Collect only the data required for the session, de-identify logs, apply role-based access controls, and support data expiration and cleanup.
    • Auditing and replay: Record plugin versions, knowledge-base versions, evidence versions, threshold parameters, and user selections to support issue reproduction.
    • Testing and gradual rollout: Build golden-path tests, boundary tests, and adversarial tests. Release plugin updates gradually before enabling them broadly.

    From an engineering perspective, the core engine should remain thin and plugins should remain replaceable. Interaction rendering, question sets, knowledge matching, evidence verification, and output review should each be versioned independently.

    Thresholds, round limits, evidence sources, and risk notices should all be configurable. This allows domain experts to maintain rules while developers can extend the system with new workflows through the registry.

    Conclusion

    The value of “everything as a plugin” is not the architectural slogan itself. It is the ability to make the variable parts of a domain workflow explicit, testable, and auditable.

    For domain consultation:

    • Option-based interaction improves information collection.
    • State machines enforce workflow constraints.
    • Confidence gates prevent premature conclusions.
    • Three independent gates improve evidence and output safety.
    • A defense mechanism enables traceable correction and rollback.

    The result is not simply a tool that chats more naturally. It is an executable, reversible, and reviewable domain workflow.

    The same approach can also be applied to customer support, operations diagnosis, compliance review, and other scenarios where the system must clarify the situation first, make a decision second, and produce an output only when supporting evidence is available.