> This page is for NeMo Relay, version v1.0.0.
> For other versions, use one of these documentation indexes:
> - Latest (v0.11.2) (default): https://docs.nvidia.com/nemo/relay/latest/llms.txt
> - dev: https://docs.nvidia.com/nemo/relay/dev/llms.txt
> - v1.0.0: https://docs.nvidia.com/nemo/relay/v1.0.0/llms.txt
> - v0.11.2: https://docs.nvidia.com/nemo/relay/v0.11.2/llms.txt
> - v0.10.4: https://docs.nvidia.com/nemo/relay/v0.10.4/llms.txt
> - v0.9.4: https://docs.nvidia.com/nemo/relay/v0.9.4/llms.txt
> - v0.8.4: https://docs.nvidia.com/nemo/relay/v0.8.4/llms.txt

> For clean Markdown of any page, append .md to the page URL. For a task-oriented documentation index, fetch https://docs.nvidia.com/nemo/relay/llms.txt. Use the documentation version matching the installed NeMo Relay package: latest follows the latest stable release, vX.Y.Z identifies a retained release snapshot, and dev documents development changes. Preserve the selected version when following links; do not mix examples or API contracts from different versions. Fetch the relevant section's /llms.txt before individual pages instead of loading a complete version index.

# Struct Plugin Context

> API documentation for the Rust `PluginContext` struct in crate `nemo_relay_plugin`.

Generated from `cargo doc --no-deps -p nemo-relay-builtins -p nemo-relay-diagnostics -p nemo-relay-logging -p nemo-relay-plugin-host -p nemo-relay-codecs -p nemo-relay -p nemo-relay-runtime -p nemo-relay-model-pricing -p nemo-relay-resource-metrics -p nemo-relay-observability -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker`.

```rust
pub struct PluginContext<'a> { /* private fields */ }
```

## Implementations

### `impl PluginContext<'_>`

<pre />

#### `runtime`

<pre />

#### `task_spawner`

<pre />

Obtain a cloneable task spawner for use inside registered middleware.

#### `spawn`

<pre />

Spawn background work whose scope, cancellation, and cleanup belong to this component.

#### `register_subscriber`

<pre />

Register a synchronous event subscriber owned by this component.

#### `register_conditional_middleware_guardrail`

<pre />

Register a synchronous gate that can disable selected middleware registrations.

### `impl PluginContext<'_>`

<pre />

#### `register_event_metadata_injector`

<pre />

Register an async callback that adds metadata to emitted events.

#### `register_mark_sanitize_guardrail`

<pre />

Register an async sanitizer for observable fields on mark events.

#### `register_scope_sanitize_start_guardrail`

<pre />

Register an async sanitizer for observable fields on scope-start events.

#### `register_scope_sanitize_end_guardrail`

<pre />

Register an async sanitizer for observable fields on scope-end events.

#### `register_tool_sanitize_request_guardrail`

<pre />

Register an async sanitizer for tool request data recorded in events.

#### `register_tool_sanitize_response_guardrail`

<pre />

Register an async sanitizer for tool response data recorded in events.

#### `register_tool_conditional_execution_guardrail`

<pre />

Register an async guardrail that allows or blocks a tool call.

#### `register_tool_request_intercept`

<pre />

Register an async intercept that can rewrite a tool's execution arguments.

#### `register_tool_execution_intercept`

<pre />

Register an async tool execution wrapper with repeatable downstream continuations.

#### `register_llm_conditional_execution_guardrail`

<pre />

Register an async guardrail that allows or blocks an LLM call.

#### `register_llm_request_intercept`

<pre />

Register an async intercept that can rewrite or complete an LLM request.

#### `register_llm_sanitize_request_guardrail`

<pre />

Register an async sanitizer for observable LLM request data with its request codec context.

#### `register_llm_sanitize_response_guardrail`

<pre />

Register an async sanitizer for observable LLM responses with their response codec context.

#### `register_llm_execution_intercept`

<pre />

Register an async LLM execution wrapper with live codec capabilities and downstream continuation.

#### `register_llm_stream_execution_intercept`

<pre />

Register an async LLM stream wrapper whose streams close with the owning component.

### `impl PluginContext<'_>`

<pre />

#### `register_synchronous_callback`

<pre />

Register a synchronous callback using only checked ABI invocation values. The Rust callback and its captured state remain in the originating SDK. Subscribers run inline; synchronous middleware uses blocking offload.

### `impl PluginContext<'_>`

<pre />

#### `register_synchronous_stream_callback`

<pre />

Register a synchronous stream factory returning a checked stream descriptor. Offload construction; poll returned stream futures under component scope and runtime context.