Implement chrs-council: Governance layer with weighted leader election and task delegation
This commit is contained in:
13
chrs-council-demo/Cargo.toml
Normal file
13
chrs-council-demo/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "chrs-council-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
chrs-agent = { path = "../chrs-agent" }
|
||||
chrs-mail = { path = "../chrs-mail" }
|
||||
chrs-council = { path = "../chrs-council" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde_json = "1.0"
|
||||
uuid = { version = "1.0", features = ["v4"] }
|
||||
chrono = "0.4"
|
||||
71
chrs-council-demo/src/main.rs
Normal file
71
chrs-council-demo/src/main.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use chrs_agent::CHORUSAgent;
|
||||
use chrs_council::Role;
|
||||
use chrs_mail::{Mailbox, Message};
|
||||
use chrono::Utc;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use tokio::time::{sleep, Duration};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== CHORUS Council Collaboration Demo ===");
|
||||
|
||||
// 1. Setup shared environment
|
||||
let base_path = Path::new("/tmp/chrs_council_demo");
|
||||
if base_path.exists() {
|
||||
fs::remove_dir_all(base_path)?;
|
||||
}
|
||||
fs::create_dir_all(base_path)?;
|
||||
|
||||
let mail_db = base_path.join("mail.sqlite");
|
||||
|
||||
// 2. Spawn Agents
|
||||
// They will internally open their own connections to mail_db
|
||||
let mut architect = CHORUSAgent::init("agent-architect", Role::Architect, &base_path.join("architect")).await?;
|
||||
let mut coder = CHORUSAgent::init("agent-coder", Role::Coder, &base_path.join("coder")).await?;
|
||||
let mut auditor = CHORUSAgent::init("agent-auditor", Role::Auditor, &base_path.join("auditor")).await?;
|
||||
|
||||
// Manually set the mailbox path to the shared one for the demo
|
||||
architect.mailbox = Mailbox::open(&mail_db)?;
|
||||
coder.mailbox = Mailbox::open(&mail_db)?;
|
||||
auditor.mailbox = Mailbox::open(&mail_db)?;
|
||||
|
||||
// 3. Start Agents in background
|
||||
let mut arch_handle_inner = architect;
|
||||
let arch_handle = tokio::spawn(async move { arch_handle_inner.run_loop().await });
|
||||
|
||||
let mut coder_handle_inner = coder;
|
||||
let coder_handle = tokio::spawn(async move { coder_handle_inner.run_loop().await });
|
||||
|
||||
let mut aud_handle_inner = auditor;
|
||||
let aud_handle = tokio::spawn(async move { aud_handle_inner.run_loop().await });
|
||||
|
||||
println!("[DEMO] 3 Agents started. Waiting for heartbeats to populate peer lists...");
|
||||
sleep(Duration::from_secs(10)).await;
|
||||
|
||||
// 4. Inject High-Level Task
|
||||
let shared_mailbox = Mailbox::open(&mail_db)?;
|
||||
let task_id = Uuid::new_v4();
|
||||
let task_msg = Message {
|
||||
id: task_id,
|
||||
from_peer: "client".into(),
|
||||
to_peer: "agent-architect".into(),
|
||||
topic: "task".into(),
|
||||
payload: serde_json::json!({
|
||||
"action": "build_feature",
|
||||
"description": "Implement UCXL version history"
|
||||
}),
|
||||
sent_at: Utc::now(),
|
||||
read_at: None,
|
||||
};
|
||||
shared_mailbox.send(&task_msg)?;
|
||||
println!("[DEMO] Task injected: {}", task_id);
|
||||
|
||||
// 5. Observe
|
||||
println!("[DEMO] Observing collaboration for 30 seconds...");
|
||||
sleep(Duration::from_secs(30)).await;
|
||||
|
||||
println!("\n=== DEMO COMPLETE ===");
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user