diff --git a/src/agent/agent_loop.rs b/src/agent/agent_loop.rs index 933fdfe..ab82f87 100644 --- a/src/agent/agent_loop.rs +++ b/src/agent/agent_loop.rs @@ -1004,6 +1004,18 @@ impl AgentLoop { return false; } + // Multiple Task tools can run in parallel + // Task tools create independent subagents with isolated contexts, no shared state + let task_count = tool_calls.iter().filter(|tc| tc.name == "task").count(); + if task_count > 1 && task_count == tool_calls.len() { + return true; + } + + // When Task is mixed with other tools, keep sequential to avoid complexity + if task_count > 0 { + return false; + } + // All tools must be concurrency-safe to run in parallel tool_calls.iter().all(|tc| { self.tools diff --git a/src/config/mod.rs b/src/config/mod.rs index 8f3e78b..8f1d87e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -114,6 +114,8 @@ pub struct TaskConfig { pub enabled: bool, #[serde(default = "default_task_max_execution_secs")] pub max_execution_secs: u64, + #[serde(default = "default_task_explore_max_execution_secs")] + pub explore_max_execution_secs: u64, #[serde(default = "default_task_ttl_hours")] pub ttl_hours: u64, #[serde(default = "default_task_allowed_tools")] @@ -125,7 +127,11 @@ fn default_task_enabled() -> bool { } fn default_task_max_execution_secs() -> u64 { - 300 + 1200 // 20分钟 +} + +fn default_task_explore_max_execution_secs() -> u64 { + 600 // 10分钟 } fn default_task_ttl_hours() -> u64 { @@ -154,6 +160,7 @@ impl Default for TaskConfig { Self { enabled: default_task_enabled(), max_execution_secs: default_task_max_execution_secs(), + explore_max_execution_secs: default_task_explore_max_execution_secs(), ttl_hours: default_task_ttl_hours(), allowed_tools: default_task_allowed_tools(), } diff --git a/src/gateway/runtime.rs b/src/gateway/runtime.rs index 6e7e151..a38188b 100644 --- a/src/gateway/runtime.rs +++ b/src/gateway/runtime.rs @@ -104,6 +104,7 @@ pub(crate) fn build_session_manager_with_sender( let runtime_config = SubAgentRuntimeConfig { allowed_tools: task_config.allowed_tools.iter().cloned().collect(), max_execution_secs: task_config.max_execution_secs, + explore_max_execution_secs: task_config.explore_max_execution_secs, explore_max_tool_calls: 20, ttl_hours: task_config.ttl_hours, }; diff --git a/src/tools/task/runtime.rs b/src/tools/task/runtime.rs index 1cd850b..3cea5fd 100644 --- a/src/tools/task/runtime.rs +++ b/src/tools/task/runtime.rs @@ -20,8 +20,10 @@ use super::types::{SubagentType, TaskDefinition, TaskHandle, TaskSession, TaskSe pub struct SubAgentRuntimeConfig { /// 子代理可用的工具列表(白名单) pub allowed_tools: HashSet, - /// 最大执行时间(秒) + /// 最大执行时间(秒) - General 类型 pub max_execution_secs: u64, + /// Explore 类型的最大执行时间(秒) + pub explore_max_execution_secs: u64, /// 探索类型的最大工具调用次数 pub explore_max_tool_calls: usize, /// 任务 TTL(小时) @@ -45,7 +47,8 @@ impl Default for SubAgentRuntimeConfig { "skill_list".to_string(), "send_session_message".to_string(), // 用于进度通知 ]), - max_execution_secs: 300, // 5分钟 + max_execution_secs: 1200, // 20分钟 + explore_max_execution_secs: 600, // 10分钟 explore_max_tool_calls: 20, ttl_hours: 24, } @@ -168,7 +171,7 @@ impl DefaultSubAgentRuntime { // 设置超时 let max_secs = if session.subagent_type == SubagentType::Explore { - self.config.max_execution_secs / 2 // Explore 类型时间更短 + self.config.explore_max_execution_secs } else { self.config.max_execution_secs };