Register Plugin Behavior
Use this guide after you define plugin configuration validation and before the plugin installs NeMo Relay runtime behavior.
What You Build
Register a plugin kind, initialize validated configuration, install subscribers
or middleware through PluginContext, and clear active plugin configuration
during teardown.
Use PluginContext
PluginContext is the component-scoped registration surface that Relay passes
to the plugin during initialization. Register subscribers, guardrails, and
intercepts through this context instead of through global registration calls in
application startup.
The context gives the plugin system three important guarantees:
- The runtime qualifies names for the component instance.
- Relay rolls back partial setup if one registration fails.
- Plugin diagnostics can identify the affected configured component when the
plugin includes
componentin each diagnostic.
Use the context only after validation succeeds. Keep validation deterministic and side-effect free. Inspect configuration and return diagnostics. Create runtime objects and attach them to the context during registration.
Header Plugin Example
The same model applies in every binding: validate component-local config, then install middleware through the component-scoped registration context.
Python
Node.js
Rust
Activation APIs
After you register the plugin kind, use the plugin APIs in this order. Refer to the Header Plugin Example for the registration pattern:
- Build a
PluginConfig. - Validate the config.
- Initialize the config.
- Inspect the activation report.
- Clear active config during teardown when needed.
Register the plugin kind before initialization. With the default
unknown_component="warn" policy, validate() reports an enabled unregistered
kind as a warning. An error-only check therefore passes, but initialize()
raises for an enabled unregistered kind. Register every enabled kind before
initialization, or set
unknown_component="error" to make validation fail.
validate() checks only the configuration you pass to it. initialize() also
layers discovered plugins.toml configuration, so startup can activate or
reject components that a preflight report did not include. Refer to Plugin
Configuration Files when file
discovery participates in deployment.
Append the following entry point to the matching Header Plugin Example above. Each tab relies on that example’s plugin definition and imports. Together, the two blocks register the custom plugin, validate configuration, initialize it, inspect the activation report and available kinds, and clear active configuration:
Python
Node.js
Rust
Append this entry point to the Python Header Plugin Example above.
Registration Checklist
Before publishing or sharing a plugin:
- Validate a correct config and confirm no errors are reported.
- Validate an intentionally invalid config and confirm diagnostics are actionable.
- Initialize the plugin and verify the expected subscribers or middleware run.
- Force one registration failure and confirm partial setup is rolled back.
- Call
clear()to remove active component registrations during teardown. Callderegister()too only when a test or embedded runtime must register the same custom kind again.
Common Issues
Check these symptoms first when the workflow does not behave as expected.
- Middleware names collide: Use component-local names and let the plugin runtime qualify them.
- Partial registrations remain after failure: Register through
PluginContextso rollback can clean up. - Registration does validation work: Move deterministic checks into the validation hook.
- Global state leaks across component instances: Create instance-local state during registration or key shared state by component identity.
Next Steps
Use these links to continue from this workflow into the next related task.
- Add advanced validation and rollout controls with Design Plugin Configuration.
- Review concrete authoring patterns in Code Examples.