This release is a pre-release and may not be stable for production use.
nemo-relay-plugin
nemo-relay-plugin is the Python SDK for NeMo Relay worker plugins. A worker
runs in its own Python process and calls Relay through
nvidia.nemo.relay.worker.v1.
The protocol is nvidia.nemo.relay.worker.v1, with contract version 1.0.0.
Upgrade the host and worker SDK together. Rebuild workers and set these manifest
values: compat.worker_protocol = "nvidia.nemo.relay.worker.v1" and
compat.relay = ">=1.0.0,<2.0". Old grpc-v1 workers cannot connect.
Crate and wheel releases continue to follow the Relay release version.
Callbacks use shared application types. The SDK converts Relay-owned values to protobuf messages for transport. It preserves application and provider JSON, tool annotations, pending marks, codec access, cancellation, and scope ownership.
Authoring Surface
The SDK provides the following types and helpers.
| Surface | Role |
|---|---|
WorkerPlugin and PluginContext |
Define validation and install all 17 worker-owned subscriber and middleware registrations. |
serve_plugin |
Starts an AsyncIO gRPC server from the Relay-managed environment and authenticated local activation endpoints. |
| Typed runtime helpers | Share JSON, event, scope, middleware, continuation, and diagnostic contracts with the Relay host. |
| Tool results | Preserve application results and opaque annotations across tool callbacks and continuations. |
LlmExecutionContext |
Provides the selected request codec and, for non-streaming calls, the completed-response codec while the callback is active. |
nemo_relay_plugin.codecs |
Selects normalized content through one authenticated Rust-host RPC, then exposes typed local snapshots without the main runtime extension. |
| Generated transport bindings | Ship private protobuf bindings in the wheel, so installation does not require protoc or grpcio-tools. |
The worker process isolates Python dependencies and crashes from Relay while preserving host-owned execution, event, scope, cancellation, and shutdown semantics.
Normalized Content Access
Annotations remain dictionaries. Use async helpers such as
await codecs.last_message(ctx.runtime, request) and
await codecs.output(ctx.runtime, response) from nemo_relay_plugin.codecs.
Each selection makes one authenticated InspectLlmContent RPC. Rust performs
selection and extraction; Python only adapts the typed response.
Returned views provide local parts(), text_parts(), and text() access.
Typed entries distinguish text/refusals, tools, media, and opaque native content.
Tool payloads retain their original representation. Snapshots are independent
and read-only, and returned Python payload values are independent copies.
Existing dictionary callbacks and codec decode/encode operations are unchanged.
Older hosts report unsupported inspection explicitly; no Python policy fallback
is used. Refer to the Python worker content guide
for async selectors, ownership, limits, and compatibility.
Propagating Continuation Errors
Re-raise an unchanged error from ToolNext, LlmNext, or LlmStreamNext to
preserve its downstream origin. Typed errors returned by the host remain catchable
as WorkerSdkError; stream transport failures retain their gRPC exception type.
Constructing a new exception represents a distinct plugin failure.
The SDK preserves the host-issued continuation identity through callback and stream responses. The host excludes a forwarded error from plugin callback failure counts only when that identity matches the current invocation. Existing error text and execution behavior are preserved. If the identity is missing or does not match, the host uses its normal error attribution rules.
Installation
Prebuilt wheels contain generated protobuf bindings and need neither Buf nor
protoc. Source and editable builds require Buf
1.75.0 or later on PATH, or an executable selected with BUF. They download
the exact validation schema version recorded in the packaged buf.lock. The
first download needs access to the Buf Schema Registry. The source package does
not contain a copy of that upstream schema.
Add the SDK to the Python worker project's dependencies:
uv add nemo-relay-plugin
If you are not using uv, install it with pip:
pip install nemo-relay-plugin
Declare a module:function entrypoint that starts the worker with
serve_plugin. Register the plugin manifest through the CLI; Relay creates a
per-plugin virtual environment, installs source.manifest_root, and records
that environment for activation:
nemo-relay plugins add ./relay-plugin.toml
nemo-relay plugins enable <plugin_id>
Python workers cannot be loaded directly from plugins.toml. They must be
registered through plugins add, which provisions the required managed
environment. plugins remove <plugin_id> deletes that environment.
Configuration
Set [load.max_message_bytes] in relay-plugin.toml. Use default_bytes for
the default limit and by_name for limits on exact callback registration names.
A callback's limit also applies to its continuations. Other callbacks and control
RPCs keep their own defaults. Host environment overrides take priority. The
default limit is 4 MiB. Restart the host and workers after changing these settings.
Refer to execution message limits.
Getting Started
Tool execution interceptors receive ToolExecutionContext.execution_context
when the caller supplied a concrete execution-context object. Its optional
data field is a JSON object for application-owned fields; unknown outer fields
and non-object data are rejected. Relay validates the envelope and resource
limits; middleware validates and interprets the payload inside data. It is separate from
args and event metadata. Each access returns a defensive copy; editing it or
passing new arguments to ToolNext.call() does not replace the original
context. Nested managed calls do not inherit it automatically. Relay assigns
no authorization meaning to its contents and does not authenticate any claim
inside the object.
Preserving this field is required by the Relay 1.0 worker contract; there is no
separate feature advertisement or opt-in. The value is still optional on each
call: omission means no context, {} is an empty context, and {"data":{}}
explicitly supplies empty application data. The
handshake checks the protocol identity and exact contract version. Rebuild and
repackage development workers with the matching SDK before using this baseline;
an obsolete development binary advertising the same 1.0.0 identity cannot be
distinguished by that version alone.
A minimal worker plugin looks like this:
from nemo_relay_plugin import Json, PluginContext, WorkerPlugin, serve_plugin
class PolicyPlugin(WorkerPlugin):
plugin_id = "acme.policy"
def register(self, ctx: PluginContext, config: Json) -> None:
async def tag_tool_request(tool_name: str, args: Json) -> Json:
await ctx.runtime.emit_mark("acme.policy.tool_request", {"tool_name": tool_name})
if isinstance(args, dict):
return {**args, "policy": "checked"}
return {"value": args, "policy": "checked"}
ctx.register_tool_request_intercept("tag_tool_request", tag_tool_request)
async def main() -> None:
await serve_plugin(PolicyPlugin())
Use the optional mark fields to set a data schema, log severity, and category, as shown in this example:
from nemo_relay_plugin import DataSchema, EventCategory, LogSeverity
await ctx.runtime.emit_mark(
"acme.policy.decision",
{"allowed": True},
data_schema=DataSchema("acme.policy.decision", "1"),
severity=LogSeverity.INFO,
category=EventCategory.CUSTOM,
)
The original positional emit_mark(name, data, metadata) form remains
supported. Relay validates the schema and severity again at the host boundary.
Use emit_metric(name, measurements, metadata) to attach the reserved Relay
metric schema; authoritative metric validation remains in Relay after mark
sanitization.
Use await ctx.runtime.runtime_diagnostics() in an asynchronous callback to
read an immutable, host-level RuntimeDiagnostics snapshot. Each entry has
code, message, and count; entries is ordered by code and get(code)
looks up one entry. Relay aggregates repeated codes, retains the latest
message, saturates counts, and caps the snapshot at 32 entries. Entries do not
identify the emitting plugin. A host that does not implement this RPC returns gRPC UNIMPLEMENTED, which
the SDK reports as an unsupported runtime diagnostics error.
Set load.entrypoint to your_module:main in relay-plugin.toml. Relay
imports that function and awaits the returned coroutine when it starts the
worker process.
Request Intercepts
LLM request intercepts return one canonical outcome:
from nemo_relay_plugin import AnnotatedLLMRequest, Json, LlmRequestInterceptOutcome, PendingMarkSpec
def intercept(
model_name: str,
request: Json,
annotated: AnnotatedLLMRequest | None,
) -> LlmRequestInterceptOutcome:
del model_name
headers = {**request.get("headers", {}), "x-policy": "checked"}
return LlmRequestInterceptOutcome(
request={**request, "headers": headers},
annotated_request=annotated,
pending_marks=[PendingMarkSpec("acme.policy.checked")],
)
When annotated is present, Relay uses it as the source of provider-body content.
Leave raw request["content"] unchanged. Edit normalized fields or provider
extensions through the annotation. Use request["headers"] for transport headers.
Callback Concurrency
The gRPC AsyncIO server can keep multiple RPCs in flight. Callback execution is
cooperative: asynchronous callbacks overlap only when they yield control at an
await. Synchronous callbacks and synchronous stream iterators run on the
worker event-loop thread. Blocking I/O, time.sleep, or long-running CPU work
in those callbacks stalls all worker RPCs. Wrap blocking work in an
asynchronous callback and offload it with asyncio.to_thread() or another
appropriate executor.
The SDK does not configure maximum_concurrent_rpcs, so gRPC does not enforce
an application-level RPC admission limit.
Invocation Cancellation
Relay assigns every unary and streaming callback an invocation ID. The host
sends CancelInvocation when its managed caller is cancelled, its worker RPC
times out, or it stops consuming a worker-backed stream. The SDK cancels the
matching asyncio.Task and reports a structured worker.cancelled result.
Cancellation is idempotent. The first request that matches an active callback
returns accepted = true; requests for unknown, completed, or already
cancelled IDs return accepted = false. Treat acceptance as confirmation that
the SDK found and cancelled the task, not as proof that arbitrary user code has
stopped.
Python task cancellation is cooperative. Async callbacks should allow
asyncio.CancelledError to propagate and use try/finally for cleanup.
Synchronous callbacks run on the event-loop thread and cannot be preempted by
task cancellation. A blocking synchronous callback can delay both the
cancellation RPC and all other worker RPCs, so offload blocking work and make
its own cancellation behavior explicit.
Worker v1 implementations are expected to implement this best-effort cancellation
contract. If a worker returns accepted = false, Relay still drops the transport
request, but it cannot guarantee worker-side interruption.
Windows ARM64 is not currently supported because grpcio does not publish a
usable wheel for that platform. The NeMo Relay workspace skips installation and
tests for this SDK on Windows ARM64 rather than creating a package without its
required gRPC runtime.
Metadata
Release files for nemo-relay-plugin 1.0.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nemo_relay_plugin-1.0.0rc1-py3-none-any.whl | Python 3 | none | any | Details for nemo_relay_plugin-1.0.0rc1-py3-none-any.whl |
Release files / nemo_relay_plugin-1.0.0rc1-py3-none-any.whl
| Download URL | nemo_relay_plugin-1.0.0rc1-py3-none-any.whl |
|---|---|
| Size | 176.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11de32e632054aca3433d2b92fb76e69f9f05373f02c8ceeec59dc5ff7ad2b6a
|
|
BLAKE2b-256 checksum How to use checksums |
af1bf4f02dd3a258b12f08eeab1b014ca3f2ded99d4c4fca8273e2086dbe4e17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for nemo-relay-plugin 1.0.0rc1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for nemo_relay_plugin-1.0.0rc1-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.