Skip to main content

Agent

Trait Agent 

Source
pub trait Agent:
    Send
    + Sync
    + 'static {
Show 19 methods // Required methods fn new( ma: ModularAgent, id: String, spec: AgentSpec, ) -> Result<Self, AgentError> where Self: Sized; fn ma(&self) -> &ModularAgent; fn id(&self) -> &str; fn status(&self) -> &AgentStatus; fn spec(&self) -> &AgentSpec; fn update_spec(&mut self, spec_update: &Value) -> Result<(), AgentError>; fn def_name(&self) -> &str; fn configs(&self) -> Result<&AgentConfigs, AgentError>; fn set_config( &mut self, key: String, value: AgentValue, ) -> Result<(), AgentError>; fn set_configs(&mut self, configs: AgentConfigs) -> Result<(), AgentError>; fn preset_id(&self) -> &str; fn set_preset_id(&mut self, preset_id: String); 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; fn as_any(&self) -> &dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any; // Provided methods fn get_global_configs(&self) -> Option<AgentConfigs> { ... } fn runtime(&self) -> &Runtime { ... }
}
Expand description

The core trait for all agents.

All agents implement this trait. Defines lifecycle management, configuration access, and message processing.

Required Methods§

Source

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

Constructs a new agent instance.

Source

fn ma(&self) -> &ModularAgent

Returns the ModularAgent.

Source

fn id(&self) -> &str

Returns the unique agent ID.

Source

fn status(&self) -> &AgentStatus

Returns the current lifecycle status.

Source

fn spec(&self) -> &AgentSpec

Returns the agent specification.

Source

fn update_spec(&mut self, spec_update: &Value) -> Result<(), AgentError>

Updates the agent specification.

Source

fn def_name(&self) -> &str

Returns the agent definition name.

Source

fn configs(&self) -> Result<&AgentConfigs, AgentError>

Returns the agent’s configuration.

§Errors

Returns NoConfig if no configuration is available.

Source

fn set_config( &mut self, key: String, value: AgentValue, ) -> Result<(), AgentError>

Sets a configuration value.

Source

fn set_configs(&mut self, configs: AgentConfigs) -> Result<(), AgentError>

Sets the entire configuration.

Source

fn preset_id(&self) -> &str

Returns the preset ID this agent belongs to.

Source

fn set_preset_id(&mut self, preset_id: String)

Sets the preset ID.

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,

Starts the agent.

Called when the workflow starts. Use for initialization and initial output.

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,

Stops the agent.

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.

Called when the agent receives a value on an input port.

Source

fn as_any(&self) -> &dyn Any

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Provided Methods§

Source

fn get_global_configs(&self) -> Option<AgentConfigs>

Gets global configuration for this agent.

Source

fn runtime(&self) -> &Runtime

Returns the tokio runtime.

Implementations§

Source§

impl dyn Agent

Source

pub fn as_agent<T: Agent>(&self) -> Option<&T>

Source

pub fn as_agent_mut<T: Agent>(&mut self) -> Option<&mut T>

Implementors§

Source§

impl<T: AsAgent> Agent for T