Plugin-Driven Consultation Workflow Engine: Design and Practice
This article describes the design of a plugin-based consultation workflow engine for compliance-heavy domains. The core engine is responsible only for contracts, orchestration, state transitions, and security boundaries, while domain capabilities are delivered as independently testable plugins that obey a unified contract. It walks through the architecture, the plugin contract, state-machine orchestration with information, matching, and evidence gates, option-based interaction, structured evidence verification, and the security and observability requirements needed to keep consultation outputs traceable and auditable.
Why “Everything as a Plugin” Is Necessary
In knowledge-intensive, compliance-heavy domains such as healthcare, legal consulting, and financial risk control, intelligent assistance systems face a common contradiction: domain knowledge changes quickly and workflows vary widely, while the core engine must remain stable, auditable, and controllable.
If all domain logic is hard-coded into the main workflow, the system quickly becomes difficult to maintain. If plugins are allowed to do whatever they want, the system risks permission overreach, missing evidence, and untraceable outputs.
The value of an “everything as a plugin” architecture is that the core engine only handles protocol, orchestration, state, and security boundaries. Domain capabilities are attached as plugins. Plugins can be iterated, tested, and canary-released independently, but they must follow a unified contract.
Taking a traditional Chinese medicine classical formula consultation as an example, intake collection, syndrome differentiation, literature verification, and prescription suggestions can be built as separate plugins or as different phases of the same plugin. If any stage does not have enough information, the system should return “continue asking” instead of giving a premature conclusion.
This type of system should be positioned as a learning and assistance tool. Its output is not a substitute for an in-person consultation or a licensed practitioner’s prescription. Pluginization does not lower safety requirements. It moves those requirements into the engine and the contract, making them enforceable engineering constraints.
Architecture Overview: Core Engine and Plugin Contract
A practical plugin-based consultation workflow engine usually includes these modules:
- Plugin registry: manages plugin IDs, versions, capability declarations, permission scope, and signature information.
- Workflow orchestrator: maintains the state machine and decides the current stage, next stage, rejection path, and rollback path.
- Context store: saves collected consultation answers, candidate plans, evidence verification records, and audit logs.
- Evidence service: connects internal knowledge bases and external public literature retrieval services, returning traceable verification conclusions.
- Security and audit: enforces least privilege, sandbox isolation, second confirmation for sensitive operations, log archival, and monitoring alerts.
The plugin contract should clearly define what a plugin can do, what it cannot do, and what structure it must return. Here is a simplified pseudocode representation:
PluginContract:idversionstagesask(stage, context) -> QuestionCard[]differentiate(context) -> Candidate[]checkEvidence(candidate) -> EvidenceVerdictprescribe(context) -> Prescription | Rejection
In this design, Rejection is not an exception. It is a normal business result and must include the rejection reason, missing information, optional alternative paths, and the next action. This allows the frontend to render interactions such as “continue asking”, “try another plan”, or “supplement evidence” in a stable way, instead of exposing an error to the user.
State Machine Orchestration: Ask First, Differentiate, Then Prescribe
The consultation flow is well suited to an explicit state machine. A typical state transition looks like this:
INTAKE -> SYMPTOMS -> SIGNS -> DIFFERENTIATE -> EVIDENCE -> PRESCRIBE^ ||---- reject ----|
Each state does one thing: collect, match, verify, or output. The state machine should support rollback and supplementation. For example, if the user notices a missing symptom during the differentiation stage, the flow can return to symptom collection. If evidence verification fails, the flow should return to the candidate list rather than terminating the session.
Three gates are encoded in the orchestrator:
- Information gate: when basic information, chief complaint, symptoms, tongue presentation, pulse presentation, and other key fields are incomplete, the system returns only the next round of questions.
- Matching gate: when key symptom coverage is insufficient, the highest matching score is below the threshold, or the score gap between the first and second candidates is too small, the system does not provide candidate options. It returns differential questions instead. For example, the system can be configured to keep asking when the highest match score is below 60%, or when the score gap is below 8% (4% in high-match cases), with at most three automatic follow-up rounds.
- Evidence gate: every candidate plan must pass literature verification. If the verdict is not “supported”, the prescription output plugin rejects the plan and returns alternatives so that the workflow goes back to the differentiation stage.
The simplified orchestration logic is:
if not intakeComplete(ctx):return askNext(ctx)candidates = differentiate(ctx)if candidates.maxScore < 0.60 or candidates.gap < gapThreshold:return askDifferential(ctx, maxRounds=3)verdict = checkEvidence(candidates.first)if verdict != SUPPORTED:return Rejection(reason="evidence_missing", alternatives=candidates)return prescribe(ctx)
The key principle is: rather than concluding too early, ask more questions. When information is insufficient, the tool should simply say “continue asking” instead of using fluent language to hide an evidence gap.
Option-Based Interaction: Reduce Ambiguity, Preserve Free Input
Free-text questionnaires create ambiguity, produce loosely structured data, and make downstream matching unstable. Option cards are better suited to strong-flow scenarios.
Symptoms, body temperature, blood pressure, pulse, tongue presentation, pulse condition, differentiation points, and candidate plans can all be presented as multi-select, single-select, range-select, or numeric-input cards. The frontend shows cards instead of a large block of text that the user must organize by themselves.
Three design points matter:
- Options should cover common cases while still keeping an “other / free input” entry.
- Multi-select groups should control information density on a single screen to avoid user fatigue.
- The flow should support rollback and modification, and all changes should be written into the context for later review.
Evidence Verification and “Evidence Defense”
Evidence verification should return structured conclusions: supported, unsupported, or uncertain.
- When supported, the result includes traceable literature sources and unique identifiers.
- When unsupported, the result explains what is missing.
- When uncertain, the result specifies what additional information is needed.
For controversial plans, the system can provide an “evidence defense” mechanism. If the system or the user insists on a particular view, it lists the original textual evidence and literature identifiers. If an error is found, the system revises the plan immediately and records the reason for revision.
Security, Permission, and Observability
High-risk actions should require separate authorization.
Ordinary plugins can only provide suggestions. The prescription output plugin needs additional permission and second confirmation. Plugins should run in a sandbox, follow the least-privilege principle, validate signatures and versions before installation, and write runtime audit logs.
When deployed on a general cloud platform, audit archives can be stored in object storage, runtime logs can be collected by a log service, and monitoring alerts can be used to observe rejection rates and abnormal fluctuations.
Testing should cover golden cases, rejection cases, missing-evidence cases, and adversarial inputs. The system should also be continuously evaluated on follow-up round count, rejection rate, evidence coverage, and consistency with human review.
