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§
Sourcefn new(
ma: ModularAgent,
id: String,
spec: AgentSpec,
) -> Result<Self, AgentError>where
Self: Sized,
fn new(
ma: ModularAgent,
id: String,
spec: AgentSpec,
) -> Result<Self, AgentError>where
Self: Sized,
Constructs a new agent instance.
Provided Methods§
Sourcefn configs_changed(&mut self) -> Result<(), AgentError>
fn configs_changed(&mut self) -> Result<(), AgentError>
Called when configuration values change.
Override to react to configuration changes at runtime.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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.