> This page is for NeMo Relay, version v0.6.0.
> For other versions, use one of these documentation indexes:
> - Latest (v0.9.4) (default): https://docs.nvidia.com/nemo/relay/latest/llms.txt
> - dev: https://docs.nvidia.com/nemo/relay/dev/llms.txt
> - v0.10.0: https://docs.nvidia.com/nemo/relay/v0.10.0/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
> - v0.7.3: https://docs.nvidia.com/nemo/relay/v0.7.3/llms.txt
> - v0.6.0: https://docs.nvidia.com/nemo/relay/v0.6.0/llms.txt
> - v0.5.0: https://docs.nvidia.com/nemo/relay/v0.5.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/relay/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server.

# Struct Nemo Relay Context State

> Process-global runtime state backing middleware and event emission.

Generated from `cargo doc --no-deps -p nemo-relay -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 NemoRelayContextState { /* private fields */ }
```

Process-global runtime state backing middleware and event emission.

The public API layer stores one shared instance of this type for the process. It contains global middleware registries, lifecycle subscribers, and arbitrary extension slots used by bindings or integrations.

## Implementations

### `impl NemoRelayContextState`

<pre />

#### `new`

<pre />

Create an empty runtime state with no registered middleware.

##### Returns

A [`NemoRelayContextState`](/reference/api/rust-library-reference/nemo-relay/api/runtime/state/struct-nemorelaycontextstate) with empty registries, no subscribers, and no extensions.

#### `set_extension`

<pre />

Store an arbitrary runtime extension under `key`.

Extensions let bindings or integrations attach shared state to the process-global runtime without adding new first-class fields.

##### Parameters

* `key`: Stable identifier for the extension slot.
* `value`: Typed extension value to store.

#### `get_extension`

<pre />

Borrow a typed runtime extension by key.

##### Parameters

* `key`: Extension slot name.

##### Returns

`Some(&T)` when an extension exists under `key` with the requested type and `None` otherwise.

#### `get_extension_mut`

<pre />

Mutably borrow a typed runtime extension by key.

##### Parameters

* `key`: Extension slot name.

##### Returns

`Some(&mut T)` when an extension exists under `key` with the requested type and `None` otherwise.

#### `remove_extension`

<pre />

Remove a runtime extension by key.

##### Parameters

* `key`: Extension slot name.

##### Returns

`true` when an extension was removed and `false` when no extension was stored under `key`.

#### `create_event`

<pre />

Build a standalone mark event.

##### Parameters

* `params`: A pre-built [`MarkEvent`](/reference/api/rust-library-reference/nemo-relay/api/event/struct-markevent) to wrap in an [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event).

##### Returns

A mark [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) containing the provided [`MarkEvent`](/reference/api/rust-library-reference/nemo-relay/api/event/struct-markevent).

#### `create_scope_handle`

<pre />

Create a new scope handle.

##### Parameters

* `name`: Human-readable scope name.
* `parent_uuid`: Optional parent scope UUID.
* `scope_type`: Semantic category of the scope.
* `attributes`: Scope attribute bitflags.
* `data`: Optional application payload stored on the handle.
* `metadata`: Optional metadata stored on the handle.
* `timestamp`: Optional handle start time. When omitted, the current UTC time is used.

##### Returns

A new [`ScopeHandle`](/reference/api/rust-library-reference/nemo-relay/api/scope/struct-scopehandle) with a fresh UUID.

#### `build_scope_start_event`

<pre />

Build a scope-start event from a handle.

##### Parameters

* `handle`: Scope handle to serialize into an event.
* `data`: Optional semantic input payload exported on the start event.

##### Returns

A scope-start [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `end_scope_handle`

<pre />

Build a scope-end event from a handle.

##### Parameters

* `handle`: Scope handle to serialize into an event.
* `data`: Optional data payload returned from the scope.
* `metadata`: Optional metadata payload merged over `handle.metadata`.

##### Returns

A scope-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `build_scope_end_event`

<pre />

Build a scope-end event from builder parameters.

The `metadata` payload is merged over the metadata already stored on the handle.

##### Parameters

* `params`: Scope end-event builder parameters.

##### Returns

A scope-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided parameters.

#### `create_tool_handle`

<pre />

Create a new tool handle.

##### Parameters

* `name`: Tool name recorded on emitted events.
* `parent_uuid`: Optional parent scope UUID.
* `attributes`: Tool attribute bitflags.
* `data`: Optional application payload stored on the handle.
* `metadata`: Optional metadata stored on the handle.
* `tool_call_id`: Optional provider-specific correlation identifier.
* `timestamp`: Optional handle start time. When omitted, the current UTC time is used.

##### Returns

A new [`ToolHandle`](/reference/api/rust-library-reference/nemo-relay/api/tool/struct-toolhandle) with a fresh UUID.

#### `build_tool_start_event`

<pre />

Build a tool-start event from a handle.

##### Parameters

* `handle`: Tool handle to serialize into an event.
* `data`: Optional tool input payload.

##### Returns

A tool-start [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `end_tool_handle`

<pre />

Build a tool-end event from a handle and optional overrides.

##### Parameters

* `handle`: Tool handle to serialize into an event.
* `data`: Optional end-event data payload.
* `metadata`: Optional metadata payload merged over `handle.metadata`.

##### Returns

A tool-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `build_tool_end_event`

<pre />

Build a tool-end event from builder parameters.

The `metadata` payload is merged over the metadata already stored on the handle.

##### Parameters

* `params`: Tool end-event builder parameters.

##### Returns

A tool-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided parameters.

#### `create_llm_handle`

<pre />

Create a new LLM handle.

##### Parameters

* `name`: Logical provider or model family name. Gateway-managed LLM calls use provider route names such as `anthropic.messages`, which become the emitted event name.
* `parent_uuid`: Optional parent scope UUID.
* `attributes`: LLM attribute bitflags.
* `data`: Optional application payload stored on the handle.
* `metadata`: Optional metadata stored on the handle.
* `model_name`: Optional normalized model name stored on the handle.
* `timestamp`: Optional handle start time. When omitted, the current UTC time is used.

##### Returns

A new [`LlmHandle`](/reference/api/rust-library-reference/nemo-relay/api/llm/struct-llmhandle) with a fresh UUID.

#### `build_llm_start_event`

<pre />

Build an LLM-start event from a handle.

##### Parameters

* `handle`: LLM handle to serialize into an event.
* `data`: Sanitized LLM request payload.
* `annotated_request`: Optional normalized request annotation.

##### Returns

An LLM-start [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `end_llm_handle`

<pre />

Build an LLM-end event from a handle and optional overrides.

##### Parameters

* `handle`: LLM handle to serialize into an event.
* `data`: Sanitized LLM response payload.
* `metadata`: Optional metadata payload merged over `handle.metadata`.
* `annotated_response`: Optional normalized response annotation.

##### Returns

An LLM-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided handle.

#### `build_llm_end_event`

<pre />

Build an LLM-end event from builder parameters.

The `metadata` payload is merged over the metadata already stored on the handle.

##### Parameters

* `params`: LLM end-event builder parameters.

##### Returns

An LLM-end [`Event`](/reference/api/rust-library-reference/nemo-relay/api/event/enum-event) derived from the provided parameters.

## Trait Implementations

### `impl Default for NemoRelayContextState`

<pre />

#### `default`

<pre />