Setting Up An Adapter#

The entry point of an Adapter is the Adapter Plugin. The Plugin is where you will register ActionModules, Resources, HealthChecks, and manage your Adapter’s config.

To set up an Adapter Plugin, you’ll need to include following two files in the adapter/main directory of your development environment.

import asyncio
from artificial.adapter_common import Adapter
from artificial.config import Config
from .plugin import AdapterPlugin

if __name__ == '__main__':
    # Parse the yaml config file to pass to the Adapter
    config = Config.from_env()
    # Run the plugin, config))
from dataclasses import dataclass
from artificial.adapter_common import ActionModule, ActionModulePlugin, PluginContext, action_modules, plugin_config

# Define the Adapter config schema
# Typically this will be in a separate file (e.g.
class AdapterConfig:

# Define an action module
# Typically this will be in a separate file (e.g.
class MyActions(ActionModule):

# Mark the Action Module for inclusion in the Action Stub generation process
class AdapterPlugin(ActionModulePlugin):
    # Register the config data class to be used for this adapter
    cfg = plugin_config(AdapterConfig)

    async def setup(self, pctx: PluginContext) -> None:
        # Register the action module


To make the Actions in an Action Module available to be called from a Workflow, you’ll need to register the Action Module with the Adapter Plugin. To do this, override the setup method and call the add_module method for each Action Module you want to register. You’ll also need to add the Action Module as a parameter to the @action_modules decorator to make sure it’s included in the Action Stub generation process.

Monitor System Health#

Artificial automatically monitors the health and connectivity of the overall Adapter and shows it in the LabOps UI. You may find it valuable to add additional health checks for various sub systems in your lab to help you get a clearer picture into your system status.

To add health checks, you’ll use add_monitor.

from artificial.adapter_common.plugin import ActionModulePlugin, PluginContext, action_modules
from artificial.adapter_common.apis import Health
from .actions import MyActionModule

class MyAdapterPlugin(ActionModulePlugin):
    async def setup(self, pctx: PluginContext):

        # Add a health check'my_health_check', self.my_health_check)

    async def my_health_check(self) -> Health.Message:
        # Check the health of your system
        return Health.ok()

Configuring the Adapter#

You can access the Adapter’s config using plugin_config.

from artificial.adapter_common.plugin import ActionModulePlugin, PluginContext, action_modules, plugin_config
from .actions import MyActionModule

# Adapter config schema is defined as a dataclass
class MyAdapterConfig:
    username: str
    password: str

class MyAdapterPlugin(ActionModulePlugin):
    # Pull in adapter configuration
    cfg = plugin_config(MyAdapterConfig)

    async def setup(self, pctx: PluginContext):
        # Pass the config to the Action Module.
        # The ActionModule __init__ must accept the config as a parameter.