LocalMesh

Struct LocalMesh 

Source
pub struct LocalMesh { /* private fields */ }

Implementations§

Source§

impl LocalMesh

Source

pub fn new(name: impl Into<String>) -> Self

Examples found in repository?
examples/mesh_architecture.rs (line 80)
78async fn main() -> Result<()> {
79    // 1. Create the Mesh (wrapped in Arc for sharing)
80    let mesh = Arc::new(LocalMesh::new("main_mesh"));
81
82    // 2. Create Agents with reference to mesh
83    let completion = Arc::new(Notify::new());
84
85    let worker = Box::new(WorkerAgent { mesh: mesh.clone() });
86    let manager = Box::new(ManagerAgent {
87        mesh: mesh.clone(),
88        completion_notify: completion.clone(),
89    });
90
91    // 3. Register Agents
92    mesh.add_agent(worker).await?;
93    mesh.add_agent(manager).await?;
94
95    // 4. Start Mesh
96    mesh.start().await?;
97
98    // Wait for the interaction to complete
99    println!("Waiting for interaction to complete...");
100    // Timeout after 5 seconds
101    tokio::select! {
102        _ = completion.notified() => {
103            println!("Interaction completed successfully!");
104        }
105        _ = tokio::time::sleep(Duration::from_secs(5)) => {
106            println!("Timeout waiting for interaction.");
107        }
108    }
109
110    // 5. Stop Mesh
111    mesh.stop().await?;
112
113    Ok(())
114}
More examples
Hide additional examples
examples/llm_multi_agent_mesh.rs (line 226)
219async fn main() -> Result<()> {
220    println!("=== Ceylon Runtime - LLM Multi-Agent Mesh Example ===\n");
221    println!("This example demonstrates two LLM agents communicating via LocalMesh:");
222    println!("  1. Researcher Agent - Researches a given topic");
223    println!("  2. Summarizer Agent - Summarizes the research findings\n");
224
225    // 1. Create the Mesh
226    let mesh = Arc::new(LocalMesh::new("llm_mesh"));
227
228    // 2. Create completion notifier
229    let completion = Arc::new(Notify::new());
230
231    // 3. Create LLM-powered agents
232    let researcher = match ResearcherAgent::new(mesh.clone()) {
233        Ok(agent) => agent,
234        Err(e) => {
235            eprintln!("Failed to create Researcher agent: {}", e);
236            eprintln!("Make sure Ollama is running and gemma3:latest is available.");
237            return Err(e);
238        }
239    };
240
241    let summarizer = match SummarizerAgent::new(completion.clone()) {
242        Ok(agent) => agent,
243        Err(e) => {
244            eprintln!("Failed to create Summarizer agent: {}", e);
245            eprintln!("Make sure Ollama is running and gemma3:latest is available.");
246            return Err(e);
247        }
248    };
249
250    let coordinator = CoordinatorAgent {
251        mesh: mesh.clone(),
252        topic: "The benefits of Rust programming language for system development".to_string(),
253    };
254
255    // 4. Register agents with the mesh
256    mesh.add_agent(Box::new(researcher)).await?;
257    mesh.add_agent(Box::new(summarizer)).await?;
258    mesh.add_agent(Box::new(coordinator)).await?;
259
260    println!("✓ All agents registered successfully\n");
261
262    // 5. Start the mesh (this triggers on_start for all agents)
263    mesh.start().await?;
264
265    // 6. Wait for the workflow to complete
266    println!("Waiting for multi-agent workflow to complete...\n");
267    tokio::select! {
268        _ = completion.notified() => {
269            println!("Multi-agent workflow completed successfully!");
270        }
271        _ = tokio::time::sleep(Duration::from_secs(120)) => {
272            println!("Timeout waiting for workflow completion.");
273        }
274    }
275
276    // 7. Stop the mesh
277    mesh.stop().await?;
278
279    println!("\n=== Example finished ===");
280    Ok(())
281}
Source

pub fn request_queue(&self) -> Arc<RequestQueue>

Get the request queue (for sharing with agent wrappers)

Source§

impl LocalMesh

Source

pub async fn broadcast( &self, message: Message, exclude: Option<&str>, ) -> Result<Vec<Result<()>>>

Broadcast a message to all agents in the mesh

Source

pub async fn submit(&self, target: &str, payload: String) -> Result<String>

Submit a request (fire-and-forget). Returns request ID.

Source

pub fn get_pending(&self) -> Vec<MeshRequest>

Get pending requests

Source

pub fn has_pending(&self) -> bool

Check if there are pending requests

Source

pub fn get_results(&self) -> Vec<MeshResult>

Get available results (removes them from queue)

Source

pub fn peek_results(&self) -> Vec<MeshResult>

Peek at results without removing

Source

pub async fn send_reminders(&self, older_than_secs: f64) -> Result<Vec<String>>

Send reminders for stale requests

Source

pub async fn wait_for( &self, request_id: &str, timeout_secs: f64, reminder_interval_secs: f64, ) -> Result<MeshResult>

Wait for a specific result with auto-reminders

Source

pub async fn collect_results( &self, reminder_interval_secs: f64, ) -> Vec<MeshResult>

Collect all results, blocking until all pending complete

Trait Implementations§

Source§

impl Mesh for LocalMesh

Source§

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

Start the mesh and all registered agents. Read more
Source§

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

Stop the mesh and all agents. Read more
Source§

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

Add an agent to the mesh. Read more
Source§

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

Send a message to a specific agent by name.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,