diff --git a/crates/zclaw-runtime/src/growth.rs b/crates/zclaw-runtime/src/growth.rs index cfc7d74..624a06d 100644 --- a/crates/zclaw-runtime/src/growth.rs +++ b/crates/zclaw-runtime/src/growth.rs @@ -12,7 +12,8 @@ use std::sync::Arc; use zclaw_growth::{ - CombinedExtraction, ExperienceExtractor, GrowthTracker, InjectionFormat, + AggregatedPattern, CombinedExtraction, EvolutionConfig, EvolutionEngine, + ExperienceExtractor, GrowthTracker, InjectionFormat, LlmDriverForExtraction, MemoryExtractor, MemoryRetriever, PromptInjector, ProfileSignals, RetrievalResult, UserProfileUpdater, VikingAdapter, }; @@ -38,6 +39,8 @@ pub struct GrowthIntegration { profile_updater: UserProfileUpdater, /// User profile store (optional, for profile updates) profile_store: Option>, + /// Evolution engine for L2 skill generation (optional) + evolution_engine: Option, /// Configuration config: GrowthConfigInner, } @@ -75,7 +78,8 @@ impl GrowthIntegration { let retriever = MemoryRetriever::new(viking.clone()); let injector = PromptInjector::new(); - let tracker = GrowthTracker::new(viking); + let tracker = GrowthTracker::new(viking.clone()); + let evolution_engine = Some(EvolutionEngine::new(viking)); Self { retriever, @@ -85,6 +89,7 @@ impl GrowthIntegration { experience_extractor: ExperienceExtractor::new(), profile_updater: UserProfileUpdater::new(), profile_store: None, + evolution_engine, config: GrowthConfigInner::default(), } } @@ -122,6 +127,36 @@ impl GrowthIntegration { 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> { + 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 /// /// This method: