Skip to main content

AsAgent

Trait AsAgent 

Source
pub trait AsAgent:
    HasAgentData
    + Send
    + Sync
    + 'static {
    // Required method
    fn new(
        ma: ModularAgent,
        id: String,
        spec: AgentSpec,
    ) -> Result<Self, AgentError>
       where Self: Sized;

    // Provided methods
    fn configs_changed(&mut self) -> Result<(), AgentError> { ... }
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn process<'life0, 'async_trait>(
        &'life0 mut self,
        _ctx: AgentContext,
        _port: String,
        _value: AgentValue,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Simplified trait for implementing custom agents.

Implement this trait instead of Agent directly. The Agent trait is automatically implemented for all types that implement AsAgent.

Required Methods§

Source

fn new( ma: ModularAgent, id: String, spec: AgentSpec, ) -> Result<Self, AgentError>
where Self: Sized,

Constructs a new agent instance.

Provided Methods§

Source

fn configs_changed(&mut self) -> Result<(), AgentError>

Called when configuration values change.

Override to react to configuration changes at runtime.

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the agent starts.

Override for initialization logic or to emit initial values.

Source

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when the agent stops.

Override for cleanup logic.

Source

fn process<'life0, 'async_trait>( &'life0 mut self, _ctx: AgentContext, _port: String, _value: AgentValue, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes an input message.

Override to implement the agent’s main logic.

Implementors§