fix(identity): agent_update 同步写入 soul.md — 跨会话名字记忆
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
config.name 更新后新会话的 system prompt 看不到名字,因为 pre_conversation_hook 只读 soul.md。现在 agent_update 在 name 变更时同步更新 soul.md(含/替换"你的名字是X"),确保下次 会话的 system prompt 包含身份信息。
This commit is contained in:
@@ -7,7 +7,7 @@ use zclaw_types::{AgentConfig, AgentId, AgentInfo};
|
|||||||
|
|
||||||
use super::{validate_agent_id, KernelState};
|
use super::{validate_agent_id, KernelState};
|
||||||
use crate::intelligence::validation::validate_string_length;
|
use crate::intelligence::validation::validate_string_length;
|
||||||
use crate::intelligence::identity::IdentityManagerState;
|
use crate::intelligence::identity::{IdentityFile, IdentityManagerState};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Request / Response types
|
// Request / Response types
|
||||||
@@ -235,6 +235,7 @@ pub async fn agent_delete(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn agent_update(
|
pub async fn agent_update(
|
||||||
state: State<'_, KernelState>,
|
state: State<'_, KernelState>,
|
||||||
|
identity_state: State<'_, IdentityManagerState>,
|
||||||
agent_id: String,
|
agent_id: String,
|
||||||
updates: AgentUpdateRequest,
|
updates: AgentUpdateRequest,
|
||||||
) -> Result<AgentInfo, String> {
|
) -> Result<AgentInfo, String> {
|
||||||
@@ -253,6 +254,20 @@ pub async fn agent_update(
|
|||||||
|
|
||||||
// Apply updates
|
// Apply updates
|
||||||
if let Some(name) = updates.name {
|
if let Some(name) = updates.name {
|
||||||
|
// Sync name to identity soul so next session's system prompt includes it
|
||||||
|
let mut identity_mgr = identity_state.lock().await;
|
||||||
|
let current_soul = identity_mgr.get_file(&agent_id, IdentityFile::Soul);
|
||||||
|
let updated_soul = if current_soul.is_empty() {
|
||||||
|
format!("# ZCLAW 人格\n\n你的名字是{}。\n\n你是一个成长性的中文 AI 助手。", name)
|
||||||
|
} else if current_soul.contains("你的名字是") {
|
||||||
|
let re = regex::Regex::new(r"你的名字是[^\n]+").unwrap();
|
||||||
|
re.replace(¤t_soul, format!("你的名字是{}", name)).to_string()
|
||||||
|
} else {
|
||||||
|
format!("你的名字是{}。\n\n{}", name, current_soul)
|
||||||
|
};
|
||||||
|
let _ = identity_mgr.update_file(&agent_id, "soul", &updated_soul);
|
||||||
|
drop(identity_mgr);
|
||||||
|
|
||||||
config.name = name;
|
config.name = name;
|
||||||
}
|
}
|
||||||
if let Some(description) = updates.description {
|
if let Some(description) = updates.description {
|
||||||
|
|||||||
Reference in New Issue
Block a user