#![allow(dead_code)]
use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::fmt;
use uuid::Uuid;
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct AgentId(String);
impl AgentId {
pub fn new() -> Self {
Self(Uuid::new_v4().to_string())
}
}
impl fmt::Display for AgentId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.0[..8])
}
}
impl Default for AgentId {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum TaskPriority {
Low = 0,
Normal = 1,
High = 2,
Critical = 3,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TaskType {
ScanRepository,
AnalyzeCode,
ExtractPatterns,
SummarizeWork,
UpdateKnowledge,
QueryKnowledge,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentTask {
pub id: String,
pub task_type: TaskType,
pub priority: TaskPriority,
pub payload: serde_json::Value,
pub metadata: TaskMetadata,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TaskMetadata {
pub source: Option<String>,
pub target: Option<String>,
pub tags: Vec<String>,
}
impl AgentTask {
pub fn new(task_type: TaskType, payload: impl Serialize) -> Result<Self> {
Ok(Self {
id: Uuid::new_v4().to_string(),
task_type,
priority: TaskPriority::Normal,
payload: serde_json::to_value(payload)?,
metadata: TaskMetadata::default(),
})
}
pub fn with_priority(mut self, priority: TaskPriority) -> Self {
self.priority = priority;
self
}
pub fn with_source(mut self, source: impl Into<String>) -> Self {
self.metadata.source = Some(source.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentResult {
pub task_id: String,
pub success: bool,
pub data: serde_json::Value,
pub summary: String,
pub confidence: f32,
}
#[async_trait]
pub trait Agent: Send + Sync {
async fn execute(&self, context: super::AgentContext) -> Result<AgentResult>;
fn name(&self) -> &str;
fn capabilities(&self) -> Vec<String>;
}