ruvswarm_core/
lib.rs

1//! Core orchestration and agent traits for RUV Swarm
2//!
3//! This crate provides the foundational building blocks for creating
4//! distributed AI agent swarms with cognitive diversity patterns.
5//!
6//! # Features
7//!
8//! - **Agent Trait**: Core abstraction for all swarm agents
9//! - **Task Management**: Distributed task queue with priority scheduling
10//! - **Swarm Orchestration**: Multiple topology and distribution strategies
11//! - **Cognitive Patterns**: Support for diverse thinking patterns
12//! - **No-std Support**: Can run in embedded environments
13//!
14//! # Example
15//!
16//! ```rust,no_run
17//! use ruvswarm_core::{Agent, Swarm, SwarmConfig, Task, Priority};
18//! use async_trait::async_trait;
19//!
20//! // Define a simple agent
21//! struct ComputeAgent {
22//!     id: String,
23//!     capabilities: Vec<String>,
24//! }
25//!
26//! #[async_trait]
27//! impl Agent for ComputeAgent {
28//!     type Input = f64;
29//!     type Output = f64;
30//!     type Error = std::io::Error;
31//!
32//!     async fn process(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
33//!         Ok(input * 2.0)
34//!     }
35//!
36//!     fn capabilities(&self) -> &[String] {
37//!         &self.capabilities
38//!     }
39//!
40//!     fn id(&self) -> &str {
41//!         &self.id
42//!     }
43//! }
44//! ```
45
46#![cfg_attr(not(feature = "std"), no_std)]
47#![warn(missing_docs)]
48#![warn(clippy::all)]
49#![warn(clippy::pedantic)]
50#![allow(clippy::module_name_repetitions)]
51#![allow(clippy::must_use_candidate)]
52
53#[cfg(not(feature = "std"))]
54extern crate alloc;
55
56pub mod agent;
57pub mod error;
58pub mod swarm;
59pub mod task;
60pub mod topology;
61
62// Async modules
63#[cfg(feature = "std")]
64pub mod async_swarm;
65pub mod swarm_trait;
66
67#[cfg(test)]
68mod tests;
69
70// Re-export commonly used types
71pub use agent::{
72    Agent, AgentMessage, AgentMetadata, AgentMetrics, BoxedAgent, CognitivePattern, ErasedAgent,
73    HealthStatus, MessageType, ResourceRequirements, Capability, DynamicAgent, AgentStatus, AgentId
74};
75
76#[cfg(test)]
77pub use agent::MockAgent;
78
79pub use error::{Result, SwarmError};
80
81#[cfg(feature = "std")]
82pub use swarm::{Swarm, SwarmConfig, SwarmMetrics};
83
84#[cfg(feature = "std")]
85pub use async_swarm::{AsyncSwarm, AsyncSwarmConfig, AsyncSwarmMetrics, AsyncSwarmTrait};
86
87pub use swarm_trait::{
88    SwarmSync, SwarmAsync, SwarmMixed, SwarmOrchestrator, SwarmFactory, SwarmBuilder,
89    SwarmLifecycle, SwarmLifecycleState, SwarmMonitoring, SwarmHealthStatus,
90    SwarmPerformanceMetrics, SwarmErrorStatistics, ErrorTrend, SwarmConfigSummary,
91    SwarmMetricsCore,
92};
93
94pub use topology::{Topology, TopologyType};
95
96pub use task::{
97    DistributionStrategy, Task, TaskId, TaskPriority as Priority, TaskResult, TaskStatus,
98};
99
100/// Prelude module for convenient imports
101pub mod prelude {
102    pub use crate::agent::{Agent, CognitivePattern};
103    pub use crate::error::Result;
104    #[cfg(feature = "std")]
105    pub use crate::swarm::{Swarm, SwarmConfig};
106    #[cfg(feature = "std")]
107    pub use crate::async_swarm::{AsyncSwarm, AsyncSwarmConfig, AsyncSwarmTrait};
108    pub use crate::swarm_trait::{SwarmSync, SwarmAsync, SwarmOrchestrator};
109    pub use crate::task::{Task, TaskId, TaskPriority as Priority};
110}
111
112/// Version information
113pub const VERSION: &str = env!("CARGO_PKG_VERSION");
114
115/// Library metadata
116pub struct Metadata;
117
118impl Metadata {
119    /// Get the library name
120    pub fn name() -> &'static str {
121        env!("CARGO_PKG_NAME")
122    }
123
124    /// Get the library version
125    pub fn version() -> &'static str {
126        VERSION
127    }
128
129    /// Get the library description
130    pub fn description() -> &'static str {
131        env!("CARGO_PKG_DESCRIPTION")
132    }
133}