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:extract_scope_path: collects function names from the scope stack for trie lookupread_manual_latency_sensitivity: walks all scopes for manuallatency_sensitiveannotationsresolve_agent_id: returns the first Agent scope name from the scope stack
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_sensitivityas 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
Nonewhen no annotation exists.Notes
Returns
Nonewhen 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
Nonewhen no Agent scope is active.Notes
Returns
Nonewhen the scope stack cannot be read safely.
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
Noneif 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
Session-local scope identity used to coordinate warm-first cohorts.
UUID of the root scope for the current execution tree.
UUID of the parent scope shared by sibling fan-out work.