Out-of-process plugin
Goal: declare a plugin written in another language and run it over stdio or HTTP.
Prerequisites
- The plugin's command or service, built and runnable from the worker.
Steps
-
Choose how the plugin runs: as a child process (stdio) or as a service (HTTP). Both speak JSON-RPC 2.0.
-
Declare it with the
Pluginkind, with the command that starts it and the environment variables it needs:apiVersion: afe.dev/v1alpha1kind: Pluginmetadata:name: my-pluginspec:transport: stdiocommand:- my-plugin- serveenv:MY_PLUGIN_LOG_LEVEL: "info" -
Run a flow. The engine calls
describeto learn the ports, then oneinvokeper port call. It is the same contract as an in-process plugin.
Ports over JSON-RPC
describe returns the descriptor. The invoke method calls one port method, named in the request.
- A
nodesport answersrunwith aNodeRequestand returns aNodeReply. - A
toolsetsport answerstoolswith{}and returns the list of tool specs. - A
toolsetsport answerscallwith{"name": <tool>, "args": <arguments>}and returns the tool's text.
A nodes request carries the node's own keys in options. It also carries the artifacts the node
declares in reads. 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. The
plugin returns it in NodeReply.artifact.
A tools reply lists each tool's name, description and input_schema. The call request
names one of those tools and passes its arguments. In an agent, cite these tools as
plugin:<source>.<tool> or plugin:<source>.*.
config_schema travels in the describe reply. The engine checks a plugin node's keys against it
before any ticket starts.
An exception in the plugin comes back as a JSON-RPC error with the plugin's message. For a node, the engine ends the ticket as failed with that message.
Examples
The two third-party packages under tests/third_party/ serve the same PLUGIN object over both
transports. They import only the standard library and afe_sdk.
acme_afe_template/__main__.pyserves anodesport.acme_afe_words/__main__.pyserves atoolsetsport.
Run one with python -m acme_afe_template for stdio. Add --http to print PORT=<n> and serve
HTTP instead.
Notes
A stdio plugin receives only PATH, HOME and the variables declared in its manifest. No
engine secret ever enters it. The env values reach the plugin as written: the engine expands no
variable. Exporting a secret in the engine's own environment does not forward it. The plugin, or
the launcher that starts it, loads its secrets from an uncommitted source, such as a .env file
outside version control.
The engine checks an out-of-process plugin like an in-process one. An unknown node type or plugin
tool stops afe run, afe serve or afe worker before any ticket starts. So does an unknown key
of a plugin node, or a value of the wrong type. A key is known only when the plugin declares it in
the root properties of its config_schema, or it matches a root patternProperties pattern.
Constraints may live in $ref, allOf or a conditional branch. The command lists every problem it
finds. A plugin node type cannot use the engine's own node field names, such as message or run:
the engine fills them and 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' did not start: [Errno 2] No such file or directory: 'my-plugin'
The command names a binary the worker cannot find on PATH. Install the plugin on the worker,
or use an absolute path in command.
plugin 'my-plugin' did not answer 'describe'
The child process started, but did not reply within the transport's timeout. Check the plugin's
own logs on stderr, and that it speaks line-delimited JSON-RPC 2.0 on stdout.
plugin 'my-plugin': <message>
The plugin replied with a JSON-RPC error. The message is the plugin's own. Read it against the
plugin's documentation or source.
spec.nodes.heading.type: no plugin provides the node type 'template'
The plugin's describe lists no nodes port named template. Install the plugin that ships the
type on every worker, or correct the node's type.
spec.nodes.heading.tempalte: unknown key
tempalte is not a key the plugin declares in the root properties of its config_schema, so the
plugin would not receive it. The engine checks unknown keys there even without
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.
plugin:words.count: no plugin provides toolsets/words (known: none)
The plugin's describe lists no toolsets port named words. Install the plugin on every worker,
or correct the reference. A named tool also fails when the toolset exists but its tools() list
has no such tool.
See also
- In-process plugin
- Architecture: the plugin contract
- The S7 scenario: a flow that uses the node type and the tool.