pub trait BaseAsyncAgent: Send + Sync {
// Required method
fn receive_event_async<'life0, 'async_trait>(
&'life0 self,
event: Box<dyn Event>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Event>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Base trait for all asynchronous agents in the system.
Agents process events and optionally emit new events. This trait defines the core interface that all agents must implement.
§Examples
use mojentic::agents::BaseAsyncAgent;
use mojentic::event::Event;
use mojentic::Result;
use async_trait::async_trait;
struct MyAgent;
#[async_trait]
impl BaseAsyncAgent for MyAgent {
async fn receive_event_async(&self, event: Box<dyn Event>) -> Result<Vec<Box<dyn Event>>> {
// Process the event and return new events
Ok(vec![])
}
}Required Methods§
Sourcefn receive_event_async<'life0, 'async_trait>(
&'life0 self,
event: Box<dyn Event>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Event>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn receive_event_async<'life0, 'async_trait>(
&'life0 self,
event: Box<dyn Event>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Event>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process an event asynchronously and return resulting events.
This method is called when an event is routed to this agent. The agent can perform any async work needed and return zero or more new events to be processed.
§Arguments
event- The event to process
§Returns
A vector of new events to be dispatched, or an error if processing failed.