ricecoder_domain_agents/
models.rs

1//! Data models for domain-specific agents
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Supported domains for specialized agents
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum Domain {
10    /// Frontend development (React, Vue, Angular, etc.)
11    Frontend,
12    /// Backend development (Node.js, Python, Go, etc.)
13    Backend,
14    /// DevOps and infrastructure
15    DevOps,
16    /// Mobile development (iOS, Android, Flutter)
17    Mobile,
18    /// Data science and ML
19    DataScience,
20    /// Security and compliance
21    Security,
22    /// Database design and optimization
23    Database,
24    /// API design and development
25    Api,
26    /// Testing and QA
27    Testing,
28    /// Documentation
29    Documentation,
30}
31
32impl Domain {
33    /// Get all available domains
34    pub fn all() -> &'static [Domain] {
35        &[
36            Domain::Frontend,
37            Domain::Backend,
38            Domain::DevOps,
39            Domain::Mobile,
40            Domain::DataScience,
41            Domain::Security,
42            Domain::Database,
43            Domain::Api,
44            Domain::Testing,
45            Domain::Documentation,
46        ]
47    }
48
49    /// Get domain name as string
50    pub fn as_str(&self) -> &'static str {
51        match self {
52            Domain::Frontend => "frontend",
53            Domain::Backend => "backend",
54            Domain::DevOps => "devops",
55            Domain::Mobile => "mobile",
56            Domain::DataScience => "data_science",
57            Domain::Security => "security",
58            Domain::Database => "database",
59            Domain::Api => "api",
60            Domain::Testing => "testing",
61            Domain::Documentation => "documentation",
62        }
63    }
64
65    /// Parse domain from string
66    pub fn from_str(s: &str) -> Option<Self> {
67        match s.to_lowercase().as_str() {
68            "frontend" => Some(Domain::Frontend),
69            "backend" => Some(Domain::Backend),
70            "devops" => Some(Domain::DevOps),
71            "mobile" => Some(Domain::Mobile),
72            "data_science" | "datascience" => Some(Domain::DataScience),
73            "security" => Some(Domain::Security),
74            "database" => Some(Domain::Database),
75            "api" => Some(Domain::Api),
76            "testing" => Some(Domain::Testing),
77            "documentation" => Some(Domain::Documentation),
78            _ => None,
79        }
80    }
81}
82
83/// Domain-specific knowledge entry
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct KnowledgeEntry {
86    /// Unique identifier for the knowledge entry
87    pub id: String,
88    /// Category of knowledge (e.g., "best_practices", "patterns", "tools")
89    pub category: String,
90    /// Title or name of the knowledge
91    pub title: String,
92    /// Detailed description
93    pub description: String,
94    /// Related tags for searching
95    pub tags: Vec<String>,
96    /// Example code or usage
97    pub example: Option<String>,
98    /// References or links
99    pub references: Vec<String>,
100}
101
102/// Domain knowledge base
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct KnowledgeBase {
105    /// Domain this knowledge base covers
106    pub domain: String,
107    /// Version of the knowledge base
108    pub version: String,
109    /// Last updated timestamp
110    pub last_updated: String,
111    /// Collection of knowledge entries
112    pub entries: Vec<KnowledgeEntry>,
113    /// Metadata about the knowledge base
114    pub metadata: HashMap<String, String>,
115}
116
117impl KnowledgeBase {
118    /// Create a new knowledge base for a domain
119    pub fn new(domain: &str, version: &str) -> Self {
120        Self {
121            domain: domain.to_string(),
122            version: version.to_string(),
123            last_updated: chrono::Utc::now().to_rfc3339(),
124            entries: Vec::new(),
125            metadata: HashMap::new(),
126        }
127    }
128
129    /// Add a knowledge entry
130    pub fn add_entry(&mut self, entry: KnowledgeEntry) {
131        self.entries.push(entry);
132        self.last_updated = chrono::Utc::now().to_rfc3339();
133    }
134
135    /// Search knowledge entries by tag
136    pub fn search_by_tag(&self, tag: &str) -> Vec<&KnowledgeEntry> {
137        self.entries
138            .iter()
139            .filter(|entry| entry.tags.iter().any(|t| t.contains(tag)))
140            .collect()
141    }
142
143    /// Search knowledge entries by category
144    pub fn search_by_category(&self, category: &str) -> Vec<&KnowledgeEntry> {
145        self.entries
146            .iter()
147            .filter(|entry| entry.category == category)
148            .collect()
149    }
150}
151
152/// Configuration for a domain-specific agent
153#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct DomainAgentConfig {
155    /// Domain this agent specializes in
156    pub domain: String,
157    /// Agent name
158    pub name: String,
159    /// Agent description
160    pub description: String,
161    /// System prompt for the agent
162    pub system_prompt: String,
163    /// Tools available to this agent
164    pub tools: Vec<String>,
165    /// Model to use for this agent
166    pub model: Option<String>,
167    /// Temperature for generation
168    pub temperature: Option<f32>,
169    /// Max tokens for generation
170    pub max_tokens: Option<usize>,
171    /// Custom configuration
172    pub custom_config: HashMap<String, serde_json::Value>,
173}
174
175/// Domain agent metadata
176#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct DomainAgentMetadata {
178    /// Domain identifier
179    pub domain: String,
180    /// Agent name
181    pub name: String,
182    /// Agent version
183    pub version: String,
184    /// Supported capabilities
185    pub capabilities: Vec<String>,
186    /// Required tools
187    pub required_tools: Vec<String>,
188    /// Optional tools
189    pub optional_tools: Vec<String>,
190}
191
192/// Domain agent registry entry
193#[derive(Debug, Clone, Serialize, Deserialize)]
194pub struct DomainAgentRegistry {
195    /// Registered agents by domain
196    pub agents: HashMap<String, DomainAgentMetadata>,
197    /// Knowledge bases by domain
198    pub knowledge_bases: HashMap<String, String>, // domain -> path to knowledge base
199}
200
201impl DomainAgentRegistry {
202    /// Create a new registry
203    pub fn new() -> Self {
204        Self {
205            agents: HashMap::new(),
206            knowledge_bases: HashMap::new(),
207        }
208    }
209
210    /// Register an agent
211    pub fn register_agent(&mut self, domain: &str, metadata: DomainAgentMetadata) {
212        self.agents.insert(domain.to_string(), metadata);
213    }
214
215    /// Register a knowledge base
216    pub fn register_knowledge_base(&mut self, domain: &str, path: String) {
217        self.knowledge_bases.insert(domain.to_string(), path);
218    }
219
220    /// Get agent for domain
221    pub fn get_agent(&self, domain: &str) -> Option<&DomainAgentMetadata> {
222        self.agents.get(domain)
223    }
224
225    /// Get knowledge base path for domain
226    pub fn get_knowledge_base(&self, domain: &str) -> Option<&str> {
227        self.knowledge_bases.get(domain).map(|s| s.as_str())
228    }
229}
230
231impl Default for DomainAgentRegistry {
232    fn default() -> Self {
233        Self::new()
234    }
235}