2026-01-11 21:32:56 +00:00
|
|
|
// Adapter implementing SwarmCoordination trait using real SwarmCoordinator
|
|
|
|
|
// Decouples agent orchestration from swarm details
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
2026-01-11 21:46:08 +00:00
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
2026-01-11 21:32:56 +00:00
|
|
|
use vapora_swarm::coordinator::SwarmCoordinator;
|
|
|
|
|
|
2026-01-11 21:46:08 +00:00
|
|
|
use crate::coordination::{AgentAssignment, AgentLoad, AgentProfile, SwarmCoordination};
|
|
|
|
|
|
2026-01-11 21:32:56 +00:00
|
|
|
/// Adapter: SwarmCoordination → SwarmCoordinator
|
|
|
|
|
/// Implements the coordination abstraction using the real swarm coordinator.
|
|
|
|
|
pub struct SwarmCoordinationAdapter {
|
|
|
|
|
swarm: Arc<SwarmCoordinator>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SwarmCoordinationAdapter {
|
|
|
|
|
pub fn new(swarm: Arc<SwarmCoordinator>) -> Self {
|
|
|
|
|
Self { swarm }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl SwarmCoordination for SwarmCoordinationAdapter {
|
|
|
|
|
async fn register_profiles(&self, profiles: Vec<AgentProfile>) -> anyhow::Result<()> {
|
|
|
|
|
// Convert internal AgentProfile to swarm's AgentProfile
|
|
|
|
|
for profile in profiles {
|
|
|
|
|
let swarm_profile = vapora_swarm::messages::AgentProfile {
|
|
|
|
|
id: profile.id.clone(),
|
|
|
|
|
roles: vec![profile.role.clone()],
|
|
|
|
|
capabilities: vec![profile.role],
|
|
|
|
|
current_load: 0.0,
|
|
|
|
|
availability: true,
|
|
|
|
|
success_rate: profile.success_rate,
|
|
|
|
|
};
|
|
|
|
|
self.swarm.register_agent(swarm_profile)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn select_agent(
|
|
|
|
|
&self,
|
|
|
|
|
_task_type: &str,
|
|
|
|
|
_required_expertise: Option<&str>,
|
|
|
|
|
) -> anyhow::Result<AgentAssignment> {
|
|
|
|
|
// For now, return a placeholder - real swarm selection would happen here
|
2026-01-11 21:46:08 +00:00
|
|
|
// This is a simplified version - full implementation would query
|
|
|
|
|
// swarm.submit_task_for_bidding()
|
2026-01-11 21:32:56 +00:00
|
|
|
Ok(AgentAssignment {
|
|
|
|
|
agent_id: "default-agent".to_string(),
|
|
|
|
|
agent_name: "Default Agent".to_string(),
|
|
|
|
|
confidence: 0.5,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn report_completion(
|
|
|
|
|
&self,
|
|
|
|
|
_agent_id: &str,
|
|
|
|
|
_success: bool,
|
|
|
|
|
_duration_ms: u64,
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
// Report task completion to swarm for load balancing updates
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn agent_load(&self, _agent_id: &str) -> anyhow::Result<AgentLoad> {
|
|
|
|
|
// Query agent load from swarm
|
|
|
|
|
Ok(AgentLoad {
|
|
|
|
|
agent_id: _agent_id.to_string(),
|
|
|
|
|
current_tasks: 0,
|
|
|
|
|
capacity: 10,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|