77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
//! Hive-mind cycle execution — run one cycle of parallel nodes.
|
|||
|
|
//!
|
||
|
|
//! Flow: load settings → resolve LLM credentials → for each directive,
|
||
|
|
//! build a SubagentContext and call run_agent → collect NodeOutputs.
|
||
|
|
|
||
|
|
use anyhow::Result;
|
||
|
|
use tracing::info;
|
||
|
|
|
||
|
|
use zesdex_domain::cms::{AppConfigRepository, SettingsRepository};
|
||
|
|
use zesdex_domain::core::Store;
|
||
|
|
|
||
|
|
use crate::persistence::{JsonAppConfigRepository, JsonSettingsRepository};
|
||
|
|
use crate::subagent::context::SubagentContext;
|
||
|
|
use crate::subagent::division::AccessTier;
|
||
|
|
use crate::subagent::engine::run_agent;
|
||
|
|
use crate::tools::ToolCtx;
|
||
|
|
use crate::workflow::hive_mind::types::{CognitiveCycle, NodeOutput};
|
||
|
|
|
||
|
|
/// Execute one cycle: run each node directive and collect outputs.
|
||
|
|
///
|
||
|
|
/// Flow:
|
||
|
|
/// 1. Load `Settings` and `AppConfig` from the store directory.
|
||
|
|
/// 2. Resolve provider, model, base_url, and api_key.
|
||
|
|
/// 3. For each directive → build `SubagentContext` → `run_agent` (Full access).
|
||
|
|
/// 4. Collect `NodeOutput` results.
|
||
|
|
pub async fn execute_cycle(
|
||
|
|
cycle: &CognitiveCycle,
|
||
|
|
tool_ctx: &ToolCtx,
|
||
|
|
) -> Result<Vec<NodeOutput>> {
|
||
|
|
info!(
|
||
|
|
"Executing cycle {} with {} directives",
|
||
|
|
cycle.index,
|
||
|
|
cycle.directives.len()
|
||
|
|
);
|
||
|
|
|
||
|
|
let store = Store::new();
|
||
|
|
let settings = JsonSettingsRepository::new()
|
||
|
|
.load(&store.base_dir)
|
||
|
|
.unwrap_or_default();
|
||
|
|
let app_config = JsonAppConfigRepository::new()
|
||
|
|
.load(&store.base_dir)
|
||
|
|
.unwrap_or_default();
|
||
|
|
|
||
|
|
let (provider, model) =
|
||
|
|
crate::subagent::provider::resolve_subagent_provider(&settings, &app_config);
|
||
|
|
|
||
|
|
let base_url = app_config
|
||
|
|
.providers
|
||
|
|
.get(&provider)
|
||
|
|
.map(|p| p.api_base.clone())
|
||
|
|
.unwrap_or_else(|| "https://opencode.ai/zen/v1".to_string());
|
||
|
|
|
||
|
|
let api_key = crate::llm::provider::resolve_api_key(&settings, &app_config);
|
||
|
|
|
||
|
|
let mut outputs = Vec::new();
|
||
|
|
for (i, directive) in cycle.directives.iter().enumerate() {
|
||
|
|
let ctx = SubagentContext::new(
|
||
|
|
directive.clone(),
|
||
|
|
tool_ctx.clone(),
|
||
|
|
"full".to_string(),
|
||
|
|
base_url.clone(),
|
||
|
|
api_key.clone(),
|
||
|
|
model.clone(),
|
||
|
|
);
|
||
|
|
|
||
|
|
let result = run_agent(ctx, directive, AccessTier::Full, tool_ctx.clone()).await?;
|
||
|
|
|
||
|
|
outputs.push(NodeOutput {
|
||
|
|
id: format!("Node-{}-{}", cycle.index, i),
|
||
|
|
directive: directive.clone(),
|
||
|
|
output: result,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(outputs)
|
||
|
|
}
|