fix(tools): 修正 scope_key 计算逻辑及任务运行时 topic_id 设置
- 调整 scope_key_from_context 根据 nesting_depth 区分主代理和子代理的 key 策略 - 主代理优先使用 topic_id,子代理使用 session_id 避免污染父代理 todo - 任务运行时将 parent_topic_id 传入 topic_id,修正为正确的引用 - 完善函数注释,增强代码可读性和维护性
This commit is contained in:
parent
879f5f243a
commit
761f8577be
@ -342,7 +342,7 @@ impl DefaultSubAgentRuntime {
|
||||
sender_id: None,
|
||||
chat_id: Some(session.parent_chat_id.clone()),
|
||||
session_id: Some(session.session_id.clone()),
|
||||
topic_id: None,
|
||||
topic_id: session.parent_topic_id.clone(),
|
||||
message_id: None,
|
||||
message_seq: None,
|
||||
subagent_description: Some(session.description.clone()),
|
||||
|
||||
@ -328,12 +328,18 @@ impl Tool for TodoWriteTool {
|
||||
|
||||
// ── 辅助函数 ──────────────────────────────────────────────
|
||||
|
||||
/// 计算 scope_key:优先 topic_id,否则 session_id
|
||||
/// 计算 scope_key:
|
||||
/// - 主代理 (nesting_depth == 0):优先 topic_id,否则 session_id
|
||||
/// - 子/孙代理 (nesting_depth > 0):使用 session_id 隔离,避免污染父代理 todo
|
||||
pub(crate) fn scope_key_from_context(context: &ToolContext) -> Option<String> {
|
||||
if context.nesting_depth > 0 {
|
||||
context.session_id.clone().filter(|s| !s.is_empty())
|
||||
} else {
|
||||
let tid = context.topic_id.as_deref().filter(|t| !t.is_empty());
|
||||
let sid = context.session_id.as_deref().filter(|s| !s.is_empty());
|
||||
tid.or(sid).map(str::to_string)
|
||||
}
|
||||
}
|
||||
|
||||
/// 校验状态转换合法性
|
||||
fn validate_transition(old: &TodoStatus, new: &TodoStatus) -> Result<(), String> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user