feat: Evolution Engine Phase 3-5 — WorkflowComposer+FeedbackCollector+EvolutionMiddleware+反馈闭环
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

Phase 3:
- EvolutionMiddleware (priority 78): 管家对话中注入进化确认提示
- GrowthIntegration.check_evolution() API 串入

Phase 4:
- WorkflowComposer: 轨迹工具链模式聚类 + Pipeline YAML prompt 构建 + JSON 解析
- EvolutionEngine.analyze_trajectory_patterns() L3 入口

Phase 5:
- FeedbackCollector: 反馈信号收集 + 信任度管理 + 推荐(Optimize/Archive/Promote)
- EvolutionEngine 反馈闭环方法: submit_feedback/get_artifacts_needing_optimization

新增 12 个测试(111→123),全 workspace 701 测试通过。
This commit is contained in:
iven
2026-04-18 21:27:59 +08:00
parent 7d03e6a90c
commit f97e6fdbb6
6 changed files with 727 additions and 4 deletions

View File

@@ -2,14 +2,20 @@
//! 协调 L1/L2/L3 三层进化的触发和执行
//! L1 (记忆进化) 在 GrowthIntegration 中处理
//! L2 (技能进化) 通过 PatternAggregator + SkillGenerator + QualityGate 协调
//! L3 (工作流进化) 预留接口Phase 4 实现
//! L3 (工作流进化) 通过 WorkflowComposer 协调
//! 反馈闭环通过 FeedbackCollector 管理
use std::sync::Arc;
use crate::experience_store::ExperienceStore;
use crate::feedback_collector::{
EvolutionArtifact, FeedbackCollector, FeedbackEntry, FeedbackSignal, RecommendedAction,
Sentiment, TrustUpdate,
};
use crate::pattern_aggregator::{AggregatedPattern, PatternAggregator};
use crate::quality_gate::{QualityGate, QualityReport};
use crate::skill_generator::{SkillCandidate, SkillGenerator};
use crate::workflow_composer::{ToolChainPattern, WorkflowComposer};
use crate::VikingAdapter;
use zclaw_types::Result;
@@ -37,6 +43,7 @@ impl Default for EvolutionConfig {
/// 进化引擎中枢
pub struct EvolutionEngine {
viking: Arc<VikingAdapter>,
feedback: FeedbackCollector,
config: EvolutionConfig,
}
@@ -44,17 +51,16 @@ impl EvolutionEngine {
pub fn new(viking: Arc<VikingAdapter>) -> Self {
Self {
viking,
feedback: FeedbackCollector::new(),
config: EvolutionConfig::default(),
}
}
/// Backward-compatible constructor
pub fn from_experience_store(_experience_store: Arc<ExperienceStore>) -> Self {
// Extract viking from ExperienceStore — we need the underlying adapter
// Since ExperienceStore holds Arc<VikingAdapter>, we create a new in-memory one
// For proper usage, use new() with the correct viking adapter
Self {
viking: Arc::new(VikingAdapter::in_memory()),
feedback: FeedbackCollector::new(),
config: EvolutionConfig::default(),
}
}
@@ -106,6 +112,72 @@ impl EvolutionEngine {
pub fn config(&self) -> &EvolutionConfig {
&self.config
}
// -----------------------------------------------------------------------
// L3: 工作流进化
// -----------------------------------------------------------------------
/// L3: 从轨迹数据中提取重复的工具链模式
pub fn analyze_trajectory_patterns(
&self,
trajectories: &[(String, Vec<String>)], // (session_id, tools_used)
) -> Vec<(ToolChainPattern, Vec<String>)> {
if !self.config.enabled {
return Vec::new();
}
WorkflowComposer::extract_patterns(trajectories)
}
/// L3: 为给定工具链模式构建工作流生成 prompt
pub fn build_workflow_prompt(
&self,
pattern: &ToolChainPattern,
frequency: usize,
industry: Option<&str>,
) -> String {
WorkflowComposer::build_prompt(pattern, frequency, industry)
}
// -----------------------------------------------------------------------
// 反馈闭环
// -----------------------------------------------------------------------
/// 提交反馈并获取信任度更新
pub fn submit_feedback(&mut self, entry: FeedbackEntry) -> TrustUpdate {
self.feedback.submit_feedback(entry)
}
/// 获取需要优化的进化产物
pub fn get_artifacts_needing_optimization(&self) -> Vec<String> {
self.feedback
.get_artifacts_needing_optimization()
.iter()
.map(|r| r.artifact_id.clone())
.collect()
}
/// 获取建议归档的进化产物
pub fn get_artifacts_to_archive(&self) -> Vec<String> {
self.feedback
.get_artifacts_to_archive()
.iter()
.map(|r| r.artifact_id.clone())
.collect()
}
/// 获取推荐产物
pub fn get_recommended_artifacts(&self) -> Vec<String> {
self.feedback
.get_recommended_artifacts()
.iter()
.map(|r| r.artifact_id.clone())
.collect()
}
/// 获取反馈收集器的引用(用于高级查询)
pub fn feedback(&self) -> &FeedbackCollector {
&self.feedback
}
}
#[cfg(test)]