PoC: Verified end-to-end Agent Inception and isolated task execution
This commit is contained in:
@@ -10,6 +10,8 @@ chrs-graph = { path = "../chrs-graph" }
|
||||
chrs-slurp = { path = "../chrs-slurp" }
|
||||
chrs-shhh = { path = "../chrs-shhh" }
|
||||
chrs-bubble = { path = "../chrs-bubble" }
|
||||
chrs-agent = { path = "../chrs-agent" }
|
||||
chrs-council = { path = "../chrs-council" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
@@ -1,128 +1,72 @@
|
||||
/// chrs-poc crate provides an end‑to‑end proof‑of‑concept demonstration of the CHORUS
|
||||
/// system. It wires together the core components:
|
||||
///
|
||||
/// * `Mailbox` – message‑passing layer (`chrs_mail`).
|
||||
/// * `DoltGraph` – persistent state graph (`chrs_graph`).
|
||||
/// * `ProvenanceGraph` – provenance tracking (`chrs_bubble`).
|
||||
/// * `SecretSentinel` – secret scrubbing (`chrs_shhh`).
|
||||
/// * `CurationEngine` – decision record curation (`chrs_slurp`).
|
||||
///
|
||||
/// The flow mirrors a realistic task lifecycle: a client dispatches a task
|
||||
/// message, an agent processes it, generates reasoning (with a deliberately
|
||||
/// injected secret), the secret is scrubbed, a decision record is curated, and
|
||||
/// provenance links are recorded. The final state is persisted in a Dolt
|
||||
/// repository.
|
||||
|
||||
use chrs_bubble::{ProvenanceGraph, ProvenanceEdge};
|
||||
use chrs_graph::DoltGraph;
|
||||
use chrs_mail::{Mailbox, Message};
|
||||
use chrs_shhh::SecretSentinel;
|
||||
use chrs_slurp::{CurationEngine, DecisionRecord};
|
||||
use chrs_council::Role;
|
||||
use chrono::Utc;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Entry point for the proof‑of‑concept binary.
|
||||
///
|
||||
/// The function performs the following high‑level steps, each documented inline:
|
||||
/// 1. Sets up a temporary workspace.
|
||||
/// 2. Initialises all required components.
|
||||
/// 3. Simulates a client sending an audit task to an agent.
|
||||
/// 4. Processes the task as the agent would, including secret scrubbing.
|
||||
/// 5. Curates a `DecisionRecord` via the SLURP engine.
|
||||
/// 6. Records provenance relationships in the BUBBLE graph.
|
||||
/// 7. Prints a success banner and the path to the persisted Dolt state.
|
||||
///
|
||||
/// Errors from any component propagate via `?` and are reported as a boxed error.
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== CHORUS End-to-End Proof of Concept ===");
|
||||
println!("=== CHORUS End-to-End: Full Agent Inception Test ===");
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// 1. Setup paths
|
||||
// ---------------------------------------------------------------------
|
||||
let base_path = Path::new("/tmp/chrs_poc");
|
||||
let base_path = Path::new("/tmp/chrs_full_test");
|
||||
if base_path.exists() {
|
||||
fs::remove_dir_all(base_path)?;
|
||||
}
|
||||
fs::create_dir_all(base_path)?;
|
||||
|
||||
let mail_path = base_path.join("mail.sqlite");
|
||||
let graph_path = base_path.join("state_graph");
|
||||
fs::create_dir_all(&graph_path)?;
|
||||
let shared_mailbox = Mailbox::open(&mail_path)?;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// 2. Initialise Components
|
||||
// ---------------------------------------------------------------------
|
||||
let mailbox = Mailbox::open(&mail_path)?;
|
||||
let persistence = DoltGraph::init(&graph_path)?;
|
||||
let mut provenance = ProvenanceGraph::new(persistence);
|
||||
// 2. Initialize Agents
|
||||
let mut architect = chrs_agent::CHORUSAgent::init(
|
||||
"agent-architect",
|
||||
Role::SeniorSoftwareArchitect,
|
||||
&base_path.join("architect")
|
||||
).await?;
|
||||
architect.mailbox = shared_mailbox.clone();
|
||||
|
||||
// A separate graph handle is needed for the SLURP engine because the
|
||||
// provenance graph consumes the original `DoltGraph`. In production we would
|
||||
// share via `Arc<Mutex<>>`.
|
||||
let slurp_persistence = DoltGraph::init(&graph_path)?;
|
||||
let curator = CurationEngine::new(slurp_persistence);
|
||||
let sentinel = SecretSentinel::new_default();
|
||||
let mut developer = chrs_agent::CHORUSAgent::init(
|
||||
"agent-developer",
|
||||
Role::Developer,
|
||||
&base_path.join("developer")
|
||||
).await?;
|
||||
developer.mailbox = shared_mailbox.clone();
|
||||
|
||||
println!("[POC] Components initialized.");
|
||||
// 3. Setup Council
|
||||
architect.peers.insert("agent-developer".into(), chrs_council::Peer {
|
||||
id: "agent-developer".into(),
|
||||
role: Role::Developer,
|
||||
resource_score: 0.9,
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// 3. Dispatch Task (simulate client sending message to Agent-A)
|
||||
// ---------------------------------------------------------------------
|
||||
let task_id = Uuid::new_v4();
|
||||
// 4. Inject Task
|
||||
let task_msg = Message {
|
||||
id: task_id,
|
||||
id: Uuid::new_v4(),
|
||||
from_peer: "client".into(),
|
||||
to_peer: "agent-a".into(),
|
||||
topic: "audit_system".into(),
|
||||
payload: serde_json::json!({"action": "audit", "target": "UCXL"}),
|
||||
to_peer: "agent-architect".into(),
|
||||
topic: "task".into(),
|
||||
payload: serde_json::json!({
|
||||
"description": "Load Project Constitution",
|
||||
"instruction": "Clone the repository from http://tony:silverfrond[1392]@192.168.1.27:3000/tony/DistOS and extract MISSION from PROJECT-CONSTITUTION.md"
|
||||
}),
|
||||
sent_at: Utc::now(),
|
||||
read_at: None,
|
||||
};
|
||||
mailbox.send(&task_msg)?;
|
||||
println!("[POC] Task dispatched to Agent-A: {}", task_id);
|
||||
shared_mailbox.send(&task_msg)?;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// 4. Process Task (Agent-A logic)
|
||||
// ---------------------------------------------------------------------
|
||||
let pending = mailbox.receive_pending("agent-a")?;
|
||||
// 5. Architect Delegation
|
||||
println!("[POC] Architect delegating...");
|
||||
architect.handle_message(task_msg).await;
|
||||
|
||||
// 6. Developer Execution (Inception)
|
||||
let pending = shared_mailbox.receive_pending("agent-developer")?;
|
||||
for msg in pending {
|
||||
println!("[POC] Agent-A received task: {}", msg.topic);
|
||||
|
||||
// Simulated reasoning that accidentally contains a secret.
|
||||
let raw_reasoning = "Audit complete. Verified UCXL address parsing. My secret key is sk-1234567890abcdef1234567890abcdef1234567890abcdef";
|
||||
|
||||
// 5. SHHH: Scrub secrets from the reasoning output.
|
||||
let clean_reasoning = sentinel.scrub_text(raw_reasoning);
|
||||
println!("[POC] SHHH scrubbed reasoning: {}", clean_reasoning);
|
||||
|
||||
// 6. SLURP: Create and curate a DecisionRecord.
|
||||
let dr = DecisionRecord {
|
||||
id: Uuid::new_v4(),
|
||||
author: "agent-a".into(),
|
||||
reasoning: clean_reasoning,
|
||||
citations: vec!["ucxl://system:watcher@local:filesystem/#/UCXL/src/lib.rs".into()],
|
||||
timestamp: Utc::now(),
|
||||
};
|
||||
curator.curate_decision(dr.clone())?;
|
||||
|
||||
// 7. BUBBLE: Record provenance relationships.
|
||||
provenance.record_node(task_id, "ucxl://client:user@poc:task/#/audit_request")?;
|
||||
provenance.record_node(dr.id, "ucxl://agent-a:worker@poc:task/#/audit_result")?;
|
||||
provenance.record_link(dr.id, task_id, ProvenanceEdge::DerivedFrom)?;
|
||||
|
||||
println!("[POC] Provenance recorded: DR {} -> Task {}", dr.id, task_id);
|
||||
|
||||
mailbox.mark_read(msg.id)?;
|
||||
println!("[POC] Developer received sub-task. Starting Inception...");
|
||||
developer.handle_message(msg).await;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// 8. Final output
|
||||
// ---------------------------------------------------------------------
|
||||
println!("\n=== POC SUCCESSFUL ===");
|
||||
println!("Final State is persisted in Dolt at: {:?}", graph_path);
|
||||
|
||||
println!("\n=== FULL POC COMPLETE ===");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user