Memory Capabilities for AI Agent Plugins: Implementation and Installation Guide

    This article explains how to add persistent memory to stateless AI agents through a plugin architecture. Using a motion memory plugin as an example, it covers the three-layer design of a memory core plugin, an optional settings UI plugin, and reusable pure-function modules; provides a manual installation workflow and a model-assisted installation option; and summarizes common troubleshooting steps. The same pattern can be applied to other utility plugins.

    1. Background and Requirements

    In AI agent development, a common issue is that the model itself is stateless: after each session ends, context generated in the previous interaction is lost. To enable an assistant to “remember” user preferences, historical operation sequences, or task execution trajectories, a common approach is to introduce an external memory mechanism at the framework layer. This mechanism provides a set of memory read/write tools through a plugin, which the model can call as needed during a conversation.

    This article uses a “motion memory” plugin as an example. This is a memory module that records an agent’s action sequence and state changes during task execution. The article outlines the engineering implementation approach, directory organization, and two typical installation and integration workflows for this type of plugin. The same approach also applies to other utility plugins, such as settings UI plugins and pure-function modules.

    2. Plugin System Design

    A well-structured memory plugin system usually consists of three parts.

    2.1 Memory Core Plugin (Main Plugin Entry)

    This is the functional core of the plugin. It registers a set of memory tools with the agent framework, usually with a unified tool name prefix, such as memory_ for read/write, query, and cleanup tools. The core plugin generally exists as a single script file and handles the following internally:

    • Tool definition and registration: declare each tool’s name, parameter structure, and invocation logic.
    • Data persistence: write memory content to local storage, such as a JSON file or a lightweight database.
    • Lifecycle management: initialize and release resources when the framework starts and shuts down.

    2.2 Settings UI Plugin (Optional Interaction Layer)

    To let users visually manage memory data, such as viewing, editing, and deleting memory entries, a companion settings UI plugin can be developed. This type of plugin usually includes server-side logic and a client-side script. The client part often needs to be loaded as a package, so its directory structure should mimic a standard Node.js package structure, including files such as package.json.

    2.3 Pure-Function Module Layer

    Generic capabilities unrelated to business logic, such as serialization, deduplication, and similarity calculation, can be extracted into pure-function modules in a separate directory for reuse by the core plugin. This makes unit testing easier and reduces coupling in the core plugin.

    The recommended directory organization is as follows:

    1. plugins/
    2. ├── motion-memory.js # Memory core plugin
    3. ├── mm-settings/ # Settings UI plugin
    4. │ ├── index.js
    5. │ ├── client.js
    6. │ └── package.json
    7. └── motion-memory-modules/ # Pure-function modules
    8. └── ...

    Manual installation is fully controllable and makes troubleshooting easier. It is recommended for initial integration.

    Step 1: Obtain the Plugin Files

    Obtain the complete plugin directory from the plugin’s release source. Use an approved official channel recognized by your team or platform, and confirm that it contains the three parts described above.

    Step 2: Place the Plugin in the Framework’s Plugin Directory

    Copy the plugin content into the plugins directory corresponding to the profile of the agent framework, referred to below as a DSH-like framework. Preserve the directory hierarchy.

    Step 3: Handle Settings UI Plugin Loading

    Because the settings UI client script is usually loaded according to a package structure, the framework must be able to resolve it from node_modules. There are two common methods.

    Method A (recommended on Windows): use a directory junction to avoid synchronization issues caused by copying files:

    1. mklink /J "your-profile\node_modules\mm-settings" "your-profile\plugins\mm-settings"

    A directory junction means that both paths point to the same physical files, so there is no need to copy the plugin again when updating it. On Linux or macOS, an equivalent symbolic link command can achieve the same effect.

    Method B: copy the entire mm-settings directory into the node_modules directory. This method is simple and direct and is suitable for quick verification. However, when the plugin is updated, it must be copied again, which can result in two inconsistent copies.

    Step 4: Enable the Plugin in the Configuration File

    Declare the plugins to be loaded in the profile’s cordis.patch.yml configuration file:

    1. - insert:
    2. - id: motion-memory
    3. name: ./plugins/motion-memory.js
    4. - id: mm-settings
    5. name: mm-settings

    There are two points to note here. The core plugin uses a relative path that points directly to the script file. The settings UI plugin has already been placed in node_modules, so its package name can be used directly for resolution.

    Step 5: Restart and Verify

    Restart the framework after completing the steps above. After a successful restart, memory tools (the tool set with the memory_ prefix) and the settings UI are registered automatically. You can ask the assistant in a conversation to call a memory tool, or check whether the settings UI loads properly, to verify the installation.

    4. Approach 2: Automatic Installation via a Model Assistant

    When the framework is already running, you can also provide the installation instructions directly to the agent in the session. The assistant can then follow the steps to download files, place files, create links, and modify the configuration. The applicable scenarios and cautions are as follows:

    • Applicable scenarios: the environment is inconvenient for manual operations, you want to complete deployment quickly, or you need to reuse the same installation workflow across multiple profiles.
    • Cautions: after automatic installation, the framework still needs to be restarted for the changes to take effect. After installation, manually spot-check file locations and configuration contents to avoid overlooking path errors or configuration format issues.

    5. Troubleshooting

    1. Tools not registered: Check whether the id and name in the configuration file match the actual file paths. Confirm that the plugin script has no syntax errors by checking load errors in the logs.
    2. Settings UI fails to load: In most cases, the corresponding package structure is missing from node_modules. Confirm that the link or copy operation is complete and that the package.json file exists.
    3. Memory data lost: Confirm that the plugin has read/write permissions on the data write directory at runtime, and that the framework did not clear the data during restart.
    4. Symbolic link creation fails: On Windows, creating a directory junction usually does not require administrator privileges, but it may be restricted in some environments. In that case, use the copy method from Method B instead.

    6. Conclusion

    Pluginization is a standard way to extend the capabilities of an agent framework. With a three-layer structure consisting of a core plugin, a settings UI, and pure-function modules, memory capabilities can be organized clearly. Developers can choose between manual placement and model-assisted installation based on their environment. After mastering this practice, readers can apply the same pattern to the development and deployment of other utility plugins and continue expanding the capabilities of their AI assistants.