Native Dynamic Plugins (Rust)
Native Dynamic Plugins (Rust)
Native dynamic plugins are trusted in-process shared libraries. Use them when plugin behavior needs host-process access while still following the Relay plugin contract: a stable kind, JSON component configuration, validation diagnostics, and registration through a component-scoped context.
Native plugins are not sandboxed. They run in the gateway process, must not unwind across ABI callbacks, and remain loaded until Relay removes their registered callbacks.
Manifest
Use the following manifest:
Set plugin.kind to rust_dynamic, compat.native_api to "1", and
capabilities.items to include plugin_native. Relay resolves relative paths
from the manifest. The exported symbol must return a descriptor whose
plugin_kind matches plugin.id exactly.
Create a Native Plugin
Create a Rust library project with the following Cargo.toml file:
Add the following implementation to src/lib.rs:
Build the library with the following command:
Update source.artifact and load.library with the resulting platform library
path, then replace <artifact-sha256> with that library’s SHA-256 digest. Use
.dylib on macOS, .so on Linux, or .dll on Windows. Refer to Build a Rust
Native Plugin for a complete example
with validation, middleware, scopes, and configuration schema support.
Native ABI v1
The host passes a NemoRelayNativeHostApiV1 table to the entry symbol. The
plugin returns a NemoRelayNativePluginV1 descriptor:
Text and JSON data cross this boundary as host-owned
NemoRelayNativeString handles. ABI structs also carry scalars, opaque
handles, callback pointers, and plugin-owned user_data. Do not pass Rust
runtime types, trait objects, futures, serde_json::Value, or allocator-owned
strings across the ABI.
ABI callbacks can register these runtime surfaces:
- Subscribers
- Tool and LLM guardrails or intercepts, including stream intercepts
- Marks, scopes, and isolated scope stacks
Relay keeps the library alive while those registrations exist and deregisters them before unloading it.
Use the nemo-relay-plugin crate rather than the host nemo-relay runtime
crate. Refer to Build a Rust Native Plugin
for the SDK-backed example.
Register the Plugin
After you package the manifest and library, register and validate the plugin:
Refer to Configure Discoverable Plugins for lifecycle and trust-policy configuration.