Skip to main content

aagt_core/agent/swarm/
protocol.rs

1use crate::agent::swarm::manifest::AgentManifest;
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(tag = "type", content = "data")]
7pub enum SwarmMessage {
8    /// Announce presence to the network
9    Announcement(AgentManifest),
10
11    /// Request help with a task
12    TaskRequest {
13        request_id: String,
14        requester_id: String,
15        task_description: String,
16        required_capabilities: Vec<String>,
17        timeout_ms: u64,
18    },
19
20    /// Bid to perform a task
21    Bid {
22        request_id: String,
23        bidder_id: String,
24        bidder_name: String,
25        estimated_time_ms: u64,
26        confidence: f32,  // 0.0 - 1.0
27        proposal: String, // "I will use Python to..."
28    },
29
30    /// Assign a task to a specific bidder
31    TaskAssignment {
32        request_id: String,
33        assigned_to: String,
34        task_context: String, // Additional context/instructions
35    },
36
37    /// Return the result of a task
38    Result {
39        request_id: String,
40        performer_id: String,
41        output: String,
42        success: bool,
43    },
44}
45
46impl SwarmMessage {
47    pub fn new_request(requester_id: &str, task: &str, caps: Vec<String>) -> Self {
48        SwarmMessage::TaskRequest {
49            request_id: Uuid::new_v4().to_string(),
50            requester_id: requester_id.to_string(),
51            task_description: task.to_string(),
52            required_capabilities: caps,
53            timeout_ms: 30000,
54        }
55    }
56
57    pub fn request_id(&self) -> Option<&str> {
58        match self {
59            SwarmMessage::TaskRequest { request_id, .. } => Some(request_id),
60            SwarmMessage::Bid { request_id, .. } => Some(request_id),
61            SwarmMessage::TaskAssignment { request_id, .. } => Some(request_id),
62            SwarmMessage::Result { request_id, .. } => Some(request_id),
63            SwarmMessage::Announcement(_) => None,
64        }
65    }
66}