For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
  • About NVIDIA NeMo Relay
    • Overview
    • Architecture
    • Ecosystem
    • Concepts
    • Release Notes
  • Getting Started
    • Agent Runtime Primer
    • Prerequisites
    • Installation
    • Configuration / Setup
    • Quick Start
  • NVIDIA NeMo Relay CLI
    • About
    • Basic Usage
    • Claude Code
    • Codex
    • Cursor
    • Hermes Agent
  • Supported Integrations
    • About
    • OpenClaw Plugin Guide
    • LangChain Integration Guide
    • LangGraph Integration Guide
    • Deep Agents Integration Guide
  • Instrument Applications
    • About
    • Adding Scopes and Marks
    • Instrument a Tool Call
    • Instrument an LLM Call
    • Add Middleware
    • Code Examples
  • Observability Plugin
    • About
    • Configuration
    • Agent Trajectory Interchange Format (ATIF)
    • Agent Trajectory Observability Format (ATOF)
    • OpenTelemetry
    • OpenInference
  • Adaptive Plugin
    • About
    • Configuration
    • Adaptive Cache Governor (ACG)
    • Adaptive Hints
  • NeMo Guardrails Plugin
    • About
    • Configuration
  • Integrate into Frameworks
    • About
    • Adding Scopes
    • Wrap Tool Calls
    • Wrap LLM Calls
    • Handle Non-Serializable Data
    • Using Codecs
    • Provider Codecs
    • Provider Response Codecs
    • Code Examples
  • Build Plugins
    • About
    • Define a Plugin
    • Validate Plugin Configuration
    • Plugin Configuration Files
    • Register Plugin Behavior
    • Design Plugin Configuration
    • NeMo Guardrails Example Plugin
    • Code Examples
  • Contribute
    • About
    • Development Setup
    • Workflow and Reviews
    • Testing and Documentation
  • Reference
    • APIs
      • Python Library Reference
      • Node.js Library Reference
      • Rust Library Reference
        • nemo-relay
          • api
            • event
            • llm
            • registry
            • runtime
              • callbacks
              • global
              • scope_stack
              • state
                • NemoRelayContextState
              • subscriber_dispatcher
            • scope
            • subscriber
            • tool
          • codec
          • config_editor
          • error
          • json
          • observability
          • plugin
          • plugins
          • stream
          • editor_config
        • nemo-relay-adaptive
        • nemo-relay-ffi
    • Performance
  • Resources
    • Support and FAQs
    • Glossary
    • Troubleshooting Guide
    • Community
    • Legal
NVIDIANVIDIA
Developer-friendly docs for your API
Privacy Policy | Your Privacy Choices | Terms of Service | Accessibility | Corporate Policies | Product Security | Contact

Copyright © 2026, NVIDIA Corporation.

LogoLogo
On this page
  • Implementations
  • impl NemoRelayContextState
  • new
  • Returns
  • set_extension
  • Parameters
  • get_extension
  • Parameters
  • Returns
  • get_extension_mut
  • Parameters
  • Returns
  • remove_extension
  • Parameters
  • Returns
  • create_event
  • Parameters
  • Returns
  • create_scope_handle
  • Parameters
  • Returns
  • build_scope_start_event
  • Parameters
  • Returns
  • end_scope_handle
  • Parameters
  • Returns
  • build_scope_end_event
  • Parameters
  • Returns
  • create_tool_handle
  • Parameters
  • Returns
  • build_tool_start_event
  • Parameters
  • Returns
  • end_tool_handle
  • Parameters
  • Returns
  • build_tool_end_event
  • Parameters
  • Returns
  • create_llm_handle
  • Parameters
  • Returns
  • build_llm_start_event
  • Parameters
  • Returns
  • end_llm_handle
  • Parameters
  • Returns
  • build_llm_end_event
  • Parameters
  • Returns
  • Trait Implementations
  • impl Default for NemoRelayContextState
  • default
ReferenceAPIsRust Library Referencenemo-relayapiruntimestate

Struct Nemo Relay Context State

||View as Markdown|
Previous

Module state

Next

Module subscriber_dispatcher

Generated from cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-ffi.

1pub 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

impl NemoRelayContextState

new

pub fn new() -> Self

Create an empty runtime state with no registered middleware.

Returns

A NemoRelayContextState with empty registries, no subscribers, and no extensions.

set_extension

pub fn set_extension<T: Any + Send + Sync>(
    &mut self,
    key: impl Into<String>,
    value: T,
)

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

pub fn get_extension<T: Any + Send + Sync>(&self, key: &str) -> Option<&T>

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

pub fn get_extension_mut<T: Any + Send + Sync>(
    &mut self,
    key: &str,
) -> Option<&mut T>

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

pub fn remove_extension(&mut self, key: &str) -> bool

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

pub fn create_event(&self, params: MarkEvent) -> Event

Build a standalone mark event.

Parameters
  • params: A pre-built MarkEvent to wrap in an Event.
Returns

A mark Event containing the provided MarkEvent.

create_scope_handle

pub fn create_scope_handle(
    &self,
    params: CreateScopeHandleParams<'_>,
) -> ScopeHandle

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 with a fresh UUID.

build_scope_start_event

pub fn build_scope_start_event(
    &self,
    handle: &ScopeHandle,
    data: Option<Json>,
) -> Event

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 derived from the provided handle.

end_scope_handle

pub fn end_scope_handle(
    &self,
    handle: &ScopeHandle,
    data: Option<Json>,
) -> Event

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.
Returns

A scope-end Event derived from the provided handle.

build_scope_end_event

pub fn build_scope_end_event(&self, params: EndScopeHandleParams<'_>) -> Event

Build a scope-end event from builder parameters.

Parameters
  • params: Scope end-event builder parameters.
Returns

A scope-end Event derived from the provided parameters.

create_tool_handle

pub fn create_tool_handle(
    &self,
    params: CreateToolHandleParams<'_>,
) -> ToolHandle

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 with a fresh UUID.

build_tool_start_event

pub fn build_tool_start_event(
    &self,
    handle: &ToolHandle,
    data: Option<Json>,
) -> Event

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 derived from the provided handle.

end_tool_handle

pub fn end_tool_handle(
    &self,
    handle: &ToolHandle,
    data: Option<Json>,
    metadata: Option<Json>,
) -> Event

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 derived from the provided handle.

build_tool_end_event

pub fn build_tool_end_event(&self, params: EndToolHandleParams<'_>) -> Event

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 derived from the provided parameters.

create_llm_handle

pub fn create_llm_handle(&self, params: CreateLlmHandleParams<'_>) -> LlmHandle

Create a new LLM handle.

Parameters
  • name: Logical provider or model family 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 with a fresh UUID.

build_llm_start_event

pub fn build_llm_start_event(
    &self,
    handle: &LlmHandle,
    data: Option<Json>,
    annotated_request: Option<Arc<AnnotatedLlmRequest>>,
) -> Event

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 derived from the provided handle.

end_llm_handle

pub fn end_llm_handle(
    &self,
    handle: &LlmHandle,
    data: Option<Json>,
    metadata: Option<Json>,
    annotated_response: Option<Arc<AnnotatedLlmResponse>>,
) -> Event

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 derived from the provided handle.

build_llm_end_event

pub fn build_llm_end_event(&self, params: EndLlmHandleParams<'_>) -> Event

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 derived from the provided parameters.

Trait Implementations

impl Default for NemoRelayContextState

impl Default for NemoRelayContextState

default

fn default() -> Self