Skip to main content

In-process plugin

Goal: add an in-process plugin that the engine discovers and resolves through a port.

Everything the engine talks to is a plugin: model providers, stores, sandboxes, forges, tools. The engine is a standalone component. It never imports a plugin: it discovers one and speaks through a port. Removing a plugin never breaks the engine build.

Prerequisites​

  • A Python package the engine's environment can import.

Steps​

  1. Add one entry point in the group afe.plugins to your Python package. The engine discovers every installed entry point at startup, and registers the ports the plugin declares.

    # pyproject.toml
    [project.entry-points."afe.plugins"]
    afe-models = "afe_plugins.models:PLUGIN"
  2. Implement the plugin. describe returns a PluginDescriptor, and resolve returns the implementation for a port and name.

    from afe_sdk.plugin import PLUGIN_API, PluginDescriptor, PortSpec

    class MyPlugin:
    def describe(self):
    return PluginDescriptor(
    name="my-plugin",
    api_version=PLUGIN_API,
    ports=[PortSpec(port="models", name="my-provider")],
    )

    def resolve(self, port, name):
    return MyProvider()

    PLUGIN = MyPlugin()
  3. To ship a node type, declare it under the nodes port. config_schema is the JSON Schema of the keys a manifest gives that node, and it is required. Return the spec from describe, in ports, so the engine registers the node type. Declare every key at the root properties, or as a root patternProperties pattern. Constraints may live in $ref, allOf or a conditional branch, but a key not declared at the root is an unknown key.

    from afe_sdk.node import NodeReply, NodeRequest
    from afe_sdk.plugin import PortSpec


    class TemplateNode:
    async def run(self, request: NodeRequest) -> NodeReply:
    return NodeReply(artifact={"text": request.options["template"]})


    SPEC = PortSpec(
    port="nodes",
    name="template",
    config_schema={
    "type": "object",
    "properties": {"template": {"type": "string"}},
    "required": ["template"],
    },
    )

    The engine refuses a nodes port without a config_schema, and names the plugin. It hands the node a NodeRequest: its own keys in options, and only the artifacts it declares in reads in artifacts. The request also names the ticket, the flow, the node, the round and the activation. writes and output_schema name the artifact the node must return, and its JSON Schema. The node returns that artifact in NodeReply.artifact.

  4. To ship tools, declare them under the toolsets port. resolve returns a ToolSet, whose tools lists the tools the plugin offers.

    from afe_sdk.tool import Tool


    class Words:
    async def tools(self) -> list[Tool]:
    return [Count()]

    toolsets is not the tools port. tools lists the tools of an MCP server, and a toolsets source is a plugin. In an agent, cite these tools as plugin:<source>.<tool> or plugin:<source>.*.

Notes​

apiVersion is the manifest version (afe.dev/v1alpha1). A different major version is refused with a clear error, and so are two plugins on the same (port, name).

Once the plugins are loaded, afe run, afe serve and afe worker check the configuration against them. An unknown node type or plugin tool stops the command before any ticket starts. So does an unknown key of a plugin node, or a value of the wrong type. The command lists every problem it finds. afe validate loads no plugin, so it keeps a plugin node type as a warning.

A plugin node type cannot use the engine's own node field names. agent, run, message, actions, requireComment, attachFiles, uses, with, over, lane, itemAs, maxItems and maxParallel are filled by the engine. They never reach the plugin.

Troubleshooting​

A message about a manifest starts with the manifest's location. For example: config.yaml#8: spec.nodes.heading.tempalte: unknown key.

plugin 'my-plugin' speaks afe.dev/v2alpha1, the engine speaks afe.dev/v1alpha1 describe returned an api_version with a different major version than the engine's PLUGIN_API. Match your plugin's major version to the engine you install it against.

port models/my-provider is provided by both 'afe-models' and 'my-plugin' Two installed plugins declare the same (port, name). Rename your plugin's port name, or remove the other plugin.

plugin 'my-plugin' has no 'describe' or has no 'resolve' The class assigned to PLUGIN is missing one of the two required methods. Both describe and resolve must exist on the object registered at the entry point.

spec.nodes.heading.type: no plugin provides the node type 'template' No installed plugin provides a nodes port named template. Install the plugin that ships the type, or correct the node's type.

spec.nodes.heading.tempalte: unknown key tempalte is not a key the node type declares in the root properties of its config_schema. The engine checks unknown keys there even when the plugin schema has no additionalProperties: false. Correct the key, or add it to the root properties.

spec.nodes.heading.message: a built-in node key, not available to a plugin node type message is one of the engine's node fields. The engine fills it and never passes it in options. Rename the key in the node type's config_schema and in the flow.

spec.nodes.heading: plugin node type 'template': invalid config_schema: … The schema the plugin declares is not valid JSON Schema. The text after the colon is the schema library's own. Correct the config_schema the plugin returns in describe.

spec.nodes.heading.template: 3 is not of type 'string' The value does not match the type the plugin declares for template. The text after the colon is the schema's own. Correct the value.

plugin:words.count: no plugin provides toolsets/words (known: none) No installed plugin provides a toolsets port named words. Install the plugin that ships the toolset, or correct the reference. A plugin:<source>.<tool> also fails when the source exists but its tools() list has no such tool.

See also​