refactor(subagent): 支持带类型的子智能体标题格式
- 将子智能体标题解析升级为支持 "Subagent [type]: description" 格式 - 兼容旧格式 "Subagent: description",默认类型为 "general" - 修改子智能体会话标题生成,包含类型信息 - 优化记录解析和会话创建逻辑,提高子智能体信息表达准确性
This commit is contained in:
parent
6962ea2eb1
commit
175e7fc01b
@ -144,12 +144,8 @@ fn reconstruct_task_from_db(
|
|||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
// Extract description from title: "Subagent: {description}"
|
// Extract subagent_type and description from title
|
||||||
let description = record
|
let (subagent_type, description) = parse_subagent_title(&record.title);
|
||||||
.title
|
|
||||||
.strip_prefix("Subagent: ")
|
|
||||||
.unwrap_or(&record.title)
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let now = record.updated_at;
|
let now = record.updated_at;
|
||||||
|
|
||||||
@ -161,7 +157,7 @@ fn reconstruct_task_from_db(
|
|||||||
parent_chat_id: record.chat_id.clone(),
|
parent_chat_id: record.chat_id.clone(),
|
||||||
parent_channel_name: record.channel_name.clone(),
|
parent_channel_name: record.channel_name.clone(),
|
||||||
description,
|
description,
|
||||||
subagent_type: "general".to_string(),
|
subagent_type,
|
||||||
state: TaskSessionState::Completed,
|
state: TaskSessionState::Completed,
|
||||||
created_at: record.created_at,
|
created_at: record.created_at,
|
||||||
updated_at: now,
|
updated_at: now,
|
||||||
@ -169,3 +165,18 @@ fn reconstruct_task_from_db(
|
|||||||
error: None,
|
error: None,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse subagent title to extract type and description.
|
||||||
|
/// New format: "Subagent [type]: description"
|
||||||
|
/// Legacy format: "Subagent: description" (defaults to "general")
|
||||||
|
fn parse_subagent_title(title: &str) -> (String, String) {
|
||||||
|
if let Some(rest) = title.strip_prefix("Subagent [") {
|
||||||
|
if let Some(bracket_pos) = rest.find("]: ") {
|
||||||
|
let agent_type = rest[..bracket_pos].to_string();
|
||||||
|
let desc = rest[bracket_pos + 3..].to_string();
|
||||||
|
return (agent_type, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let desc = title.strip_prefix("Subagent: ").unwrap_or(title).to_string();
|
||||||
|
("general".to_string(), desc)
|
||||||
|
}
|
||||||
|
|||||||
@ -509,7 +509,7 @@ impl SubAgentRuntime for DefaultSubAgentRuntime {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 4. 在 sessions 表中创建子智能体会话(确保外键约束满足)
|
// 4. 在 sessions 表中创建子智能体会话(确保外键约束满足)
|
||||||
let session_title = format!("Subagent: {}", task.description);
|
let session_title = format!("Subagent [{}]: {}", session.subagent_type, task.description);
|
||||||
if let Err(e) = self.conversation_repository.ensure_session(
|
if let Err(e) = self.conversation_repository.ensure_session(
|
||||||
&session.session_id,
|
&session.session_id,
|
||||||
&session.parent_channel_name,
|
&session.parent_channel_name,
|
||||||
@ -638,7 +638,7 @@ impl SubAgentRuntime for DefaultSubAgentRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 确保 sessions 表中存在子智能体会话记录
|
// 3. 确保 sessions 表中存在子智能体会话记录
|
||||||
let session_title = format!("Subagent: {}", session.description);
|
let session_title = format!("Subagent [{}]: {}", session.subagent_type, session.description);
|
||||||
if let Err(e) = self.conversation_repository.ensure_session(
|
if let Err(e) = self.conversation_repository.ensure_session(
|
||||||
&session.session_id,
|
&session.session_id,
|
||||||
&session.parent_channel_name,
|
&session.parent_channel_name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user