pub struct NemoFlowContextState {Show 13 fields
pub tool_sanitize_request_guardrails: SortedRegistry<GuardrailEntry<ToolSanitizeFn>>,
pub tool_sanitize_response_guardrails: SortedRegistry<GuardrailEntry<ToolSanitizeFn>>,
pub tool_conditional_execution_guardrails: SortedRegistry<GuardrailEntry<ToolConditionalFn>>,
pub tool_request_intercepts: SortedRegistry<Intercept<ToolInterceptFn>>,
pub tool_execution_intercepts: SortedRegistry<ExecutionIntercept<ToolExecutionFn>>,
pub llm_sanitize_request_guardrails: SortedRegistry<GuardrailEntry<LlmSanitizeRequestFn>>,
pub llm_sanitize_response_guardrails: SortedRegistry<GuardrailEntry<LlmSanitizeResponseFn>>,
pub llm_conditional_execution_guardrails: SortedRegistry<GuardrailEntry<LlmConditionalFn>>,
pub llm_request_intercepts: SortedRegistry<Intercept<LlmRequestInterceptFn>>,
pub llm_execution_intercepts: SortedRegistry<ExecutionIntercept<LlmExecutionFn>>,
pub llm_stream_execution_intercepts: SortedRegistry<ExecutionIntercept<LlmStreamExecutionFn>>,
pub event_subscribers: HashMap<String, EventSubscriberFn>,
pub extensions: HashMap<String, Box<dyn Any + Send + Sync>>,
}Expand description
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.
Fields§
§tool_sanitize_request_guardrails: SortedRegistry<GuardrailEntry<ToolSanitizeFn>>Global tool request sanitizers applied to emitted tool-start payloads.
tool_sanitize_response_guardrails: SortedRegistry<GuardrailEntry<ToolSanitizeFn>>Global tool response sanitizers applied to emitted tool-end payloads.
tool_conditional_execution_guardrails: SortedRegistry<GuardrailEntry<ToolConditionalFn>>Global tool guardrails that can reject execution before the callback runs.
tool_request_intercepts: SortedRegistry<Intercept<ToolInterceptFn>>Global tool request intercepts that can rewrite arguments before execution.
tool_execution_intercepts: SortedRegistry<ExecutionIntercept<ToolExecutionFn>>Global tool execution intercepts that wrap or replace callback execution.
llm_sanitize_request_guardrails: SortedRegistry<GuardrailEntry<LlmSanitizeRequestFn>>Global LLM request sanitizers applied to emitted LLM-start payloads.
llm_sanitize_response_guardrails: SortedRegistry<GuardrailEntry<LlmSanitizeResponseFn>>Global LLM response sanitizers applied to emitted LLM-end payloads.
llm_conditional_execution_guardrails: SortedRegistry<GuardrailEntry<LlmConditionalFn>>Global LLM guardrails that can reject execution before the provider callback runs.
llm_request_intercepts: SortedRegistry<Intercept<LlmRequestInterceptFn>>Global LLM request intercepts that can rewrite or annotate requests.
llm_execution_intercepts: SortedRegistry<ExecutionIntercept<LlmExecutionFn>>Global non-streaming LLM execution intercepts that wrap callback execution.
llm_stream_execution_intercepts: SortedRegistry<ExecutionIntercept<LlmStreamExecutionFn>>Global streaming LLM execution intercepts that wrap stream-producing callbacks.
event_subscribers: HashMap<String, EventSubscriberFn>Global lifecycle subscribers notified after runtime events are emitted.
extensions: HashMap<String, Box<dyn Any + Send + Sync>>Arbitrary binding- or integration-specific runtime extensions.
Implementations§
Source§impl NemoFlowContextState
impl NemoFlowContextState
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty runtime state with no registered middleware.
§Returns
A NemoFlowContextState with empty registries, no subscribers, and no
extensions.
Sourcepub fn set_extension<T: Any + Send + Sync>(
&mut self,
key: impl Into<String>,
value: T,
)
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.
Sourcepub fn remove_extension(&mut self, key: &str) -> bool
pub fn remove_extension(&mut self, key: &str) -> bool
Sourcepub fn collect_event_subscribers(
&self,
scope_local_subscribers: &[EventSubscriberFn],
) -> Vec<EventSubscriberFn> ⓘ
pub fn collect_event_subscribers( &self, scope_local_subscribers: &[EventSubscriberFn], ) -> Vec<EventSubscriberFn> ⓘ
Sourcepub fn emit_event(event: &Event, subscribers: &[EventSubscriberFn])
pub fn emit_event(event: &Event, subscribers: &[EventSubscriberFn])
Deliver an event to every subscriber in order.
§Parameters
event: Fully constructed lifecycle event to deliver.subscribers: Subscribers that should observe the event.
Sourcepub fn create_event(&self, params: MarkEvent) -> Event
pub fn create_event(&self, params: MarkEvent) -> Event
Sourcepub fn create_scope_handle(
&self,
params: CreateScopeHandleParams<'_>,
) -> ScopeHandle
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.
Sourcepub fn build_scope_start_event(
&self,
handle: &ScopeHandle,
data: Option<Json>,
) -> Event
pub fn build_scope_start_event( &self, handle: &ScopeHandle, data: Option<Json>, ) -> Event
Sourcepub fn end_scope_handle(
&self,
handle: &ScopeHandle,
data: Option<Json>,
) -> Event
pub fn end_scope_handle( &self, handle: &ScopeHandle, data: Option<Json>, ) -> Event
Sourcepub fn build_scope_end_event(&self, params: EndScopeHandleParams<'_>) -> Event
pub fn build_scope_end_event(&self, params: EndScopeHandleParams<'_>) -> Event
Sourcepub fn create_tool_handle(
&self,
params: CreateToolHandleParams<'_>,
) -> ToolHandle
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.
Sourcepub fn build_tool_start_event(
&self,
handle: &ToolHandle,
data: Option<Json>,
) -> Event
pub fn build_tool_start_event( &self, handle: &ToolHandle, data: Option<Json>, ) -> Event
Sourcepub fn end_tool_handle(
&self,
handle: &ToolHandle,
data: Option<Json>,
metadata: Option<Json>,
) -> Event
pub fn end_tool_handle( &self, handle: &ToolHandle, data: Option<Json>, metadata: Option<Json>, ) -> Event
Sourcepub fn build_tool_end_event(&self, params: EndToolHandleParams<'_>) -> Event
pub fn build_tool_end_event(&self, params: EndToolHandleParams<'_>) -> Event
Sourcepub fn create_llm_handle(&self, params: CreateLlmHandleParams<'_>) -> LlmHandle
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.
Sourcepub fn build_llm_start_event(
&self,
handle: &LlmHandle,
data: Option<Json>,
annotated_request: Option<Arc<AnnotatedLlmRequest>>,
) -> Event
pub fn build_llm_start_event( &self, handle: &LlmHandle, data: Option<Json>, annotated_request: Option<Arc<AnnotatedLlmRequest>>, ) -> Event
Sourcepub fn end_llm_handle(
&self,
handle: &LlmHandle,
data: Option<Json>,
metadata: Option<Json>,
annotated_response: Option<Arc<AnnotatedLlmResponse>>,
) -> Event
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 overhandle.metadata.annotated_response: Optional normalized response annotation.
§Returns
An LLM-end Event derived from the provided handle.
Sourcepub fn build_llm_end_event(&self, params: EndLlmHandleParams<'_>) -> Event
pub fn build_llm_end_event(&self, params: EndLlmHandleParams<'_>) -> Event
Sourcepub fn tool_sanitize_request_chain(
&self,
name: &str,
args: Json,
scope_locals: &[&SortedRegistry<GuardrailEntry<ToolSanitizeFn>>],
) -> Json
pub fn tool_sanitize_request_chain( &self, name: &str, args: Json, scope_locals: &[&SortedRegistry<GuardrailEntry<ToolSanitizeFn>>], ) -> Json
Run tool request sanitizers across global and scope-local registries.
§Parameters
name: Tool name associated with the request.args: Raw tool arguments to sanitize for observability.scope_locals: Scope-local sanitizer registries collected from the active scope stack.
§Returns
The sanitized JSON payload after every matching guardrail has run.
Sourcepub fn tool_sanitize_response_chain(
&self,
name: &str,
result: Json,
scope_locals: &[&SortedRegistry<GuardrailEntry<ToolSanitizeFn>>],
) -> Json
pub fn tool_sanitize_response_chain( &self, name: &str, result: Json, scope_locals: &[&SortedRegistry<GuardrailEntry<ToolSanitizeFn>>], ) -> Json
Run tool response sanitizers across global and scope-local registries.
§Parameters
name: Tool name associated with the response.result: Raw tool result to sanitize for observability.scope_locals: Scope-local sanitizer registries collected from the active scope stack.
§Returns
The sanitized JSON payload after every matching guardrail has run.
Sourcepub fn tool_conditional_execution_chain(
&self,
name: &str,
args: &Json,
scope_locals: &[&SortedRegistry<GuardrailEntry<ToolConditionalFn>>],
) -> Result<Option<String>>
pub fn tool_conditional_execution_chain( &self, name: &str, args: &Json, scope_locals: &[&SortedRegistry<GuardrailEntry<ToolConditionalFn>>], ) -> Result<Option<String>>
Evaluate tool conditional-execution guardrails in priority order.
§Parameters
name: Tool name associated with the request.args: Tool arguments to validate.scope_locals: Scope-local conditional guardrail registries collected from the active scope stack.
§Returns
A Result containing Ok(None) when execution is allowed or
Ok(Some(reason)) when a guardrail rejects the call.
§Errors
Propagates any error returned by a guardrail callback.
Sourcepub fn tool_request_intercepts_chain(
&self,
name: &str,
args: Json,
scope_locals: &[&SortedRegistry<Intercept<ToolInterceptFn>>],
) -> Result<Json>
pub fn tool_request_intercepts_chain( &self, name: &str, args: Json, scope_locals: &[&SortedRegistry<Intercept<ToolInterceptFn>>], ) -> Result<Json>
Run tool request intercepts in priority order.
§Parameters
name: Tool name associated with the request.args: Tool arguments to pass through the intercept chain.scope_locals: Scope-local request intercept registries collected from the active scope stack.
§Returns
A Result containing the final JSON argument payload.
§Errors
Propagates any error returned by an intercept callback.
§Notes
If an intercept entry has break_chain enabled, later intercepts are
skipped after that entry runs.
Sourcepub fn tool_build_execution_chain(
&self,
name: &str,
default_fn: ToolExecutionNextFn,
scope_locals: &[&SortedRegistry<ExecutionIntercept<ToolExecutionFn>>],
) -> ToolExecutionNextFn
pub fn tool_build_execution_chain( &self, name: &str, default_fn: ToolExecutionNextFn, scope_locals: &[&SortedRegistry<ExecutionIntercept<ToolExecutionFn>>], ) -> ToolExecutionNextFn
Build the composed tool execution continuation chain.
§Parameters
name: Tool name passed into each execution intercept.default_fn: Base tool callback that should run after all intercepts.scope_locals: Scope-local execution intercept registries collected from the active scope stack.
§Returns
A composed ToolExecutionNextFn that wraps default_fn in every
matching execution intercept.
Sourcepub fn llm_sanitize_request_chain(
&self,
request: LlmRequest,
scope_locals: &[&SortedRegistry<GuardrailEntry<LlmSanitizeRequestFn>>],
) -> LlmRequest
pub fn llm_sanitize_request_chain( &self, request: LlmRequest, scope_locals: &[&SortedRegistry<GuardrailEntry<LlmSanitizeRequestFn>>], ) -> LlmRequest
Run LLM request sanitizers across global and scope-local registries.
§Parameters
request: Raw LLM request to sanitize for observability.scope_locals: Scope-local sanitizer registries collected from the active scope stack.
§Returns
The sanitized LlmRequest after every matching guardrail has run.
Sourcepub fn llm_sanitize_response_chain(
&self,
response: Json,
scope_locals: &[&SortedRegistry<GuardrailEntry<LlmSanitizeResponseFn>>],
) -> Json
pub fn llm_sanitize_response_chain( &self, response: Json, scope_locals: &[&SortedRegistry<GuardrailEntry<LlmSanitizeResponseFn>>], ) -> Json
Run LLM response sanitizers across global and scope-local registries.
§Parameters
response: Raw response payload to sanitize for observability.scope_locals: Scope-local sanitizer registries collected from the active scope stack.
§Returns
The sanitized response payload after every matching guardrail has run.
Sourcepub fn llm_conditional_execution_chain(
&self,
request: &LlmRequest,
scope_locals: &[&SortedRegistry<GuardrailEntry<LlmConditionalFn>>],
) -> Result<Option<String>>
pub fn llm_conditional_execution_chain( &self, request: &LlmRequest, scope_locals: &[&SortedRegistry<GuardrailEntry<LlmConditionalFn>>], ) -> Result<Option<String>>
Evaluate LLM conditional-execution guardrails in priority order.
§Parameters
request: LLM request to validate.scope_locals: Scope-local conditional guardrail registries collected from the active scope stack.
§Returns
A Result containing Ok(None) when execution is allowed or
Ok(Some(reason)) when a guardrail rejects the call.
§Errors
Propagates any error returned by a guardrail callback.
Sourcepub fn llm_request_intercepts_chain(
&self,
name: &str,
request: LlmRequest,
annotated: Option<AnnotatedLlmRequest>,
scope_locals: &[&SortedRegistry<Intercept<LlmRequestInterceptFn>>],
) -> Result<(LlmRequest, Option<AnnotatedLlmRequest>)>
pub fn llm_request_intercepts_chain( &self, name: &str, request: LlmRequest, annotated: Option<AnnotatedLlmRequest>, scope_locals: &[&SortedRegistry<Intercept<LlmRequestInterceptFn>>], ) -> Result<(LlmRequest, Option<AnnotatedLlmRequest>)>
Run LLM request intercepts in priority order.
§Parameters
name: Logical provider or model family name.request: LLM request to pass through the intercept chain.annotated: Optional normalized request annotation to carry through the chain.scope_locals: Scope-local request intercept registries collected from the active scope stack.
§Returns
A Result containing the final request and annotation pair.
§Errors
Propagates any error returned by an intercept callback.
§Notes
If an intercept entry has break_chain enabled, later intercepts are
skipped after that entry runs.
Sourcepub fn llm_build_execution_chain(
&self,
name: &str,
default_fn: LlmExecutionNextFn,
scope_locals: &[&SortedRegistry<ExecutionIntercept<LlmExecutionFn>>],
) -> LlmExecutionNextFn
pub fn llm_build_execution_chain( &self, name: &str, default_fn: LlmExecutionNextFn, scope_locals: &[&SortedRegistry<ExecutionIntercept<LlmExecutionFn>>], ) -> LlmExecutionNextFn
Build the composed non-streaming LLM execution continuation chain.
§Parameters
name: Logical provider or model family name passed into each execution intercept.default_fn: Base provider callback that should run after all intercepts.scope_locals: Scope-local execution intercept registries collected from the active scope stack.
§Returns
A composed LlmExecutionNextFn that wraps default_fn in every
matching execution intercept.
Sourcepub fn llm_stream_build_execution_chain(
&self,
name: &str,
default_fn: LlmStreamExecutionNextFn,
scope_locals: LlmStreamExecutionRegistryRefs<'_>,
) -> LlmStreamExecutionNextFn
pub fn llm_stream_build_execution_chain( &self, name: &str, default_fn: LlmStreamExecutionNextFn, scope_locals: LlmStreamExecutionRegistryRefs<'_>, ) -> LlmStreamExecutionNextFn
Build the composed streaming LLM execution continuation chain.
§Parameters
name: Logical provider or model family name passed into each execution intercept.default_fn: Base stream-producing callback that should run after all intercepts.scope_locals: Scope-local execution intercept registries collected from the active scope stack.
§Returns
A composed LlmStreamExecutionNextFn that wraps default_fn in every
matching execution intercept.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NemoFlowContextState
impl !RefUnwindSafe for NemoFlowContextState
impl Send for NemoFlowContextState
impl Sync for NemoFlowContextState
impl Unpin for NemoFlowContextState
impl UnsafeUnpin for NemoFlowContextState
impl !UnwindSafe for NemoFlowContextState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request