🐛 Fix identity always-available fallback chain
- Agent name now falls back to config.name if [identity] section is empty - Agent role defaults to "AI Assistant built by Gyannetra" - User name defaults to "the User" if not set - Removes dependency on identity_setup being completed - Every session gets identity+memory injected into system prompt
This commit is contained in:
@@ -163,25 +163,33 @@ impl AgentLoop {
|
||||
let (agent_name, agent_role, user_name, user_role) = {
|
||||
let memory = self.memory.lock().await;
|
||||
let (l0, _) = memory.identity_get().unwrap_or_default();
|
||||
if !l0.is_empty() && !self.config.identity.agent_name.is_empty() {
|
||||
(
|
||||
self.config.identity.agent_name.clone(),
|
||||
self.config.identity.agent_role.clone(),
|
||||
self.config.identity.user_name.clone(),
|
||||
self.config.identity.user_role.clone(),
|
||||
)
|
||||
} else if !l0.is_empty() {
|
||||
// Parse from L0: "name: X\nrole: Y\nuser: Z (W)\n"
|
||||
let mut parts = l0.lines().filter_map(|l| l.split_once(": ").map(|(_, v)| v.to_string())).collect::<Vec<_>>();
|
||||
(
|
||||
parts.get(0).cloned().unwrap_or_default(),
|
||||
parts.get(1).cloned().unwrap_or_default(),
|
||||
parts.get(2).and_then(|u| u.split_once(" (").map(|(n, _)| n.to_string())).unwrap_or_default(),
|
||||
parts.get(2).and_then(|u| u.split_once(" (").and_then(|(_, r)| r.trim_end_matches(')').to_string().into())).unwrap_or_default(),
|
||||
)
|
||||
|
||||
// Priority: config identity > L0 file > config.agent.name > defaults
|
||||
let a_name = if !self.config.identity.agent_name.is_empty() {
|
||||
self.config.identity.agent_name.clone()
|
||||
} else {
|
||||
(String::new(), String::new(), String::new(), String::new())
|
||||
}
|
||||
self.config.name.clone() // fallback to agent name from config
|
||||
};
|
||||
|
||||
let a_role = if !self.config.identity.agent_role.is_empty() {
|
||||
self.config.identity.agent_role.clone()
|
||||
} else {
|
||||
"AI Assistant built by Gyannetra".to_string()
|
||||
};
|
||||
|
||||
let u_name = if !self.config.identity.user_name.is_empty() {
|
||||
self.config.identity.user_name.clone()
|
||||
} else {
|
||||
"the User".to_string()
|
||||
};
|
||||
|
||||
let u_role = if !self.config.identity.user_role.is_empty() {
|
||||
self.config.identity.user_role.clone()
|
||||
} else {
|
||||
"User".to_string()
|
||||
};
|
||||
|
||||
(a_name, a_role, u_name, u_role)
|
||||
};
|
||||
|
||||
// Build system prompt with identity + dialogue memory
|
||||
|
||||
Reference in New Issue
Block a user