Building a Pluggable AI Workshop: How to Create an Extensible Agent Environment from Scratch

    A practical guide to building a modular AI agent environment that can use tools, connect to external data, generate small plugins, and execute tasks with permission controls, observability, checkpoints, testing, migration, and recovery in place.

    1. Why “Being Able to Answer” Is Not Enough

    Large language models are good at generating text, but a single question-and-answer interaction cannot directly modify business data or leave an auditable record of what happened. When a task involves reading spreadsheets, calling APIs, modifying files, and repeatedly validating results, the model needs an execution environment to carry out these actions. This type of environment is commonly called an agent runtime framework. It converts model outputs into controlled operations and records the result of each step.

    An AI tool has entered the “workshop” stage when it provides four capabilities:

    1. Actionability: It can call tools to read, calculate, query, and write data.
    2. Observability: It records the inputs, outputs, execution time, and errors for every step.
    3. Replaceability: Model providers, data sources, and tools can be replaced independently.
    4. Extensibility: New capabilities can be added without modifying the core code.

    2. The Basic Layers of a Pluggable Architecture

    The central idea of a pluggable architecture is to divide functionality into independent units that the runtime loads and orchestrates. A typical structure includes the following layers:

    • Runtime core: Manages sessions, task scheduling, permission checks, and logging.
    • Services: Provide fundamental capabilities such as model calls, data storage, and file access, usually through standardized interfaces.
    • Tools: Specific operations that the model can choose to invoke, such as querying records, writing a row of data, or generating a report.
    • Plugins: Functional units that package services, tools, prompt templates, and configuration. They can be installed, disabled, or uninstalled independently.
    • Presets: Reusable configuration files that store plugin combinations, execution modes, task templates, and permission policies.

    This layered design creates clear boundaries. If the spreadsheet data source needs to be replaced, only the relevant tool plugin needs to change. Likewise, adding a course conflict checker does not require modifications to the runtime core.

    3. Designing a Replaceable Model Integration Layer

    Model providers change quickly, and different models vary in cost, response time, and output quality. A practical approach is to place an adapter layer between the runtime framework and the models, allowing upper-level code to depend on a consistent interface.

    The following pseudocode illustrates the structure:

    1. class ModelAdapter:
    2. def generate(self, messages, options):
    3. raise NotImplementedError
    4. class VendorAAdapter(ModelAdapter):
    5. def generate(self, messages, options):
    6. # Call a provider API and convert its response to a unified format
    7. ...

    When switching models, only the adapter name in the configuration needs to be changed. Business plugins do not need to be modified.

    To compare cost and performance, run the same set of test tasks with different models. Record token usage, execution time, and human evaluation scores for each call, then summarize the results in a table. The prompts, sampling parameters, and evaluation criteria must remain fixed; otherwise, the results are not comparable. For example, if the prompt is changed in two places during one test, any difference in performance cannot be attributed solely to the model.

    4. Connecting External Data Sources

    Many business records are stored in spreadsheets or databases. When connecting these data sources, consider the following practices:

    1. Separate reads and writes: Reading tools can be enabled by default, while writing tools should require explicit authorization.
    2. Return structured data: Tools should return clearly defined lists or objects rather than large blocks of text, making the results easier for the model and subsequent code to process.
    3. Validate inputs: Check whether required fields exist, whether date formats are valid, and whether numeric values fall within reasonable ranges. This prevents invalid data from entering later stages of the workflow.
    4. Provide complete tool descriptions: Document every parameter, the return structure, and possible failure conditions. The model relies on these descriptions to decide how to call a tool. Incomplete documentation can directly cause incorrect tool calls.

    Example:

    1. def read_rows(sheet_id, cell_range):
    2. # Return a list in which each element is a row represented as a dictionary
    3. ...

    5. Generating Small Plugins with Natural Language

    Suppose the workshop does not yet have a course conflict checker. The capability can be added through the following process:

    1. Describe the requirement: The input is a list of courses. Each course includes an ID, start time, end time, classroom, and instructor. If two courses taught by the same instructor or held in the same classroom overlap, the system should return conflict details.
    2. Generate the plugin: Have the model generate a minimal plugin containing the checking logic, input and output definitions, and test cases.
    3. Load and test: Load the plugin into the workshop and run the test cases.
    4. Fix failures: Modify the code based on failure messages until all tests pass.
    5. Disable or uninstall: When the capability is no longer needed, disable or uninstall the plugin to return the workshop to its previous state.

    The core checking logic is shown below. Time fields must use a format that can be compared directly.

    1. class CourseConflictCheck(Plugin):
    2. name = "course_conflict_check"
    3. def run(self, courses):
    4. conflicts = []
    5. for i, a in enumerate(courses):
    6. for b in courses[i + 1:]:
    7. same_teacher = a["teacher"] == b["teacher"]
    8. same_room = a["room"] == b["room"]
    9. overlap = a["start"] < b["end"] and b["start"] < a["end"]
    10. if (same_teacher or same_room) and overlap:
    11. conflicts.append({"a": a["id"], "b": b["id"]})
    12. return conflicts

    The tests should cover at least three situations:

    • No conflict
    • A conflict involving the same instructor
    • A conflict involving the same classroom

    They should also include a boundary case: if one course ends at 10:00 and another starts at 10:00, the two courses should not be considered to conflict. Boundary cases are easy to overlook and are among the clearest demonstrations of the value of testing.

    6. Permissions, Execution Traces, and Checkpoints

    These three mechanisms determine whether the workshop can be trusted.

    • Permission policies: Define read and write scopes for each plugin and tool, following the principle of least privilege by default.
    • Execution traces: Record the parameters, return values, execution time, and errors for every tool call to support review and auditing.
    • Checkpoints: Save intermediate state at important stages of long-running tasks so that execution can resume from the latest checkpoint instead of starting over after a failure.

    A plugin that writes data should also provide confirmation before writing, an operation log, and a rollback method. Without any one of these safeguards, errors become difficult to locate and repair.

    7. Migration and Recovery

    The value of a workshop lies partly in its ability to move its configuration and data as a unit. A migration package should generally include:

    • The plugin inventory and version numbers
    • Presets and permission policy files
    • Model configuration, excluding secrets; secrets should be injected through environment variables or a secrets management service
    • Test cases and execution records
    • Documentation describing dependencies and startup steps

    After migration, perform an actual recovery drill in the new environment. Confirm that the plugins can load, the tests pass, and execution traces are written correctly. Checking only whether the files exist does not prove that the workshop is operational.

    8. Suitable Use Cases and Important Considerations

    A pluggable workshop is well suited to repetitive tasks for individuals and small teams, such as organizing data, generating reports, and performing checks based on fixed rules. High-concurrency services, core business systems with strict compliance requirements, and systems that require strong consistency should be evaluated with dedicated engineering solutions. They should not rely directly on model-generated code in production.

    Start with one concrete, small task. First complete the full cycle of loading, testing, fixing, and uninstalling a plugin. Then gradually add more tools and plugins. Every new capability should be accompanied by additional test cases and an updated permission configuration.