Agent Workflow Orchestration with an Everything-as-a-Plugin Architecture

    This article presents a reusable design approach for building controllable AI agents based on an everything-as-a-plugin architecture. It explains how to split an agent into four layers (interaction, orchestration, capability plugins, and governance), how to encode design principles such as "ask more, conclude later" into a state machine through coverage, confidence, and margin gates, and how to decouple evidence retrieval from output generation to reduce hallucination risk. It also covers structured option-based interaction, a defense plugin for handling challenges, built-in safety and compliance boundaries, and practical suggestions for starting from a minimal closed loop.

    1. The Starting Point: Why More Capable Agents Are Harder to Control

    As agent applications spread quickly, a common pattern emerges: the stronger the capabilities, the harder the output is to constrain. When a model is free to improvise, the biggest concern for business teams is often not that it cannot do the task, but that it skips steps, acts on intuition, or states uncertain conclusions as definitive facts.

    The everything-as-a-plugin architecture is essentially an engineering response to this uncertainty: it breaks an agent’s capabilities out of a long prompt into several units with clear boundaries that can be tested and replaced independently; and it changes business flows from “the model decides freely” to “a state machine drives the process explicitly.” From a general technical perspective, this article provides a reusable design method.

    2. Architecture Overview: A Four-Layer Breakdown

    A robust plugin-based agent can usually be split into four layers:

    • Interaction layer: Collects structured input through option cards, forms, and lists, so users do not face large blocks of free text.
    • Orchestration layer: A state machine and flow engine that decide what to ask next and whether the process can move to the next stage.
    • Capability plugin layer: Consultation, differentiation, evidence verification, output generation, and other functions are independent plugins, each declaring its input and output contracts.
    • Governance layer: Permissions, auditing, traceability, disclaimers, and compliance checks cut across all plugins.

    A sample plugin contract can be written as:

    1. {
    2. "name": "differentiate",
    3. "input": ["symptoms", "signs", "intake"],
    4. "output": ["candidates", "next_questions"],
    5. "gates": ["coverage", "confidence", "margin"],
    6. "on_fail": "ask_more"
    7. }

    The value of contracts is that the orchestration layer does not need to know how a plugin is implemented internally; it only needs to know under what conditions the plugin is allowed to pass.

    3. Flow Gates: Encoding “Ask More, Never Conclude Early” into the Engine

    The most useful part of the original practice is writing design principles into the engine rather than only into the prompt. This can be abstracted into three independent gates:

    1. Information completeness gate: Do not enter the conclusion stage when coverage of the main symptoms is insufficient.
    2. Confidence gate: Refuse to give a conclusion when the top candidate match is below a threshold (for example, 60%).
    3. Margin gate: Keep asking when the gap between the first and second choices is too small (for example, below 8%, relaxed to 4% in high-match scenarios).

    Expressed as pseudocode:

    1. if coverage < MIN_COVERAGE or top1 < 0.60 or (top1 - top2) < 0.08:
    2. return {"action": "ask_more", "questions": next_questions(stage)}
    3. return {"action": "propose", "candidates": ranked}

    The key point is that follow-up rounds must have a limit (for example, three automatic follow-ups) to avoid infinite loops; and every follow-up round must be carried by an option list to reduce input noise.

    4. Evidence-Driven: Retrieve First, Then Allow Output

    The second independent gate is evidence verification. The general approach is to decouple knowledge retrieval from conclusion generation: the retrieval plugin only returns verifiable items and source identifiers, and the generation plugin is allowed to produce final content only when the retrieval verdict is “supported”; otherwise, it refuses directly and falls back to the previous stage.

    1. evidence = search(kb, query) # returns supported / unsupported
    2. if evidence.verdict != "supported":
    3. return {"action": "revise", "alternatives": candidates}
    4. return prescribe(evidence)

    This three-stage retrieve-judge-generate pattern can significantly reduce the business risk caused by hallucinations and makes every output traceable.

    5. Interaction Design: Replace Long Questionnaires with Option Cards

    Structured interaction is a natural partner for a plugin-based architecture. Making symptoms, signs, differentiation points, and candidate options selectable lets users complete input by clicking; free text serves only as a supplement. This brings three benefits: input can be validated, the flow can be measured, and results can be reproduced.

    Recommended interaction patterns:

    • Single-point collection: Ask about only one group at a time to avoid cognitive overload.
    • Multi-select plus supplement: Use multi-select to cover common categories for the chief complaint, then open a supplement box.
    • Range plus value: For temperature, blood pressure, pulse, and similar items, provide both range options and a field for numeric values.

    6. A Defense Plugin for Handling Challenges: Stand Firm or Admit Error

    A mature system should be able to respond to challenges. You can design an independent defense plugin: when challenged, it either provides the original basis and verifiable identifiers, or immediately revises the conclusion when evidence is insufficient. This plugin is also constrained by the governance layer, and any revision must be logged.

    7. Safety and Compliance: Boundaries That Must Be Built In

    Any assistant tool aimed at a professional domain should have built-in disclaimers and boundary constraints: state clearly that it is for learning and assistance, cannot replace offline professional judgment or the formal opinion of a licensed practitioner; and when high-risk ingredients or dosage conversions are involved, it must prompt users to proceed under the guidance of a professional. Technically, this can be injected uniformly through the governance layer rather than relying on the model’s own discretion.

    8. Implementation Suggestions: Start from a Minimal Closed Loop

    • Define the state machine and stage enumeration first, then write plugins.
    • Every plugin needs a contract, thresholds, and a failure fallback.
    • Keep interaction structured, and cap follow-up rounds.
    • Decouple evidence verification from generation, and make output verifiable.
    • Let the governance layer handle permissions, traceability, and disclaimers uniformly.

    9. Conclusion

    Everything-as-a-plugin does not mean piling features into a wall of plugins; it means using contracts, gates, and an evidence chain to lock uncertainty into a testable cage. When the flow is driven by a state machine, conclusions are supported by evidence, and interaction is carried by options, an agent is truly qualified to enter serious scenarios.