From 7d03e6a90c5c860f21e95faf9ade3799772c5158 Mon Sep 17 00:00:00 2001 From: iven Date: Sat, 18 Apr 2026 21:17:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(runtime):=20GrowthIntegration=20=E4=B8=B2?= =?UTF-8?q?=E5=85=A5=20EvolutionEngine=20=E2=80=94=20L2=20=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E6=A3=80=E6=9F=A5=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/zclaw-runtime/src/growth.rs | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) 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: