Implement specialized agent roles and system prompts inspired by models.yaml

This commit is contained in:
anthonyrawlins
2026-03-04 03:21:12 +11:00
parent 00623ac125
commit 9996b9b84d
5 changed files with 157 additions and 97 deletions

View File

@@ -6,15 +6,25 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use uuid::Uuid;
/// Specialized roles for CHORUS agents.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
/// Specialized roles for CHORUS agents, inspired by models.yaml
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Role {
/// Responsible for high-level planning and task delegation.
Developer,
Reviewer,
Architect,
/// Responsible for code generation and technical implementation.
Coder,
/// Responsible for security verification and final decision audit.
Auditor,
Tester,
DevOps,
Security,
Documentation,
TechnicalWriter,
SystemsAnalyst,
SeniorSoftwareArchitect,
TPM,
SecurityArchitect,
DevExPlatformEngineer,
QATestEngineer,
SREObservabilityLead,
General,
}
/// Represents a peer agent participating in a council.
@@ -40,15 +50,10 @@ pub struct CouncilManager {
}
impl CouncilManager {
/// Initialize a new CouncilManager for the local agent.
pub fn new(local_peer: Peer, mailbox: Mailbox) -> Self {
Self { local_peer, mailbox }
}
/// Deterministically selects a leader from a list of peers.
///
/// **Why**: Ensures that even in a distributed system, all honest nodes
/// agree on the same leader for a given epoch without a central broker.
pub fn elect_leader(&self, peers: &[Peer]) -> Option<String> {
peers.iter()
.max_by(|a, b| {
@@ -59,12 +64,11 @@ impl CouncilManager {
.map(|p| p.id.clone())
}
/// Broadcasts the local agent's presence and score to the council.
pub fn broadcast_heartbeat(&self, topic: &str) -> Result<(), CouncilError> {
let msg = Message {
id: Uuid::new_v4(),
from_peer: self.local_peer.id.clone(),
to_peer: "council".into(), // Broadcast address
to_peer: "council".into(),
topic: topic.into(),
payload: serde_json::to_value(&self.local_peer).unwrap(),
sent_at: Utc::now(),
@@ -74,18 +78,18 @@ impl CouncilManager {
Ok(())
}
/// Splits a high-level task into specialized sub-tasks for the council.
///
/// **Why**: This implements the "Divide and Conquer" strategy of CHORUS,
/// allowing the Architect leader to orchestrate complex work across experts.
pub fn delegate_work(&self, task_id: Uuid, task_description: &str, peers: &[Peer]) -> Vec<Message> {
let mut sub_tasks = Vec::new();
for peer in peers {
let topic = match peer.role {
Role::Coder => "implementation_task",
Role::Auditor => "security_audit_task",
Role::Architect => "planning_task",
Role::Developer => "implementation_task",
Role::Reviewer => "review_task",
Role::Architect | Role::SeniorSoftwareArchitect => "planning_task",
Role::Tester | Role::QATestEngineer => "test_task",
Role::Security | Role::SecurityArchitect => "security_audit_task",
Role::Documentation | Role::TechnicalWriter => "documentation_task",
_ => "general_task",
};
let msg = Message {
@@ -106,26 +110,3 @@ impl CouncilManager {
sub_tasks
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[test]
fn test_election() {
let dir = TempDir::new().unwrap();
let mailbox = Mailbox::open(dir.path().join("mail.sqlite")).unwrap();
let local = Peer { id: "agent-1".into(), role: Role::Architect, resource_score: 0.8 };
let manager = CouncilManager::new(local, mailbox);
let peers = vec![
Peer { id: "agent-1".into(), role: Role::Architect, resource_score: 0.8 },
Peer { id: "agent-2".into(), role: Role::Coder, resource_score: 0.95 },
Peer { id: "agent-3".into(), role: Role::Auditor, resource_score: 0.7 },
];
let leader = manager.elect_leader(&peers).unwrap();
assert_eq!(leader, "agent-2"); // Highest score wins
}
}