agent_kernel/evolution.rs
1use crate::{Agent, BoxFuture};
2
3/// Context provided to an evolution operation.
4///
5/// Passed to [`EvolutionRuntime::evolve`] to give the LLM enough information
6/// to produce an improved SOUL.md.
7pub struct EvolutionContext {
8 /// Key insights accumulated from past discussions.
9 pub memories: Vec<String>,
10 /// Human-readable summary of recent feedback (e.g. "3 ratings averaging 4.2 stars").
11 pub feedback_summary: String,
12 /// Current weighted-average quality score (0.0–5.0).
13 pub current_quality_score: f64,
14}
15
16/// Persistent self-evolution primitives (Sixth Principle: persistent self-evolution).
17///
18/// This trait is the Phase 2 addition in the independent agent-kernel repository.
19/// Implement this trait in the product shell (e.g. OhMyZeroClaw) to wire up
20/// feedback tracking, memory storage, SOUL.md optimization, and version rollback.
21///
22/// Only the trait definition lives in the kernel — no implementation provided.
23pub trait EvolutionRuntime: Send + Sync {
24 /// Record user feedback for an agent and return the updated quality_score.
25 fn feedback<'a>(
26 &'a self,
27 agent: &'a str,
28 rating: u8,
29 comment: Option<&'a str>,
30 ) -> BoxFuture<'a, anyhow::Result<f64>>;
31
32 /// Store a discussion insight into the agent's persistent memory.
33 fn remember<'a>(
34 &'a self,
35 agent: &'a str,
36 insight: &'a str,
37 tags: &'a [String],
38 ) -> BoxFuture<'a, anyhow::Result<()>>;
39
40 /// Evolve an agent's SOUL.md given an EvolutionContext. Returns the new SOUL.md.
41 fn evolve<'a>(
42 &'a self,
43 agent: &'a Agent,
44 context: &'a EvolutionContext,
45 ) -> BoxFuture<'a, anyhow::Result<String>>;
46
47 /// Roll back an agent's SOUL.md to a specific version. Returns the rolled-back SOUL.md.
48 fn rollback<'a>(
49 &'a self,
50 agent: &'a str,
51 version: u32,
52 ) -> BoxFuture<'a, anyhow::Result<String>>;
53}