mod builtin;
mod registry;
#[cfg(test)]
mod property_tests;
pub use builtin::*;
pub use registry::AgentRegistry;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Agent {
pub id: String,
pub name: String,
pub title: String,
pub icon: String,
pub persona: AgentPersona,
pub capabilities: Vec<String>,
pub workflows: Vec<String>,
pub delegates_to: Vec<String>,
#[serde(default)]
pub builtin: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentPersona {
pub role: String,
pub identity: String,
pub communication_style: String,
pub principles: Vec<String>,
pub traits: Vec<String>,
}
impl Agent {
pub fn new(
id: impl Into<String>,
name: impl Into<String>,
title: impl Into<String>,
icon: impl Into<String>,
persona: AgentPersona,
) -> Self {
Self {
id: id.into(),
name: name.into(),
title: title.into(),
icon: icon.into(),
persona,
capabilities: Vec::new(),
workflows: Vec::new(),
delegates_to: Vec::new(),
builtin: false,
}
}
pub fn with_capability(mut self, capability: impl Into<String>) -> Self {
self.capabilities.push(capability.into());
self
}
pub fn with_capabilities(mut self, capabilities: Vec<String>) -> Self {
self.capabilities.extend(capabilities);
self
}
pub fn with_workflow(mut self, workflow: impl Into<String>) -> Self {
self.workflows.push(workflow.into());
self
}
pub fn with_workflows(mut self, workflows: Vec<String>) -> Self {
self.workflows.extend(workflows);
self
}
pub fn with_delegate(mut self, delegate: impl Into<String>) -> Self {
self.delegates_to.push(delegate.into());
self
}
pub fn as_builtin(mut self) -> Self {
self.builtin = true;
self
}
pub fn has_capability(&self, capability: &str) -> bool {
self.capabilities.iter().any(|c| c == capability)
}
pub fn can_delegate_to(&self, agent_id: &str) -> bool {
self.delegates_to.iter().any(|d| d == agent_id)
}
}
impl AgentPersona {
pub fn new(
role: impl Into<String>,
identity: impl Into<String>,
communication_style: impl Into<String>,
) -> Self {
Self {
role: role.into(),
identity: identity.into(),
communication_style: communication_style.into(),
principles: Vec::new(),
traits: Vec::new(),
}
}
pub fn with_principle(mut self, principle: impl Into<String>) -> Self {
self.principles.push(principle.into());
self
}
pub fn with_principles(mut self, principles: Vec<String>) -> Self {
self.principles.extend(principles);
self
}
pub fn with_trait(mut self, trait_: impl Into<String>) -> Self {
self.traits.push(trait_.into());
self
}
pub fn with_traits(mut self, traits: Vec<String>) -> Self {
self.traits.extend(traits);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DelegationRequest {
pub from_agent: String,
pub to_agent: String,
pub task: String,
pub context: HashMap<String, String>,
}
impl DelegationRequest {
pub fn new(
from_agent: impl Into<String>,
to_agent: impl Into<String>,
task: impl Into<String>,
) -> Self {
Self {
from_agent: from_agent.into(),
to_agent: to_agent.into(),
task: task.into(),
context: HashMap::new(),
}
}
pub fn with_context(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.context.insert(key.into(), value.into());
self
}
}
#[derive(Debug, Clone)]
pub struct DelegationResult {
pub success: bool,
pub handled_by: String,
pub output: Option<String>,
pub error: Option<String>,
}
impl DelegationResult {
pub fn success(handled_by: impl Into<String>, output: Option<String>) -> Self {
Self {
success: true,
handled_by: handled_by.into(),
output,
error: None,
}
}
pub fn failure(error: impl Into<String>) -> Self {
Self {
success: false,
handled_by: String::new(),
output: None,
error: Some(error.into()),
}
}
}