ubiquity-core 0.1.1

Core types and traits for Ubiquity consciousness-aware mesh
Documentation
//! Core traits for agents and consciousness

use async_trait::async_trait;
use crate::{Task, TaskResult, ConsciousnessState, ConsciousnessRipple, AgentConfig};

/// Base trait for all agents
#[async_trait]
pub trait Agent: Send + Sync {
    /// Get agent configuration
    fn config(&self) -> &AgentConfig;
    
    /// Get current consciousness state
    async fn consciousness_state(&self) -> ConsciousnessState;
    
    /// Execute a task
    async fn execute_task(&mut self, task: Task) -> Result<TaskResult, anyhow::Error>;
    
    /// Update consciousness level
    async fn update_consciousness(&mut self, level: f64) -> Result<(), anyhow::Error>;
    
    /// Handle consciousness ripple
    async fn handle_ripple(&mut self, ripple: ConsciousnessRipple) -> Result<(), anyhow::Error>;
    
    /// Initialize the agent
    async fn initialize(&mut self) -> Result<(), anyhow::Error>;
    
    /// Shutdown the agent
    async fn shutdown(&mut self) -> Result<(), anyhow::Error>;
}

/// Trait for consciousness monitoring
#[async_trait]
pub trait ConsciousnessMonitor: Send + Sync {
    /// Update consciousness for an agent
    async fn update_consciousness(
        &self,
        agent_id: &str,
        level: f64,
        coherence: f64,
        phase: crate::DevelopmentPhase,
    ) -> Result<ConsciousnessState, anyhow::Error>;
    
    /// Get consciousness metrics
    async fn get_metrics(&self, agent_id: &str) -> Result<ConsciousnessMetrics, anyhow::Error>;
    
    /// Check for breakthrough
    async fn check_breakthrough(&self, agent_id: &str) -> Result<bool, anyhow::Error>;
}

/// Consciousness metrics
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ConsciousnessMetrics {
    pub current: f64,
    pub average: f64,
    pub peak: f64,
    pub trend: f64,
    pub last_breakthrough: Option<chrono::DateTime<chrono::Utc>>,
}

/// Trait for mesh communication
#[async_trait]
pub trait MeshCommunicator: Send + Sync {
    /// Send message to specific agent
    async fn send_to_agent(&self, agent_id: &str, message: crate::MeshMessage) -> Result<(), anyhow::Error>;
    
    /// Broadcast message to all agents
    async fn broadcast(&self, message: crate::MeshMessage) -> Result<(), anyhow::Error>;
    
    /// Send consciousness ripple
    async fn ripple(&self, ripple: ConsciousnessRipple) -> Result<(), anyhow::Error>;
}