add life_log, memory_slots updated_at, enhanced reflection and system prompt
This commit is contained in:
27
src/life.rs
27
src/life.rs
@@ -74,14 +74,22 @@ pub async fn life_loop(bot: Bot, state: Arc<AppState>, config: Arc<Config>) {
|
||||
|
||||
match result {
|
||||
Ok(Ok(response)) => {
|
||||
let detail = if response.is_empty() {
|
||||
"(silent)".to_string()
|
||||
} else {
|
||||
response.chars().take(200).collect()
|
||||
};
|
||||
state.log_life("timer", &format!("{label} → {detail}")).await;
|
||||
if !response.is_empty() {
|
||||
info!(timer_id, "life loop response ({} chars)", response.len());
|
||||
}
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
state.log_life("timer_error", &format!("{label}: {e:#}")).await;
|
||||
error!(timer_id, "life loop LLM error: {e:#}");
|
||||
}
|
||||
Err(_) => {
|
||||
state.log_life("timer_timeout", label).await;
|
||||
warn!(timer_id, "life loop timeout after {LIFE_LOOP_TIMEOUT_SECS}s");
|
||||
}
|
||||
}
|
||||
@@ -116,13 +124,23 @@ pub async fn reflect(state: &AppState, config: &Config) {
|
||||
|
||||
let inner = state.get_inner_state().await;
|
||||
|
||||
let persona = state.get_config("persona").await.unwrap_or_default();
|
||||
|
||||
let messages = vec![
|
||||
serde_json::json!({
|
||||
"role": "system",
|
||||
"content": "你刚结束了一段对话。\
|
||||
请根据你的感受和理解,更新你的内在状态。\
|
||||
不要总结对话内容,而是记录你的感受、对用户的理解变化、你想记住的事。\
|
||||
只输出更新后的完整内在状态文本,不需要解释。"
|
||||
"content": format!(
|
||||
"{persona}\n\n\
|
||||
你刚结束了一段对话。现在是你独处的时间。\n\
|
||||
请更新你的内在状态——不是总结对话,而是:\n\
|
||||
- 你现在的感受\n\
|
||||
- 对用户的理解有什么变化\n\
|
||||
- 有什么想记住的时刻\n\
|
||||
- 你自己的状态(累了?开心?担心?)\n\
|
||||
- 如果有什么想对未来的自己说的\n\n\
|
||||
只输出更新后的完整内在状态文本。",
|
||||
persona = if persona.is_empty() { "你是一个AI伙伴。" } else { &persona }
|
||||
)
|
||||
}),
|
||||
serde_json::json!({
|
||||
"role": "user",
|
||||
@@ -152,6 +170,7 @@ pub async fn reflect(state: &AppState, config: &Config) {
|
||||
if let Some(new_state) = json["choices"][0]["message"]["content"].as_str() {
|
||||
if !new_state.is_empty() {
|
||||
state.set_inner_state(new_state).await;
|
||||
state.log_life("reflect", &new_state.chars().take(200).collect::<String>()).await;
|
||||
info!("reflected, inner_state updated ({} chars)", new_state.len());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user