feat: 工具执行超时可配置 + 修复硬编码盖过工具自定义超时的 bug

1. 新增 agent.toolExecutionTimeoutMs 配置(默认 120s,范围 10~600s),AgentSettings 加输入框

2. 修复 engine.ts 硬编码 120s 会盖过 delegate-task(5min)/web-search(5min) 等工具自定义 timeoutMs 的 bug:改为取 max(配置值, tool.timeoutMs)

3. main.ts 启动时从 ConfigService 加载;handlers.ts 监听 config:set 即时更新
This commit is contained in:
thzxx
2026-07-12 14:51:12 +08:00
parent 6d31498e6a
commit 3858f5ede3
5 changed files with 27 additions and 4 deletions
+5 -1
View File
@@ -49,6 +49,7 @@ const DEFAULT_CONFIG: AgentLoopConfig = {
maxTokens: 63488,
thinkingEnabled: true,
thinkingEffort: 'high',
toolExecutionTimeoutMs: 120_000,
};
/**
@@ -574,7 +575,10 @@ export class AgentLoopEngine extends EventEmitter {
}
// 执行工具(带超时)
const toolTimeout = 120_000; // 单个工具最大 2 分钟
// 兜底超时取 max(配置值, 工具自定义 timeoutMs),确保工具能跑满自己声明的超时
const configuredTimeout = this.config.toolExecutionTimeoutMs ?? 120_000;
const toolDef = this.toolRegistry.get(toolCall.name)?.definition;
const toolTimeout = Math.max(configuredTimeout, toolDef?.timeoutMs ?? 0);
let toolResult: MetonaToolResult;
try {
toolResult = await Promise.race([
+2
View File
@@ -73,6 +73,8 @@ export interface AgentLoopConfig {
thinkingEffort: 'low' | 'medium' | 'high' | 'max';
/** Ollama 上下文窗口大小(num_ctx),其他 Provider 忽略 */
contextLength?: number;
/** 工具执行兜底超时(ms,默认 120000),实际取 max(此值, tool.timeoutMs) */
toolExecutionTimeoutMs?: number;
}
// ===== Agent Loop 输出 =====