mod context_helpers#

module context_helpers#

Context helpers for reading scope metadata on the intercept hot path.

These functions read from the NeMo Flow scope stack (via current_scope_stack) to extract information needed by the LLM request intercept:

All functions are safe to call from sync contexts (intercepts are sync closures). They acquire a read lock on the scope stack, which is always fast.

Metadata Convention

Manual latency sensitivity is stored in scope metadata under the JSON path /nemo_flow_adaptive/latency_sensitivity as a positive integer.

Variables

const LATENCY_SENSITIVITY_POINTER: &str#

Metadata key path for manual latency sensitivity annotation.

Functions

fn extract_scope_path() -> Vec<String>#

Extracts the current function call path from the NeMo Flow scope stack.

Walks all scopes from root to top, skipping the root scope (index 0), and collects names of Agent and Function scopes. This path is used for prediction trie lookup.

Returns

A vector of scope names from the current Agent and Function scope path. Returns an empty vector when the scope stack cannot be read safely.

Notes

The implicit root scope is always skipped.

fn read_manual_latency_sensitivity() -> Option<u32>#

Reads the maximum manual latency sensitivity from all scopes in the current scope stack.

Walks all scopes and checks metadata for /nemo_flow_adaptive/latency_sensitivity. Uses max-merge semantics: if multiple scopes have annotations, the highest wins.

Returns

The highest manual latency sensitivity annotation visible on the current scope stack, or None when no annotation exists.

Notes

Returns None when the scope stack cannot be read safely.

fn resolve_agent_id() -> Option<String>#

Resolves the agent ID from the current scope stack.

Walks all scopes from root to top, skipping the implicit root scope (index 0, name=“root”), and returns the name of the first Agent-typed scope.

Returns

The first Agent scope name found on the current stack, or None when no Agent scope is active.

Notes

Returns None when the scope stack cannot be read safely.

fn resolve_shared_parent_scope_identity() -> Option<SharedParentScopeIdentity>#

Resolves the session-local identity used by warm-first cohort coordination.

The shared parent must come from the parent scope, not the current scope’s own UUID, so siblings under the same fan-out coordinate with one another. Returns None if the scope stack cannot be read.

fn set_latency_sensitivity(value: u32) -> std::result::Result<(), String>#

Sets latency sensitivity on the current (top) scope using max-merge semantics.

If the current scope already has a latency_sensitivity value, the new value is only applied if it is greater than the existing one.

Parameters

  • value: New non-negative latency sensitivity hint (>= 0) for the current top scope.

Returns

Ok(()) when the current scope metadata has been updated or left unchanged.

Errors

Returns an error string when the scope stack lock is poisoned.

Notes

Existing non-negative latency sensitivity values are updated using max-merge semantics.

Structs and Unions

struct SharedParentScopeIdentity#

Session-local scope identity used to coordinate warm-first cohorts.

root_uuid: Uuid#

UUID of the root scope for the current execution tree.

shared_parent_uuid: Uuid#

UUID of the parent scope shared by sibling fan-out work.