gRPC Worker Plugins (Python)
gRPC Worker Plugins (Python)
Use the nemo-relay-plugin package to build an out-of-process plugin worker.
The SDK owns gRPC server setup, generated protocol stubs, JSON-envelope
conversion, continuations, cancellation hooks, and scope-stack helpers.
Refer to gRPC Worker Plugin Concepts
to compare the Python, Rust, and command worker runtimes.
This guide builds a complete plugin that adds a tag to every tool request and emits a mark through the Relay host runtime.
Create the Project
Create the following project layout:
Add the following pyproject.toml file:
Create nemo_relay_python_grpc_worker/__init__.py with the following content:
Implement the Worker
Add the following implementation to
nemo_relay_python_grpc_worker/worker.py:
WorkerPlugin.validate returns structured diagnostics after Relay starts the
worker process and before Relay installs registrations. WorkerPlugin.register
registers a tool request intercept that updates the request JSON and emits a
mark through PluginContext.runtime. The main entrypoint blocks until Relay
requests shutdown.
Create the Manifest
Create relay-plugin.toml with the following content:
The digest matches the worker.py file in this guide. Use Python 3.11 or later
to calculate a new digest before you register the worker:
Register the Plugin
Run the following commands from the project directory:
plugins add creates an isolated Relay-managed Python environment and installs
the source.manifest_root project into it. Relay uses that recorded environment
when it starts the worker. Do not start the worker directly: Relay supplies its
worker socket, host socket, activation ID, and activation token.
Configure the Plugin
After plugins add registers the worker, edit
$relay_tmp/plugins.toml. Add the configuration table to the
[[plugins.dynamic]] entry that plugins add created. The configuration sets
the tag that the worker adds to tool request JSON:
Do not use this TOML block instead of plugins add for a Python worker. The
CLI also creates the lifecycle record that points to the Relay-managed Python
environment. The tag field is optional and defaults to python_grpc_worker.
Test Worker-Side Validation
nemo-relay plugins validate checks the manifest, trust evidence, and optional
static schema. It does not call WorkerPlugin.validate.
To test runtime validation:
- Set
reject = true, then start the gateway. Relay starts the worker and reports the worker diagnostic before it installs registrations. - Set
tagto a non-string value, then start the gateway. Relay reports the structured diagnostic fromWorkerPlugin.validate.
WorkerPlugin.validate runs after Relay starts the worker and before Relay
installs registrations.
Run the Plugin
Enable, validate, and start the gateway with the following commands:
Update the Worker
After you change worker source code or dependencies, rebuild the managed environment instead of only updating the manifest digest:
-
Recalculate
integrity.sha256with Python 3.11 or later and updaterelay-plugin.toml. -
Remove the registered worker, then add it again:
-
Restore any
[[plugins.dynamic]].configvalues, then enable the worker.
plugins add installs a new copy of source.manifest_root into a fresh
Relay-managed environment. It cannot refresh an already registered worker.
After you stop Relay, remove the plugin and its managed environment:
Refer to gRPC Worker Protocol Overview for the
shared grpc-v1 contract and
Configure Discoverable Plugins for
host trust and lifecycle policies.