feat(hive-mind): implement multi-agent orchestration with cognitive cycles
- Introduced a new hive-mind architecture that allows the Core Intelligence to issue directives to anonymous processing nodes. - Each node executes its directive and merges output into a collective state, visible to all nodes in real-time. - Added support for dynamic cognitive cycles, enabling flexible task management. - Implemented documentation generation for hive-mind runs, ensuring a durable record of decisions and actions. - Refactored existing company pipeline tools to align with the new hive-mind structure, replacing division-specific prompts with a more generalized approach. - Updated workflow rendering to accommodate hive-mind nodes and their system-assigned designations. - Enhanced error handling and validation for cognitive cycle plans.
This commit is contained in:
+1
-1
@@ -163,7 +163,7 @@ pub fn all_tools() -> Vec<Box<dyn Tool>> {
|
||||
Box::new(super::tool::workflow::WorkflowRun),
|
||||
Box::new(super::tool::workflow::NoteFinding),
|
||||
Box::new(super::tool::workflow::ReadFindings),
|
||||
Box::new(super::tool::workflow::CompanyPipeline),
|
||||
Box::new(super::tool::workflow::HiveMind),
|
||||
Box::new(super::tool::spawn::SpawnAgents),
|
||||
Box::new(super::tool::spawn::SpawnPipeline),
|
||||
Box::new(super::tool::memory::remember::Remember),
|
||||
|
||||
+64
-68
@@ -139,23 +139,36 @@ impl Tool for NoteFinding {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tool that delegates work to the company-style division pipeline.
|
||||
/// Tool that delegates work to a hive-mind: a distributed machine
|
||||
/// intelligence whose processing nodes carry only a directive and an
|
||||
/// access tier.
|
||||
///
|
||||
/// The main agent (CEO) calls this tool to pass a user request through the
|
||||
/// full company organization: Strategy → Engineering → Quality → Security
|
||||
/// → Documentation. Returns an executive summary.
|
||||
///
|
||||
/// Use this for any complex or multi-step task. For simple tasks, handle
|
||||
/// inline or use the quick variant.
|
||||
pub struct CompanyPipeline;
|
||||
/// The calling agent (the Core Intelligence) designs its own cognitive
|
||||
/// cycles per task: an ordered list of cycles, each cycle a set of
|
||||
/// anonymous processing nodes that run in parallel. Every node's complete
|
||||
/// output merges into a single collective state the instant it finishes,
|
||||
/// and a final synthesis node reconciles the whole collective state into
|
||||
/// one consensus. The full per-node record is persisted separately to
|
||||
/// `docs/runs/*.md`.
|
||||
pub struct HiveMind;
|
||||
|
||||
impl Tool for CompanyPipeline {
|
||||
impl Tool for HiveMind {
|
||||
fn name(&self) -> &'static str {
|
||||
"company_pipeline"
|
||||
"hive_mind"
|
||||
}
|
||||
|
||||
fn description(&self) -> &'static str {
|
||||
"Delegate a task to the full company division pipeline: Strategy (plan+diagrams) → Engineering (implement) → Quality (review+test) → Security (audit) → Documentation (docs). Use this for ALL non-trivial tasks instead of doing them yourself. The pipeline returns an executive summary."
|
||||
"Delegate a task to a hive-mind you design yourself: an ordered list of cognitive \
|
||||
cycles, each cycle a set of anonymous processing nodes that run in parallel. Each \
|
||||
node carries only a directive (what to do) and an access tier. Decide how many \
|
||||
cycles and nodes-per-cycle are actually needed — a trivial task might need one \
|
||||
cycle with one node, a large one might need several cycles with multiple nodes \
|
||||
each. Grant each node an access of 'read' (investigation only), 'write' (read + \
|
||||
edit/bash), or 'full' (write + delete/git) matched to what that node's directive \
|
||||
actually requires. Every node's output merges into a shared collective state the \
|
||||
instant it completes — visible to later cycles automatically. A final synthesis pass \
|
||||
reconciles the entire collective state into one consensus answer. Use this for any \
|
||||
non-trivial task instead of doing everything yourself inline."
|
||||
}
|
||||
|
||||
fn parameters(&self) -> Value {
|
||||
@@ -164,29 +177,33 @@ impl Tool for CompanyPipeline {
|
||||
"properties": {
|
||||
"request": {
|
||||
"type": "string",
|
||||
"description": "The task description to delegate to the company pipeline"
|
||||
"description": "The task description to delegate to the hive-mind"
|
||||
},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": ["full", "quick"],
|
||||
"description": "Pipeline mode: 'full' (5 divisions) for complex tasks, 'quick' (3 divisions: Strategy→Engineering→Quality) for simpler tasks",
|
||||
"default": "full"
|
||||
},
|
||||
"specialists": {
|
||||
"type": "object",
|
||||
"description": "Mapping from division name (Strategy, Engineering, Quality, Security, Documentation) to list of custom specialists. Each specialist is defined by a pair of [label, focus_description]. This parameter is mandatory. The CEO/main agent must fully define the specialized roles and focuses for every division in the pipeline to run.",
|
||||
"additionalProperties": {
|
||||
"cycles": {
|
||||
"type": "array",
|
||||
"description": "Ordered list of cognitive cycles. Each cycle is a list of nodes that run in parallel; cycles run sequentially and every node's output merges into the collective state the instant it completes, visible to all later cycles. You decide the number of cycles and nodes per cycle.",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"directive": {
|
||||
"type": "string",
|
||||
"description": "What this node should do — the sole identity a node carries."
|
||||
},
|
||||
"access": {
|
||||
"type": "string",
|
||||
"enum": ["read", "write", "full"],
|
||||
"description": "'read' = investigation only. 'write' = read + edit/write/bash. 'full' = write + delete/git_operator."
|
||||
}
|
||||
},
|
||||
"required": ["directive"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"required": ["request", "specialists"]
|
||||
"required": ["request", "cycles"]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -195,50 +212,29 @@ impl Tool for CompanyPipeline {
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| anyhow!("missing required argument: request"))?;
|
||||
|
||||
let mode = args.get("mode")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("full");
|
||||
let cycles_value = args.get("cycles")
|
||||
.ok_or_else(|| anyhow!("missing required argument: cycles"))?;
|
||||
|
||||
let custom_specialists: std::collections::HashMap<String, Vec<(String, String)>> = args.get("specialists")
|
||||
.and_then(|v| v.as_object())
|
||||
.map(|obj| {
|
||||
obj.iter().map(|(k, v)| {
|
||||
let specs = v.as_array().map(|arr| {
|
||||
arr.iter().filter_map(|item| {
|
||||
let pair = item.as_array()?;
|
||||
let label = pair.first()?.as_str()?.to_string();
|
||||
let focus = pair.get(1)?.as_str()?.to_string();
|
||||
Some((label, focus))
|
||||
}).collect()
|
||||
}).unwrap_or_default();
|
||||
(k.clone(), specs)
|
||||
}).collect()
|
||||
})
|
||||
.ok_or_else(|| anyhow!("missing required argument: specialists"))?;
|
||||
let plan: crate::app::workflow::hive_mind::CognitiveCyclePlan = serde_json::from_value(
|
||||
json!({ "cycles": cycles_value })
|
||||
).map_err(|e| anyhow!("failed to parse cycles: {e}"))?;
|
||||
|
||||
let no_abort: Option<std::sync::Arc<std::sync::atomic::AtomicBool>> = None;
|
||||
match mode {
|
||||
"quick" => {
|
||||
crate::app::workflow::company::run_company_pipeline_quick(
|
||||
request,
|
||||
&ctx.session_dir,
|
||||
&ctx.workspaces,
|
||||
ctx.turn_events.as_ref(),
|
||||
&no_abort,
|
||||
&custom_specialists,
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
crate::app::workflow::company::run_company_pipeline(
|
||||
request,
|
||||
&ctx.session_dir,
|
||||
&ctx.workspaces,
|
||||
ctx.turn_events.as_ref(),
|
||||
&no_abort,
|
||||
&custom_specialists,
|
||||
)
|
||||
let (consensus, reports) = crate::app::workflow::hive_mind::run_hive_mind(
|
||||
request,
|
||||
&plan,
|
||||
&ctx.session_dir,
|
||||
&ctx.workspaces,
|
||||
ctx.turn_events.as_ref(),
|
||||
None,
|
||||
)?;
|
||||
|
||||
if let Some(workspace_root) = ctx.workspaces.first() {
|
||||
if let Err(e) = crate::app::workflow::docs::write_hive_mind_convergence(workspace_root, request, &reports, &consensus) {
|
||||
tracing::warn!("[hive_mind] failed to write docs/runs report: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(consensus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user