#![deny(warnings)]
#![deny(missing_docs)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use serde::{Deserialize, Serialize};
pub struct Team {
name: String,
roles: Vec<AgentRole>,
}
impl Team {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
roles: Vec::new(),
}
}
#[must_use]
pub fn add_role(mut self, role: AgentRole) -> Self {
self.roles.push(role);
self
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn roles(&self) -> &[AgentRole] {
&self.roles
}
#[must_use]
pub fn find_role(&self, name: &str) -> Option<&AgentRole> {
self.roles.iter().find(|r| r.name == name)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentRole {
pub name: String,
pub description: String,
pub system_prompt: Option<String>,
}
impl AgentRole {
#[must_use]
pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
Self {
name: name.into(),
description: description.into(),
system_prompt: None,
}
}
#[must_use]
pub fn with_system_prompt(mut self, prompt: impl Into<String>) -> Self {
self.system_prompt = Some(prompt.into());
self
}
}
pub struct VerificationChain {
pub max_retries: usize,
}
impl VerificationChain {
#[must_use]
pub fn new() -> Self {
Self { max_retries: 3 }
}
#[must_use]
pub fn with_max_retries(mut self, n: usize) -> Self {
self.max_retries = n;
self
}
}
impl Default for VerificationChain {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub enum VerifyResult {
Accepted(String),
Rejected(String),
}
impl VerifyResult {
#[must_use]
pub fn is_accepted(&self) -> bool {
matches!(self, Self::Accepted(_))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_team_builder() {
let team = Team::new("test_team")
.add_role(AgentRole::new("role1", "First role"))
.add_role(AgentRole::new("role2", "Second role"));
assert_eq!(team.name(), "test_team");
assert_eq!(team.roles().len(), 2);
}
#[test]
fn test_find_role() {
let team = Team::new("team").add_role(AgentRole::new("researcher", "Research"));
assert!(team.find_role("researcher").is_some());
assert!(team.find_role("unknown").is_none());
}
#[test]
fn test_agent_role_with_prompt() {
let role =
AgentRole::new("writer", "Write docs").with_system_prompt("You are a technical writer");
assert_eq!(
role.system_prompt,
Some("You are a technical writer".into())
);
}
#[test]
fn test_verification_chain_default() {
let chain = VerificationChain::new();
assert_eq!(chain.max_retries, 3);
}
#[test]
fn test_verification_chain_custom_retries() {
let chain = VerificationChain::new().with_max_retries(5);
assert_eq!(chain.max_retries, 5);
}
#[test]
fn test_verify_result() {
assert!(VerifyResult::Accepted("ok".into()).is_accepted());
assert!(!VerifyResult::Rejected("bad".into()).is_accepted());
}
}