Agent Workflow Orchestration with an Everything-as-a-Plugin Architecture
This article explains how an everything-as-a-plugin architecture makes AI agent workflows controllable, testable, and auditable. It covers a three-layer design of orchestration engine, capability plugins, and gates; structured option-card input; confidence thresholds that trigger follow-up questions instead of premature conclusions; evidence gates that block prescription generation without verifiable sources; a defense plugin that can be challenged; and engineering practices for observability, canary rollout, and governance. A classical-formula assistant scenario is used as the running example for learning and research only.
Agent Workflow Orchestration with an Everything-as-a-Plugin Architecture
1. Why “Everything as a Plugin” Becomes Necessary for Complex Workflows
When agents move from being question-answering toys into real business processes, the biggest obstacle is not model capability but lack of process control: prompts keep growing, branching is guessed from natural language, outputs cannot be reproduced, and failures cannot be traced. “Everything as a plugin” essentially means decomposing capabilities, data, validation, and interaction into minimal units that are registrable, replaceable, and composable, with a deterministic orchestration layer owning state transitions. The model is responsible only for understanding and generation, while whether the flow may advance is decided by plugins and gates.
This architecture delivers three direct benefits. First, it is testable: every plugin has an explicit input/output contract. Second, it is replaceable: models, retrieval sources, and rule bases can be upgraded independently. Third, it is auditable: every state transition leaves a structured record. Take a classical Chinese medicine formula assistant scenario as an example (for learning and research purposes only; it does not replace an in-person consultation or a licensed practitioner’s prescription). The full chain can be abstracted as: intake record creation → symptom collection → formula-pattern differentiation → literature verification → prescribing or switching formulas → evidence-based defense. Each step is a plugin, and the flow may not advance if any step fails.
2. Overall Architecture: Decoupling Engine, Plugins, and Gates
A three-layer split is recommended. The first layer is the orchestration engine, which maintains the session state machine and a stage field, and handles invocation order, retries, and timeouts. The second layer is capability plugins, including interaction plugins, reasoning plugins, retrieval plugins, and validation plugins. The third layer is gates, which express business red lines as code rather than as prompts.
A sample plugin contract looks like this:
{"name": "jingfang_differentiate","stage": "differentiate","input": ["symptoms", "signs", "intake"],"output": ["candidates", "next_questions"],"gates": ["confidence_threshold", "coverage_check"],"timeout_ms": 8000,"retry": 1}
The engine only understands contracts and does not care about plugin internals. As a result, swapping the underlying model, switching the literature database, or adding rules for a new specialty requires no changes to the main flow.
3. Structured Interaction: Option Cards Instead of Long Questionnaires
The first pain point in real business is input quality. Having patients or frontline staff type long free-form text is both slow and noisy. A better approach is to compile questions into “option cards plus a few numeric inputs,” rendered and collected uniformly by the interaction plugin.
- Intake stage: 6 items in total — form of address, age, gender, chief complaint, disease duration, and special conditions (such as pregnancy, postpartum, or breastfeeding) — all single-choice or short fill-in.
- Symptom stage: multi-select across 9 categories of discomfort with free-form additions allowed; then a signs stage collects range options and exact values for body temperature, blood pressure, and pulse.
- Specialty scales: 12 tongue-image items and 13 pulse-image items, all single-choice to avoid ambiguity.
The value of structured input is that it can be validated: out-of-range values and internal contradictions (such as a chief complaint conflicting with the disease duration) can be intercepted directly inside the plugin, instead of handing dirty data to the model to “improvise” with.
4. Confidence Thresholds: Better to Ask More Than to Conclude Early
The formula-pattern differentiation plugin must have a built-in ability to abstain. At least three hard rules should take effect simultaneously: insufficient coverage of primary symptoms, a top match score below a threshold (for example 60%), and too small a gap between the first and second choice (4% for high matches, 8% in general). If any rule triggers, the plugin returns no candidate formulas; it returns only the next round of differentiation questions, and the number of automatic follow-up rounds is capped (for example, at most 3), after which the case is handed to a human.
if coverage < required or top1 < 0.60 or (top1 - top2) < margin:return {"action": "ask_more", "questions": next_batch, "round": r+1}else:return {"action": "propose", "candidates": topk}
This mechanism makes uncertainty explicit and prevents the model from producing plausible but wrong conclusions when information is insufficient.
5. Evidence Gates: No Prescribing Without Verifiable Sources
The prescribing plugin should not generate a prescription directly; it must first call the evidence plugin. The evidence plugin searches both built-in classical passages and a live public literature database, returning passage IDs, sources, and unique identifiers. The prescribing plugin re-verifies once more before issuing a formula, and the conclusion has only two states: supported and not supported. When not supported, it refuses outright, returns alternative directions, and the flow goes back to the differentiation stage.
Dosage and safety must also be written as rules: conversions are done conservatively at “1 liang = 3 grams,” and any formula containing toxic medicinal ingredients must be explicitly labeled as requiring use under a physician’s guidance. These constraints live in the validation plugin, so no model output can bypass them.
6. Evidence-Based Defense: Making the Agent Open to Challenge
A defense plugin facing challenges should support two actions: when the position holds, it outputs the original source basis and the unique literature identifier; when it is wrong, it retracts on the spot and triggers the formula-switching flow. In implementation, a cache of “claim–evidence–confidence” triples can be maintained and compared item by item during defense, avoiding on-the-spot fabrication.
7. Engineering Practice: Observable, Canary-Releasable, Governable
- Observability: every plugin invocation records an input summary, output, elapsed time, and gate conclusion, forming a replayable chain.
- Canary release: a new model or new rule is first enabled for a small share of sessions and regressed against the same evaluation set.
- Governance: a plugin registry manages versions and permissions centrally, and sensitive data is masked before entering logs.
- Cloud support: the plugin runtime can be hosted on Baidu AI Cloud’s container platform, with a message queue for asynchronous retrieval, object storage for masked corpora, and log and monitoring services for full-chain tracing and threshold alerting.
8. Conclusion
“Everything as a plugin” is not about chopping features into fragments; it is about locking uncertainty in a cage: interaction is structured, judgments have thresholds, prescribing has evidence, and errors can be rolled back. Only by writing red lines into the engine rather than into prompts can an agent run stably and auditably in professional scenarios.
