pub struct LocalMesh { /* private fields */ }Implementations§
Source§impl LocalMesh
impl LocalMesh
Sourcepub fn new(name: impl Into<String>) -> Self
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
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}Sourcepub fn request_queue(&self) -> Arc<RequestQueue>
pub fn request_queue(&self) -> Arc<RequestQueue>
Get the request queue (for sharing with agent wrappers)
Source§impl LocalMesh
impl LocalMesh
Sourcepub async fn broadcast(
&self,
message: Message,
exclude: Option<&str>,
) -> Result<Vec<Result<()>>>
pub async fn broadcast( &self, message: Message, exclude: Option<&str>, ) -> Result<Vec<Result<()>>>
Broadcast a message to all agents in the mesh
Sourcepub async fn submit(&self, target: &str, payload: String) -> Result<String>
pub async fn submit(&self, target: &str, payload: String) -> Result<String>
Submit a request (fire-and-forget). Returns request ID.
Sourcepub fn get_pending(&self) -> Vec<MeshRequest>
pub fn get_pending(&self) -> Vec<MeshRequest>
Get pending requests
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if there are pending requests
Sourcepub fn get_results(&self) -> Vec<MeshResult>
pub fn get_results(&self) -> Vec<MeshResult>
Get available results (removes them from queue)
Sourcepub fn peek_results(&self) -> Vec<MeshResult>
pub fn peek_results(&self) -> Vec<MeshResult>
Peek at results without removing
Sourcepub async fn send_reminders(&self, older_than_secs: f64) -> Result<Vec<String>>
pub async fn send_reminders(&self, older_than_secs: f64) -> Result<Vec<String>>
Send reminders for stale requests
Sourcepub async fn wait_for(
&self,
request_id: &str,
timeout_secs: f64,
reminder_interval_secs: f64,
) -> Result<MeshResult>
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
Sourcepub async fn collect_results(
&self,
reminder_interval_secs: f64,
) -> Vec<MeshResult>
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
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,
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,
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
Auto Trait Implementations§
impl Freeze for LocalMesh
impl !RefUnwindSafe for LocalMesh
impl Send for LocalMesh
impl Sync for LocalMesh
impl Unpin for LocalMesh
impl !UnwindSafe for LocalMesh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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