Everything-as-a-Plugin Architecture: Designing a Staged Intelligent Consultation Workflow

    This article explains how an everything-as-a-plugin architecture turns an AI assistant that can chat into a workflow engine that can enforce rules. It covers the four-layer design (interaction, orchestration, capability plugins, and governance), a staged consultation state machine, confidence thresholds that trigger follow-up questions instead of early conclusions, evidence verification with dual-source retrieval, and governance practices such as auditable state transitions, plugin versioning, and rollback. It also lists common pitfalls and shows how the same pattern applies to AI coding, code review, and operations workflows.

    Everything-as-a-Plugin Architecture: Designing a Staged Intelligent Consultation Workflow

    1. Background: Why “Being Able to Chat” Is Not “Being Able to Get Things Done”

    Over the past two years, the capability boundary of AI coding tools and AI assistants has kept expanding, from code completion to workflow orchestration. But when the scenario shifts from “generating a piece of text” to “completing a constrained task,” relying on prompts alone quickly exposes three weaknesses:

    1. Uncontrollable flow: the model may skip required steps and jump straight to a conclusion;
    2. Unverifiable conclusions: outputs lack traceable evidence and cannot be reviewed;
    3. Unenforceable boundaries: without hard interception points, out-of-scope output is hard to prevent.

    The everything-as-a-plugin approach moves “capability” out of the model and into an external, orchestrable plugin layer: the model only interprets intent and generates candidates, while flow advancement, gate checks, and evidence verification are handled by plugins. The direct benefit is that constraints are written into the engine, not just into prompts.

    2. Architecture Overview: A Layered Everything-as-a-Plugin Model

    A practical layered structure typically has four layers:

    • Interaction layer: converts open-ended questions into option cards to lower input cost;
    • Orchestration layer: manages the stage state machine and decides which plugin to call next;
    • Capability plugin layer: consultation, differentiation, evidence, and output plugins are independent and individually replaceable;
    • Governance layer: logging, auditing, permissions, versioning, and rollback.

    The key design principle is single responsibility plus explicit contracts. Each plugin declares its own input schema, output schema, and preconditions; the orchestration layer only schedules and carries no business rules.

    Illustrative plugin contracts (pseudocode):

    1. plugin jingfang_consult {
    2. input: { stage: "intake" | "symptoms" | "signs" }
    3. output: { questions: [OptionCard], state_patch: {...} }
    4. precondition: state.session_active == true
    5. }
    6. plugin jingfang_differentiate {
    7. input: { state }
    8. output: { mode: "ask" | "candidates", payload }
    9. guard: confidence >= threshold
    10. }

    3. Staged Consultation: Turning a Questionnaire into a State Machine

    The most valuable part of the original practice is reshaping “consultation” from a one-shot long questionnaire into multi-stage state advancement. The suggested stages are:

    1. intake (basic information): form of address, age, gender, chief complaint, course of illness, special circumstances (such as pregnancy, postpartum, or breastfeeding). The goal here is not to collect everything, but to establish a minimal usable context.
    2. symptoms / symptoms2 (symptom groups): mainly multiple choice, covering common categories of discomfort with free-form supplements allowed; also collects range options and numeric input for temperature, blood pressure, and pulse.
    3. signs (signs, tongue, and pulse): structured options for tongue and pulse presentation, avoiding the ambiguity of free-form user description.
    4. differentiate: first show a multiple-choice list of differentiation points, then a single-choice list of candidate formulas, with match scores and a formula-pattern summary.
    5. evidence (evidence verification): retrieves built-in classical text passages and a live literature library to form citable entries.
    6. prescribe (output): re-checks evidence status before a formula is allowed out.

    The value of the state machine is re-entrancy: if any step fails, the flow returns to a designated node instead of starting over.

    1. intake -> symptoms -> signs -> differentiate
    2. ^ |
    3. | v
    4. +------ evidence <---- prescribe

    4. Confidence Thresholds: Better to Ask More Than to Conclude Early

    The most overlooked yet quality-determining part of workflow design is when to refuse to answer. The thresholds can be written as explicit rules:

    • insufficient hits on the chief symptom;
    • the highest match score is below a configured threshold (for example 60%);
    • the gap between the top and second choice is too small (the threshold can tighten to 4% for high matches, and is 8% in general cases).

    If any condition triggers, the plugin does not return candidates; it returns the next round of differentiation questions, and caps the number of automatic follow-up rounds (for example 3 at most) to avoid infinite loops.

    1. if (top1 < 0.60 || (top1 - top2) < 0.08) {
    2. return ask_more(questions, max_rounds = 3);
    3. }

    This “refuse to prescribe” mechanism essentially makes uncertainty explicit instead of masking it with vague wording.

    5. Evidence-Driven: Output Only When Evidence Can Be Found

    The third independent gate is evidence. The design should ensure:

    • dual-source retrieval: a built-in classical text library plus live public literature retrieval;
    • citable: every conclusion carries a source identifier (such as a literature number);
    • secondary re-check: the output plugin re-validates evidence status and refuses outright when the status is not “supported,” returning alternative directions and sending the flow back to the differentiation stage.

    Expressed in pseudocode:

    1. if (evidence.verdict != "supported") {
    2. return { refuse: true, alternatives: [...] };
    3. }

    6. Interaction and Governance: Option-Based Input, Auditable, Rollback-Ready

    • Options first: present questions as option lists wherever possible to reduce typing and ambiguity;
    • Defense mechanism: when challenged, provide the original text and literature number if the answer holds, and revise the formula on the spot if it does not;
    • Auditable: record every state transition, threshold decision, and evidence reference for later review;
    • Versioning and rollback: plugins are versioned independently and can be rolled back individually when something goes wrong, without affecting the whole;
    • Safety boundaries: state clearly that output is for learning and assistance only and cannot replace an in-person consultation or a licensed prescription; force a prompt to use under professional guidance when special populations or toxic medicinal materials are involved; use conservative dose conversion and label the source.

    7. Implementation Advice and Common Pitfalls

    1. Do not stuff rules into prompts: prompts can be bypassed, engine checks cannot;
    2. Do not try to ask everything at once: staged collection is more stable, paired with a re-entrant state machine;
    3. Do not omit the refusal path: refusing to prescribe is the core of quality, not an exceptional branch;
    4. Do not confuse “smooth” with “sloppy”: option-based input improves smoothness, thresholds guarantee rigor;
    5. Do not ignore governance: logging, permissions, and versioning are prerequisites for long-term usability.

    8. Conclusion

    The real meaning of everything-as-a-plugin is to break a complex business into minimal capability units that are replaceable, verifiable, and composable, then chain them into a reliable flow with the orchestration and governance layers. In high-constraint scenarios like intelligent consultation, success is often determined not by how well the model expresses itself, but by whether the flow asks clearly first, differentiates next, and outputs only with evidence. The same methodology applies to scenarios that need to “advance with gates,” such as AI coding, code review, and operations handling.