1use async_trait::async_trait;
7use serde::{Deserialize, Serialize};
8use std::fmt;
9use uuid::Uuid;
10
11use crate::Result;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
15pub struct AgentId(Uuid);
16
17impl AgentId {
18 pub fn new() -> Self {
20 Self(Uuid::new_v4())
21 }
22}
23
24impl Default for AgentId {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl fmt::Display for AgentId {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "{}", self.0)
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38pub enum AgentCapability {
39 Parsing,
41 TypeInference,
43 ApiExtraction,
45 SpecificationGeneration,
47 CodeGeneration,
49 Compilation,
51 Testing,
53 Packaging,
55}
56
57#[async_trait]
64pub trait Agent: Send + Sync {
65 type Input: Send + Sync;
67
68 type Output: Send + Sync;
70
71 async fn execute(&self, input: Self::Input) -> Result<Self::Output>;
76
77 fn id(&self) -> AgentId;
79
80 fn name(&self) -> &str;
82
83 fn capabilities(&self) -> Vec<AgentCapability>;
85
86 fn validate_input(&self, _input: &Self::Input) -> Result<()> {
90 Ok(())
91 }
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct AgentMetadata {
97 pub id: AgentId,
98 pub name: String,
99 pub capabilities: Vec<AgentCapability>,
100 pub version: String,
101}
102
103impl AgentMetadata {
104 pub fn new(id: AgentId, name: impl Into<String>, capabilities: Vec<AgentCapability>) -> Self {
106 Self {
107 id,
108 name: name.into(),
109 capabilities,
110 version: env!("CARGO_PKG_VERSION").to_string(),
111 }
112 }
113}
114
115#[cfg(test)]
116mod tests {
117 use super::*;
118
119 #[test]
120 fn test_agent_id_creation() {
121 let id1 = AgentId::new();
122 let id2 = AgentId::new();
123 assert_ne!(id1, id2);
124 }
125
126 #[test]
127 fn test_agent_id_display() {
128 let id = AgentId::new();
129 let display = format!("{}", id);
130 assert!(!display.is_empty());
131 }
132
133 #[test]
134 fn test_agent_metadata_creation() {
135 let id = AgentId::new();
136 let metadata = AgentMetadata::new(
137 id,
138 "TestAgent",
139 vec![AgentCapability::Parsing],
140 );
141
142 assert_eq!(metadata.id, id);
143 assert_eq!(metadata.name, "TestAgent");
144 assert_eq!(metadata.capabilities.len(), 1);
145 }
146}