feat(runtime): GrowthIntegration 串入 EvolutionEngine — L2 触发检查 API

This commit is contained in:
iven
2026-04-18 21:17:48 +08:00
parent 415abf9e66
commit 7d03e6a90c

View File

@@ -12,7 +12,8 @@
use std::sync::Arc; use std::sync::Arc;
use zclaw_growth::{ use zclaw_growth::{
CombinedExtraction, ExperienceExtractor, GrowthTracker, InjectionFormat, AggregatedPattern, CombinedExtraction, EvolutionConfig, EvolutionEngine,
ExperienceExtractor, GrowthTracker, InjectionFormat,
LlmDriverForExtraction, MemoryExtractor, MemoryRetriever, PromptInjector, LlmDriverForExtraction, MemoryExtractor, MemoryRetriever, PromptInjector,
ProfileSignals, RetrievalResult, UserProfileUpdater, VikingAdapter, ProfileSignals, RetrievalResult, UserProfileUpdater, VikingAdapter,
}; };
@@ -38,6 +39,8 @@ pub struct GrowthIntegration {
profile_updater: UserProfileUpdater, profile_updater: UserProfileUpdater,
/// User profile store (optional, for profile updates) /// User profile store (optional, for profile updates)
profile_store: Option<Arc<UserProfileStore>>, profile_store: Option<Arc<UserProfileStore>>,
/// Evolution engine for L2 skill generation (optional)
evolution_engine: Option<EvolutionEngine>,
/// Configuration /// Configuration
config: GrowthConfigInner, config: GrowthConfigInner,
} }
@@ -75,7 +78,8 @@ impl GrowthIntegration {
let retriever = MemoryRetriever::new(viking.clone()); let retriever = MemoryRetriever::new(viking.clone());
let injector = PromptInjector::new(); let injector = PromptInjector::new();
let tracker = GrowthTracker::new(viking); let tracker = GrowthTracker::new(viking.clone());
let evolution_engine = Some(EvolutionEngine::new(viking));
Self { Self {
retriever, retriever,
@@ -85,6 +89,7 @@ impl GrowthIntegration {
experience_extractor: ExperienceExtractor::new(), experience_extractor: ExperienceExtractor::new(),
profile_updater: UserProfileUpdater::new(), profile_updater: UserProfileUpdater::new(),
profile_store: None, profile_store: None,
evolution_engine,
config: GrowthConfigInner::default(), config: GrowthConfigInner::default(),
} }
} }
@@ -122,6 +127,36 @@ impl GrowthIntegration {
self self
} }
/// Set the evolution engine configuration
pub fn with_evolution_config(self, config: EvolutionConfig) -> Self {
let engine = self.evolution_engine.unwrap_or_else(|| {
EvolutionEngine::new(Arc::new(VikingAdapter::in_memory()))
});
Self {
evolution_engine: Some(engine.with_config(config)),
..self
}
}
/// Enable or disable the evolution engine
pub fn set_evolution_enabled(&mut self, enabled: bool) {
if let Some(ref mut engine) = self.evolution_engine {
engine.set_enabled(enabled);
}
}
/// L2 检查:是否有可进化的模式
/// 在 extract_combined 之后调用,返回可固化的经验模式列表
pub async fn check_evolution(
&self,
agent_id: &AgentId,
) -> Result<Vec<AggregatedPattern>> {
match &self.evolution_engine {
Some(engine) => engine.check_evolvable_patterns(&agent_id.to_string()).await,
None => Ok(Vec::new()),
}
}
/// Enhance system prompt with retrieved memories /// Enhance system prompt with retrieved memories
/// ///
/// This method: /// This method: