AgentContext

Struct AgentContext 

Source
pub struct AgentContext {
    pub mesh_name: String,
    /* private fields */
}
Expand description

Runtime context provided to agents during lifecycle and message handling.

The context gives agents access to mesh information and utilities for interacting with the request/response system.

§Example

async fn on_message(&mut self, msg: Message, ctx: &mut AgentContext) -> Result<()> {
    println!("Running in mesh: {}", ctx.mesh_name);
    if let Some(id) = msg.correlation_id() {
        ctx.report_result(&id, "Done!".to_string());
    }
    Ok(())
}

Fields§

§mesh_name: String

The name of the mesh this agent is running in.

Implementations§

Source§

impl AgentContext

Source

pub fn new(mesh_name: String, request_queue: Option<Arc<RequestQueue>>) -> Self

Create a new agent context.

§Arguments
  • mesh_name - Name of the mesh
  • request_queue - Optional request queue for request/response pattern
Source

pub fn report_result(&self, request_id: &str, response: String)

Report a result for a pending request.

Call this to send a response back to the requester when handling a message with a correlation ID.

Source

pub fn has_request_queue(&self) -> bool

Check if this context has a request queue available.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.