> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server. # Module runtime > Advanced runtime state, callbacks, and scope-stack helpers. Advanced runtime state, callbacks, and scope-stack helpers. 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`. Advanced runtime state, callbacks, and scope-stack helpers. Advanced runtime state, callbacks, and scope-stack helpers. ## Re-exports * `pub use callbacks::ConditionalMiddlewareGuardrailFn;` * `pub use callbacks::EventMetadataInjectorFn;` * `pub use callbacks::EventSanitizeFn;` * `pub use callbacks::EventSubscriberFn;` * `pub use callbacks::LlmCollectorFn;` * `pub use callbacks::LlmConditionalFn;` * `pub use callbacks::LlmExecutionFn;` * `pub use callbacks::LlmExecutionNextFn;` * `pub use callbacks::LlmFinalizerFn;` * `pub use callbacks::LlmJsonStream;` * `pub use callbacks::LlmRequestContext;` * `pub use callbacks::LlmRequestInterceptFn;` * `pub use callbacks::LlmResponseContext;` * `pub use callbacks::LlmSanitizeRequestContext;` * `pub use callbacks::LlmSanitizeRequestFn;` * `pub use callbacks::LlmSanitizeResponseContext;` * `pub use callbacks::LlmSanitizeResponseFn;` * `pub use callbacks::LlmStreamExecutionFn;` * `pub use callbacks::LlmStreamExecutionNextFn;` * `pub use callbacks::LlmStreamInner;` * `pub use callbacks::ToolConditionalFn;` * `pub use callbacks::ToolExecutionContext;` * `pub use callbacks::ToolExecutionFn;` * `pub use callbacks::ToolExecutionNextFn;` * `pub use callbacks::ToolInterceptFn;` * `pub use callbacks::ToolSanitizeFn;` * `pub use global::global_context;` * `pub use scope_stack::PropagationContext;` * `pub use scope_stack::ScopeStack;` * `pub use scope_stack::ScopeStackHandle;` * `pub use scope_stack::TASK_SCOPE_STACK;` * `pub use scope_stack::ThreadScopeStackBinding;` * `pub use scope_stack::capture_propagation_context;` * `pub use scope_stack::capture_propagation_context_with_root;` * `pub use scope_stack::capture_rootless_propagation_context;` * `pub use scope_stack::capture_thread_scope_stack;` * `pub use scope_stack::capture_traceparent;` * `pub use scope_stack::create_scope_stack;` * `pub use scope_stack::create_scope_stack_from_propagation;` * `pub use scope_stack::current_scope_stack;` * `pub use scope_stack::fork_scope_stack;` * `pub use scope_stack::propagate_scope_to_thread;` * `pub use scope_stack::restore_thread_scope_stack;` * `pub use scope_stack::scope_stack_active;` * `pub use scope_stack::set_thread_scope_stack;` * `pub use scope_stack::sync_thread_scope_stack;` * `pub use scope_stack::task_scope_push;` * `pub use scope_stack::task_scope_remove;` * `pub use scope_stack::task_scope_top;` * `pub use scope_stack::with_active_event_uuid;` * `pub use scope_stack::with_scope_stack;` * `pub use state::NemoRelayContextState;` * `pub use subscriber_dispatcher::flush_subscribers;` ## Modules * [callbacks](/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks): Callback type aliases used by the runtime middleware pipeline. * [global](/reference/api/rust-library-reference/nemo-relay/api/runtime/global): Process-global access to the shared runtime context state. * [scope\_stack](/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack): Scope stack storage and propagation helpers. * [state](/reference/api/rust-library-reference/nemo-relay/api/runtime/state): Process-global runtime state and middleware-chain builders. * [subscriber\_dispatcher](/reference/api/rust-library-reference/nemo-relay/api/runtime/subscriber_dispatcher): Asynchronous subscriber delivery for native targets. ## Structs * [LlmExecutionContext](/reference/api/rust-library-reference/nemo-relay/api/runtime/struct-llmexecutioncontext): Codec access for one LLM execution. ## Enums * [BuiltinLlmCodec](/reference/api/rust-library-reference/nemo-relay/api/runtime/enum-builtinllmcodec): Relay's built-in LLM codec identities. * [LlmCodecIdentity](/reference/api/rust-library-reference/nemo-relay/api/runtime/enum-llmcodecidentity): Per-call LLM codec identity supplied to sanitizer and SDK callbacks. > Advanced runtime state, callbacks, and scope-stack helpers. Advanced runtime state, callbacks, and scope-stack helpers. ## Docs - [Module callbacks](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks.md): Callback type aliases used by the runtime middleware pipeline. - [Type Alias Conditional Middleware Guardrail Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-conditionalmiddlewareguardrailfn.md): Decide whether matching global runtime registrations remain eligible. - [Type Alias Event Metadata Injector Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-eventmetadatainjectorfn.md): Add flat metadata attributes to a fully constructed event. - [Type Alias Event Sanitize Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-eventsanitizefn.md): Sanitize mutable observability fields on a fully constructed event. - [Type Alias Event Subscriber Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-eventsubscriberfn.md): Consume runtime lifecycle events after they are emitted. - [Enum Builtin LlmCodec](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/enum-builtinllmcodec.md): Relay's built-in LLM codec identities. - [Type Alias LlmCollector Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmcollectorfn.md): Per-chunk collector used by the streaming LLM runtime. - [Enum LlmCodec Identity](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/enum-llmcodecidentity.md): Per-call LLM codec identity supplied to sanitizer and SDK callbacks. - [Type Alias LlmConditional Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmconditionalfn.md): Decide whether an LLM call is allowed to continue. - [Type Alias LlmExecution Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmexecutionfn.md): Wrap or replace non-streaming LLM execution. - [Type Alias LlmExecution Next Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmexecutionnextfn.md): Continuation type invoked by non-streaming LLM execution intercepts. - [Type Alias LlmFinalizer Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmfinalizerfn.md): Finalizer used to synthesize the aggregate streaming response payload. - [Struct LlmJson Stream](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/struct-llmjsonstream.md): Stream of JSON chunks produced by the managed streaming LLM pipeline. - [Type Alias LlmRequest Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmrequestcontext.md): Request codec context exposed to an LLM execution intercept. - [Type Alias LlmRequest Intercept Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmrequestinterceptfn.md): Rewrite or annotate an LLM request before execution. - [Type Alias LlmResponse Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmresponsecontext.md): Response codec context exposed to a non-streaming LLM execution intercept. - [Struct LlmSanitize Request Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/struct-llmsanitizerequestcontext.md): Per-call codec identity and capability for an LLM request. - [Type Alias LlmSanitize Request Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmsanitizerequestfn.md): Sanitize an LLM request before the runtime records it. - [Struct LlmSanitize Response Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/struct-llmsanitizeresponsecontext.md): Per-call codec identity and capability for an LLM response. - [Type Alias LlmSanitize Response Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmsanitizeresponsefn.md): Sanitize an LLM response before the runtime records it. - [Type Alias LlmStream Execution Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmstreamexecutionfn.md): Wrap or replace streaming LLM execution. - [Type Alias LlmStream Execution Next Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-llmstreamexecutionnextfn.md): Continuation type invoked by streaming LLM execution intercepts. - [Trait LlmStream Inner](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/trait-llmstreaminner.md): Internal close-aware stream implementation. - [Type Alias Tool Conditional Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-toolconditionalfn.md): Decide whether a tool call is allowed to continue. - [Struct Tool Execution Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/struct-toolexecutioncontext.md): Per-call context delivered to a tool execution intercept. - [Type Alias Tool Execution Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-toolexecutionfn.md): Wrap or replace tool execution with access to the full call context. - [Type Alias Tool Execution Next Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-toolexecutionnextfn.md): Continuation type invoked by tool execution intercepts. - [Type Alias Tool Intercept Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-toolinterceptfn.md): Rewrite tool arguments before execution. - [Type Alias Tool Sanitize Fn](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/callbacks/type-toolsanitizefn.md): Sanitize a tool request payload before the runtime records it. - [Module global](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/global.md): Process-global access to the shared runtime context state. - [Function global_context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/global/fn-global-context.md): Return the process-global runtime context state handle. - [Module scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack.md): Scope stack storage and propagation helpers. - [Struct Propagation Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/struct-propagationcontext.md): Versioned, transport-neutral causal context for crossing a Relay boundary. - [Struct Scope Stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/struct-scopestack.md): Mutable stack of active scopes plus their scope-local registries. - [Struct Thread Scope Stack Binding](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/struct-threadscopestackbinding.md): Captured thread-local scope stack binding. - [Static TASK_SCOPE_STACK](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/static-task-scope-stack.md): Task-local scope stack handle used by async execution contexts. - [Function capture_propagation_context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-capture-propagation-context.md): Capture the current causal parent and its Relay root when available. - [Function capture_propagation_context_with_root](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-capture-propagation-context-with-root.md): Capture the current causal parent and an application-supplied session root. Without an imported W3C parent, the supplied root determines the receiver's trace. An imported W3C parent retains precedence over the Relay root. Passing `None` has the same behavior as `capture_rootless_propagation_context`. - [Function capture_rootless_propagation_context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-capture-rootless-propagation-context.md): Capture the current causal parent without a root UUID. - [Function capture_thread_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-capture-thread-scope-stack.md): Capture the current thread-local scope stack binding. - [Function capture_traceparent](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-capture-traceparent.md): Capture the current canonical W3C `traceparent` value. - [Function create_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-create-scope-stack.md): Create a new scope stack handle with an implicit root scope. - [Function create_scope_stack_from_propagation](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-create-scope-stack-from-propagation.md): Create an isolated scope stack rooted below a supplied propagation context. - [Function current_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-current-scope-stack.md): Return the scope stack visible to the current execution context. - [Function fork_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-fork-scope-stack.md): Create an isolated scope stack below the current causal parent. - [Function propagate_scope_to_thread](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-propagate-scope-to-thread.md): Capture the current scope stack handle for use in another thread. - [Function restore_thread_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-restore-thread-scope-stack.md): Restore a previously captured thread-local scope stack binding. - [Function scope_stack_active](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-scope-stack-active.md): Report whether the current context has an explicitly active scope stack. - [Function set_thread_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-set-thread-scope-stack.md): Install an explicit scope stack for the current thread. - [Function sync_thread_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-sync-thread-scope-stack.md): Synchronize the thread-local scope stack without marking it explicit. - [Function task_scope_push](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-task-scope-push.md): Push a scope handle onto the active stack. - [Function task_scope_remove](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-task-scope-remove.md): Remove a scope handle from the active stack. - [Function task_scope_top](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-task-scope-top.md): Clone the current top-most scope handle from the active stack. - [Function with_active_event_uuid](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-with-active-event-uuid.md): Run a future with `uuid` as the causally active managed event. - [Function with_scope_stack](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/fn-with-scope-stack.md): Run a synchronous callback with `handle` as the visible scope stack. - [Type Alias Scope Stack Handle](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/type-scopestackhandle.md): Shared handle type for the runtime scope stack. - [Module state](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/state.md): Process-global runtime state and middleware-chain builders. - [Struct Nemo Relay Context State](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/state/struct-nemorelaycontextstate.md): Process-global runtime state backing middleware and event emission. - [Module subscriber_dispatcher](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/subscriber_dispatcher.md): Asynchronous subscriber delivery for native targets. - [Function flush_subscribers](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/subscriber_dispatcher/fn-flush-subscribers.md): Wait for all queued subscriber callbacks and managed terminal publications registered before this call, including publications emitted transitively by those callbacks. - [Type Alias Publication Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/subscriber_dispatcher/type-publicationcontext.md): Binding-owned context captured when an event is emitted. - [Struct LlmExecution Context](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/struct-llmexecutioncontext.md): Codec access for one LLM execution. - [Enum Builtin LlmCodec](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/enum-builtinllmcodec.md): Relay's built-in LLM codec identities. - [Enum LlmCodec Identity](https://docs.nvidia.com/nemo/relay/v0.10.0/reference/api/rust-library-reference/nemo-relay/api/runtime/enum-llmcodecidentity.md): Per-call LLM codec identity supplied to sanitizer and SDK callbacks.