Mesh

Trait Mesh 

Source
pub trait Mesh: Send + Sync {
    // Required methods
    fn start<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn add_agent<'life0, 'async_trait>(
        &'life0 self,
        agent: Box<dyn Agent>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn send<'life0, 'async_trait>(
        &'life0 self,
        message: Message,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Trait for agent coordination and message routing.

A mesh manages a collection of agents and handles communication between them. The primary implementation is [enki_local::LocalMesh] for single-process scenarios.

§Lifecycle

  1. Create a mesh with new()
  2. Add agents with add_agent()
  3. Start the mesh with start() - calls on_start for all agents
  4. Send messages with send()
  5. Stop the mesh with stop() - calls on_stop for all agents

§Example

use enki_local::LocalMesh;
use enki_core::Mesh;

let mesh = LocalMesh::new("my-mesh");
// mesh.add_agent(Box::new(my_agent)).await?;
mesh.start().await?;
// ... use the mesh ...
mesh.stop().await?;

Required Methods§

Source

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

Start the mesh and all registered agents.

Calls on_start for each agent.

Source

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

Stop the mesh and all agents.

Calls on_stop for each agent.

Source

fn add_agent<'life0, 'async_trait>( &'life0 self, agent: Box<dyn Agent>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Add an agent to the mesh.

The agent will be started when start() is called, or immediately if the mesh is already running.

Source

fn send<'life0, 'async_trait>( &'life0 self, message: Message, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Send a message (routing determined by message.to field).

Implementors§