pub struct AgentContext { /* private fields */ }Expand description
Event-scoped context that identifies a single flow across agents and carries auxiliary metadata.
A context is created per externally triggered event (user input, timer, webhook, etc.) so that agents connected through channels can recognize they are handling the same flow. It can carry auxiliary metadata useful for processing without altering the primary payload.
When a single datum fans out into multiple derived items (e.g., a map operation), frames track
the branching lineage. Because mapping can nest, frames behave like a stack to preserve ancestry.
Instances are cheap to clone and return new copies instead of mutating in place.
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn get_var(&self, key: &str) -> Option<&AgentValue>
pub fn get_var(&self, key: &str) -> Option<&AgentValue>
Retrieves an immutable reference to a stored variable, if present.
Sourcepub fn with_var(&self, key: String, value: AgentValue) -> Self
pub fn with_var(&self, key: String, value: AgentValue) -> Self
Returns a new context with the provided variable inserted while keeping the current context unchanged.
Source§impl AgentContext
impl AgentContext
Sourcepub fn frames(&self) -> Option<&Vector<Frame>>
pub fn frames(&self) -> Option<&Vector<Frame>>
Returns the current frame stack, if any frames have been pushed.
Sourcepub fn push_frame(&self, name: String, data: AgentValue) -> Self
pub fn push_frame(&self, name: String, data: AgentValue) -> Self
Appends a new frame to the end of the stack and returns the updated context.
Sourcepub fn push_map_frame(
&self,
index: usize,
len: usize,
) -> Result<Self, AgentError>
pub fn push_map_frame( &self, index: usize, len: usize, ) -> Result<Self, AgentError>
Pushes a map frame with index/length metadata after validating bounds.
Sourcepub fn current_map_frame(&self) -> Result<Option<(usize, usize)>, AgentError>
pub fn current_map_frame(&self) -> Result<Option<(usize, usize)>, AgentError>
Returns the most recent map frame’s (index, length) if present at the top of the stack.
Sourcepub fn pop_map_frame(&self) -> Result<AgentContext, AgentError>
pub fn pop_map_frame(&self) -> Result<AgentContext, AgentError>
Removes the most recent map frame, erroring if the top frame is missing or not a map frame.
Sourcepub fn map_frame_indices(&self) -> Result<Vec<(usize, usize)>, AgentError>
pub fn map_frame_indices(&self) -> Result<Vec<(usize, usize)>, AgentError>
Collects all map frame (index, length) tuples in order, validating each entry.
Sourcepub fn ctx_key(&self) -> Result<String, AgentError>
pub fn ctx_key(&self) -> Result<String, AgentError>
Returns a stable key combining the context id with all map frame indices, if present.
Trait Implementations§
Source§impl Clone for AgentContext
impl Clone for AgentContext
Source§fn clone(&self) -> AgentContext
fn clone(&self) -> AgentContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AgentContext
impl Debug for AgentContext
Source§impl Default for AgentContext
impl Default for AgentContext
Source§fn default() -> AgentContext
fn default() -> AgentContext
Source§impl<'de> Deserialize<'de> for AgentContext
impl<'de> Deserialize<'de> for AgentContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AgentContext
impl RefUnwindSafe for AgentContext
impl Send for AgentContext
impl Sync for AgentContext
impl Unpin for AgentContext
impl UnwindSafe for AgentContext
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
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, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more