fix(hive-mind): ganti gerbang pipeline berbasis jumlah pesan dengan deteksi konvergensi sebelumnya

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
asepharyana
2026-07-14 10:55:05 +07:00
co-authored by Claude Sonnet 5
parent a125f5d440
commit 5498088532
2 changed files with 51 additions and 7 deletions
+15 -7
View File
@@ -992,10 +992,19 @@ fn run_agent_turn(
// ── AUTO CEO PIPELINE ──
// Before the main agent starts working, check if the pipeline should run.
let user_msg_count = msgs.iter()
.filter(|m| matches!(m.role, crate::dto::chat::message::Role::User))
.count();
let should_pipeline = if user_msg_count <= 2 {
// Gated on whether a hive-mind convergence has already happened earlier
// in this session (detected from message content), not an arbitrary
// message-count cutoff — a complex request in message 5 deserves the
// same treatment as one in message 1, as long as this session hasn't
// already converged once.
let already_ran_hive_mind = crate::app::workflow::hive_mind::hive_mind_already_ran(
msgs.iter()
.filter(|m| matches!(m.role, crate::dto::chat::message::Role::System))
.filter_map(|m| m.content.as_deref())
);
let should_pipeline = if already_ran_hive_mind {
false
} else {
let user_request = msgs.iter()
.rev().find(|m| matches!(m.role, crate::dto::chat::message::Role::User))
.and_then(|m| m.content.as_deref())
@@ -1006,8 +1015,6 @@ fn run_agent_turn(
} else {
crate::app::workflow::hive_mind::is_complex_request(user_request)
}
} else {
false
};
if should_pipeline {
@@ -1112,7 +1119,8 @@ fn run_agent_turn(
tracing::info!("[hive-mind] convergence completed successfully");
let pipeline_msg = ChatMessage::system(format!(
"[Hive-Mind Consensus]\n{consensus}",
"{}\n{consensus}",
crate::app::workflow::hive_mind::HIVE_MIND_CONSENSUS_TAG,
));
archive_message(tc.db.as_ref(), &tc.session_id, &pipeline_msg);
msgs.push(pipeline_msg);