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: StringThe name of the mesh this agent is running in.
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn new(mesh_name: String, request_queue: Option<Arc<RequestQueue>>) -> Self
pub fn new(mesh_name: String, request_queue: Option<Arc<RequestQueue>>) -> Self
Create a new agent context.
§Arguments
mesh_name- Name of the meshrequest_queue- Optional request queue for request/response pattern
Sourcepub fn report_result(&self, request_id: &str, response: String)
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.
Sourcepub fn has_request_queue(&self) -> bool
pub fn has_request_queue(&self) -> bool
Check if this context has a request queue available.
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<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
Mutably borrows from an owned value. Read more