@cicctencent/agent-core 1.0.34 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/rest-runner.d.ts.map +1 -1
- package/dist/cjs/a2a/rest-runner.js +24 -5
- package/dist/cjs/a2a/rest-runner.js.map +1 -1
- package/dist/cjs/a2a/runner.d.ts.map +1 -1
- package/dist/cjs/a2a/runner.js +33 -8
- package/dist/cjs/a2a/runner.js.map +1 -1
- package/dist/cjs/agent/compaction.d.ts.map +1 -1
- package/dist/cjs/agent/compaction.js +1 -4
- package/dist/cjs/agent/compaction.js.map +1 -1
- package/dist/cjs/agent/constants.d.ts +14 -0
- package/dist/cjs/agent/constants.d.ts.map +1 -0
- package/dist/cjs/agent/constants.js +30 -0
- package/dist/cjs/agent/constants.js.map +1 -0
- package/dist/cjs/agent/engine.d.ts +38 -2
- package/dist/cjs/agent/engine.d.ts.map +1 -1
- package/dist/cjs/agent/engine.js +53 -378
- package/dist/cjs/agent/engine.js.map +1 -1
- package/dist/cjs/agent/guard-controller.d.ts +64 -0
- package/dist/cjs/agent/guard-controller.d.ts.map +1 -0
- package/dist/cjs/agent/guard-controller.js +265 -0
- package/dist/cjs/agent/guard-controller.js.map +1 -0
- package/dist/cjs/agent/llm-caller.d.ts.map +1 -1
- package/dist/cjs/agent/llm-caller.js +6 -3
- package/dist/cjs/agent/llm-caller.js.map +1 -1
- package/dist/cjs/agent/rate-limit-manager.d.ts +8 -0
- package/dist/cjs/agent/rate-limit-manager.d.ts.map +1 -1
- package/dist/cjs/agent/rate-limit-manager.js +36 -0
- package/dist/cjs/agent/rate-limit-manager.js.map +1 -1
- package/dist/cjs/agent/runtime-builder.d.ts +44 -0
- package/dist/cjs/agent/runtime-builder.d.ts.map +1 -1
- package/dist/cjs/agent/runtime-builder.js +78 -20
- package/dist/cjs/agent/runtime-builder.js.map +1 -1
- package/dist/cjs/agent/session-state-manager.d.ts +47 -0
- package/dist/cjs/agent/session-state-manager.d.ts.map +1 -0
- package/dist/cjs/agent/session-state-manager.js +85 -0
- package/dist/cjs/agent/session-state-manager.js.map +1 -0
- package/dist/cjs/agent/tool-executor.d.ts +2 -3
- package/dist/cjs/agent/tool-executor.d.ts.map +1 -1
- package/dist/cjs/agent/tool-executor.js +9 -16
- package/dist/cjs/agent/tool-executor.js.map +1 -1
- package/dist/cjs/agent/tool-section-builder.d.ts +55 -0
- package/dist/cjs/agent/tool-section-builder.d.ts.map +1 -0
- package/dist/cjs/agent/tool-section-builder.js +191 -0
- package/dist/cjs/agent/tool-section-builder.js.map +1 -0
- package/dist/cjs/agent/types.d.ts +1 -1
- package/dist/cjs/agent/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +8 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mcp/base-client.js +2 -2
- package/dist/cjs/mcp/base-client.js.map +1 -1
- package/dist/cjs/mcp/client.js +4 -4
- package/dist/cjs/mcp/client.js.map +1 -1
- package/dist/cjs/mcp/factory.d.ts +6 -1
- package/dist/cjs/mcp/factory.d.ts.map +1 -1
- package/dist/cjs/mcp/factory.js +7 -2
- package/dist/cjs/mcp/factory.js.map +1 -1
- package/dist/cjs/mcp/http-client.js +5 -5
- package/dist/cjs/mcp/http-client.js.map +1 -1
- package/dist/cjs/observability/logger.d.ts.map +1 -1
- package/dist/cjs/observability/logger.js +56 -2
- package/dist/cjs/observability/logger.js.map +1 -1
- package/dist/cjs/tool/ask-user.js +3 -3
- package/dist/cjs/tool/delegate.d.ts.map +1 -1
- package/dist/cjs/tool/delegate.js +4 -2
- package/dist/cjs/tool/delegate.js.map +1 -1
- package/dist/cjs/utils/dsml-parser.d.ts +1 -1
- package/dist/cjs/utils/dsml-parser.js +1 -1
- package/dist/esm/a2a/rest-runner.d.ts.map +1 -1
- package/dist/esm/a2a/rest-runner.js +24 -5
- package/dist/esm/a2a/rest-runner.js.map +1 -1
- package/dist/esm/a2a/runner.d.ts.map +1 -1
- package/dist/esm/a2a/runner.js +33 -8
- package/dist/esm/a2a/runner.js.map +1 -1
- package/dist/esm/agent/compaction.d.ts.map +1 -1
- package/dist/esm/agent/compaction.js +1 -4
- package/dist/esm/agent/compaction.js.map +1 -1
- package/dist/esm/agent/constants.d.ts +14 -0
- package/dist/esm/agent/constants.d.ts.map +1 -0
- package/dist/esm/agent/constants.js +27 -0
- package/dist/esm/agent/constants.js.map +1 -0
- package/dist/esm/agent/engine.d.ts +38 -2
- package/dist/esm/agent/engine.d.ts.map +1 -1
- package/dist/esm/agent/engine.js +54 -379
- package/dist/esm/agent/engine.js.map +1 -1
- package/dist/esm/agent/guard-controller.d.ts +64 -0
- package/dist/esm/agent/guard-controller.d.ts.map +1 -0
- package/dist/esm/agent/guard-controller.js +256 -0
- package/dist/esm/agent/guard-controller.js.map +1 -0
- package/dist/esm/agent/llm-caller.d.ts.map +1 -1
- package/dist/esm/agent/llm-caller.js +6 -3
- package/dist/esm/agent/llm-caller.js.map +1 -1
- package/dist/esm/agent/rate-limit-manager.d.ts +8 -0
- package/dist/esm/agent/rate-limit-manager.d.ts.map +1 -1
- package/dist/esm/agent/rate-limit-manager.js +36 -0
- package/dist/esm/agent/rate-limit-manager.js.map +1 -1
- package/dist/esm/agent/runtime-builder.d.ts +44 -0
- package/dist/esm/agent/runtime-builder.d.ts.map +1 -1
- package/dist/esm/agent/runtime-builder.js +75 -20
- package/dist/esm/agent/runtime-builder.js.map +1 -1
- package/dist/esm/agent/session-state-manager.d.ts +47 -0
- package/dist/esm/agent/session-state-manager.d.ts.map +1 -0
- package/dist/esm/agent/session-state-manager.js +78 -0
- package/dist/esm/agent/session-state-manager.js.map +1 -0
- package/dist/esm/agent/tool-executor.d.ts +2 -3
- package/dist/esm/agent/tool-executor.d.ts.map +1 -1
- package/dist/esm/agent/tool-executor.js +9 -16
- package/dist/esm/agent/tool-executor.js.map +1 -1
- package/dist/esm/agent/tool-section-builder.d.ts +55 -0
- package/dist/esm/agent/tool-section-builder.d.ts.map +1 -0
- package/dist/esm/agent/tool-section-builder.js +182 -0
- package/dist/esm/agent/tool-section-builder.js.map +1 -0
- package/dist/esm/agent/types.d.ts +1 -1
- package/dist/esm/agent/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mcp/base-client.js +2 -2
- package/dist/esm/mcp/base-client.js.map +1 -1
- package/dist/esm/mcp/client.js +4 -4
- package/dist/esm/mcp/client.js.map +1 -1
- package/dist/esm/mcp/factory.d.ts +6 -1
- package/dist/esm/mcp/factory.d.ts.map +1 -1
- package/dist/esm/mcp/factory.js +7 -2
- package/dist/esm/mcp/factory.js.map +1 -1
- package/dist/esm/mcp/http-client.js +5 -5
- package/dist/esm/mcp/http-client.js.map +1 -1
- package/dist/esm/observability/logger.d.ts.map +1 -1
- package/dist/esm/observability/logger.js +56 -2
- package/dist/esm/observability/logger.js.map +1 -1
- package/dist/esm/tool/ask-user.js +3 -3
- package/dist/esm/tool/delegate.d.ts.map +1 -1
- package/dist/esm/tool/delegate.js +4 -2
- package/dist/esm/tool/delegate.js.map +1 -1
- package/dist/esm/utils/dsml-parser.d.ts +1 -1
- package/dist/esm/utils/dsml-parser.js +1 -1
- package/package.json +1 -1
package/dist/cjs/agent/engine.js
CHANGED
|
@@ -13,30 +13,11 @@ const tool_executor_ts_1 = require("./tool-executor.js");
|
|
|
13
13
|
const logger_ts_1 = require("../observability/logger.js");
|
|
14
14
|
const rate_limit_manager_ts_1 = require("./rate-limit-manager.js");
|
|
15
15
|
const compaction_ts_1 = require("./compaction.js");
|
|
16
|
+
const tool_section_builder_ts_1 = require("./tool-section-builder.js");
|
|
17
|
+
const guard_controller_ts_1 = require("./guard-controller.js");
|
|
18
|
+
const session_state_manager_ts_1 = require("./session-state-manager.js");
|
|
16
19
|
/** 默认系统提示词 */
|
|
17
20
|
const DEFAULT_BASE_PROMPT = `You are a helpful AI assistant with access to tools. Use tools when needed to accomplish tasks. Always explain your actions clearly.`;
|
|
18
|
-
/**
|
|
19
|
-
* 核心工具集(summary-all 模式下保持全量 schema 的工具)。
|
|
20
|
-
*
|
|
21
|
-
* 这些工具是 Agent 执行绝大多数任务的基础(文件读写、代码搜索、命令执行、
|
|
22
|
-
* 工具发现、委托派发),必须让 LLM 看到完整参数 schema 以保证调用可靠性。
|
|
23
|
-
* 非核心工具(通讯、日历、自动化、文档生成等)仅以摘要形式呈现,
|
|
24
|
-
* LLM 需通过 read_tool_doc 获取完整 schema 后再调用。
|
|
25
|
-
*/
|
|
26
|
-
const CORE_TOOL_NAMES = new Set([
|
|
27
|
-
'read_file',
|
|
28
|
-
'write_file',
|
|
29
|
-
'edit_file',
|
|
30
|
-
'append_file',
|
|
31
|
-
'search_code',
|
|
32
|
-
'execute_command',
|
|
33
|
-
'run_script',
|
|
34
|
-
'read_terminal',
|
|
35
|
-
'read_tool_doc',
|
|
36
|
-
'read_tool_result',
|
|
37
|
-
'read_offload',
|
|
38
|
-
'delegate_task',
|
|
39
|
-
]);
|
|
40
21
|
/** 进度叙述规则(追加到 system prompt,引导 LLM 在工具调用间输出可见文本)— 可通过 AgentConfig.progressNarrationRules 覆盖 */
|
|
41
22
|
const DEFAULT_PROGRESS_NARRATION_RULES = `
|
|
42
23
|
|
|
@@ -106,6 +87,8 @@ class AgentEngine {
|
|
|
106
87
|
childSessionMap = new Map();
|
|
107
88
|
/** childSessionId → parentSessionId(反向索引,用于快速查找父会话) */
|
|
108
89
|
parentSessionMap = new Map();
|
|
90
|
+
/** 被摘要化的工具名集合(progressive loading:这些工具的 prompt 不注入 system prompt) */
|
|
91
|
+
summarizedToolNames = new Set();
|
|
109
92
|
/** 子模块:历史管理器 */
|
|
110
93
|
historyManager;
|
|
111
94
|
/** 子模块:LLM 调用器 */
|
|
@@ -126,6 +109,33 @@ class AgentEngine {
|
|
|
126
109
|
guardConfig;
|
|
127
110
|
/** 错误恢复策略配置 */
|
|
128
111
|
errorRecovery;
|
|
112
|
+
/** 为 ToolSectionBuilder 提供依赖 */
|
|
113
|
+
get toolSectionDeps() {
|
|
114
|
+
return { config: this.config, summarizedToolNames: this.summarizedToolNames };
|
|
115
|
+
}
|
|
116
|
+
/** 为 GuardController 提供依赖 */
|
|
117
|
+
get guardControllerDeps() {
|
|
118
|
+
return {
|
|
119
|
+
historyManager: this.historyManager,
|
|
120
|
+
dataFetchTools: this.dataFetchTools,
|
|
121
|
+
outputTools: this.outputTools,
|
|
122
|
+
guardConfig: this.guardConfig,
|
|
123
|
+
maxIterations: this.config.maxIterations,
|
|
124
|
+
hasTool: (name) => this.hasTool(name),
|
|
125
|
+
runHooks: (event, ctx) => this.runHooks(event, ctx),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** 为 SessionStateManager 提供依赖 */
|
|
129
|
+
get sessionStateDeps() {
|
|
130
|
+
return {
|
|
131
|
+
abortMap: this.abortMap,
|
|
132
|
+
steeringMap: this.steeringMap,
|
|
133
|
+
statusMap: this.statusMap,
|
|
134
|
+
childSessionMap: this.childSessionMap,
|
|
135
|
+
parentSessionMap: this.parentSessionMap,
|
|
136
|
+
historyManager: this.historyManager,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
129
139
|
constructor(config) {
|
|
130
140
|
this.config = {
|
|
131
141
|
...config,
|
|
@@ -176,8 +186,7 @@ class AgentEngine {
|
|
|
176
186
|
// 模型在收尾阶段无法再用它读取 data/ 下的结果文件。
|
|
177
187
|
// 若某 agent 仍需将其纳入数据获取循环检测,可在 AgentConfig.dataFetchTools 中显式加回。
|
|
178
188
|
this.outputTools = new Set(config.outputTools ?? [
|
|
179
|
-
'delegate_task', '
|
|
180
|
-
'create_pdf', 'create_report', 'show_widget', 'save_artifact',
|
|
189
|
+
'delegate_task', 'create_document', 'show_widget', 'save_artifact',
|
|
181
190
|
]);
|
|
182
191
|
// 外部数据源获取工具(用于数据出处水印判定,仅含真正访问外部/实时数据源的工具,
|
|
183
192
|
// 不含 read_file 等本地读取——本地读取不构成「实时数据核验」但也不代表数据源失败)
|
|
@@ -694,67 +703,19 @@ ${textHistory.join('\n')}`;
|
|
|
694
703
|
// ---- 工具定义 ----
|
|
695
704
|
/** 获取工具定义列表(含预过滤 + 渐进式发现) */
|
|
696
705
|
resolveToolDefs(options) {
|
|
697
|
-
|
|
698
|
-
let defs = toolNames.length > 0
|
|
699
|
-
? this.config.toolRegistry.getDefinitions({ names: toolNames })
|
|
700
|
-
: this.config.toolRegistry.getDefinitions();
|
|
701
|
-
if (this.config.deniedTools?.length) {
|
|
702
|
-
const denied = new Set(this.config.deniedTools);
|
|
703
|
-
defs = defs.filter(d => !denied.has(d.function.name));
|
|
704
|
-
}
|
|
705
|
-
const discovery = this.config.toolDiscovery;
|
|
706
|
-
// summary 模式:仅 MCP 工具摘要
|
|
707
|
-
if (discovery === 'summary') {
|
|
708
|
-
defs = defs.map(d => this.summarizeToolDef(d, 'mcp'));
|
|
709
|
-
}
|
|
710
|
-
// summary-all 模式:所有非核心工具摘要(MCP + 非核心内置工具)
|
|
711
|
-
if (discovery === 'summary-all') {
|
|
712
|
-
const coreOverride = this.config.coreToolNames
|
|
713
|
-
? new Set(this.config.coreToolNames)
|
|
714
|
-
: CORE_TOOL_NAMES;
|
|
715
|
-
defs = defs.map(d => {
|
|
716
|
-
const isCore = coreOverride.has(d.function.name);
|
|
717
|
-
return this.summarizeToolDef(d, isCore ? null : 'all');
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
return defs;
|
|
706
|
+
return (0, tool_section_builder_ts_1.resolveToolDefs)(this.toolSectionDeps, options);
|
|
721
707
|
}
|
|
722
708
|
/**
|
|
723
709
|
* 将工具定义转为摘要形式(截断 description + 清空 parameters)。
|
|
724
|
-
* 实现抽离至 ./compaction.ts,保持单一来源。
|
|
710
|
+
* 实现抽离至 ./tool-section-builder.ts -> compaction.ts,保持单一来源。
|
|
725
711
|
*/
|
|
726
712
|
summarizeToolDef(def, scope) {
|
|
727
|
-
return (0,
|
|
728
|
-
scope,
|
|
729
|
-
maxDesc: this.config.toolSummaryMaxDesc ?? 100,
|
|
730
|
-
getCategory: (name) => this.config.toolRegistry.get(name)?.category,
|
|
731
|
-
});
|
|
713
|
+
return (0, tool_section_builder_ts_1.summarizeToolDefImpl)(this.toolSectionDeps, def, scope);
|
|
732
714
|
}
|
|
733
715
|
// ---- 准备阶段(续) ----
|
|
734
716
|
/** 构建 ToolContext */
|
|
735
717
|
buildToolContext(options, internalAbort) {
|
|
736
|
-
|
|
737
|
-
return {
|
|
738
|
-
sessionId: options.sessionId,
|
|
739
|
-
shell: custom?.shell || this.createNoopShell(),
|
|
740
|
-
fs: custom?.fs,
|
|
741
|
-
env: options.context?.env,
|
|
742
|
-
abortSignal: internalAbort.signal,
|
|
743
|
-
custom: {
|
|
744
|
-
...custom,
|
|
745
|
-
// Fix A:始终使用引擎授权注册表(已按 selectedTools/disabledTools 过滤),
|
|
746
|
-
// 不接受 custom.toolRegistry 覆盖——防止 read_tool_doc/diagnose 泄漏被禁工具 schema。
|
|
747
|
-
toolRegistry: this.config.toolRegistry,
|
|
748
|
-
skillManager: custom?.skillManager ?? this.config.skillManager,
|
|
749
|
-
},
|
|
750
|
-
emitSubEvent: custom?.emitSubEvent,
|
|
751
|
-
emitWidget: custom?.emitWidget,
|
|
752
|
-
emitArtifact: custom?.emitArtifact,
|
|
753
|
-
emitToolLog: custom?.emitToolLog,
|
|
754
|
-
emitToolHeartbeat: custom?.emitToolHeartbeat,
|
|
755
|
-
toolTimeout: this.config.toolTimeout,
|
|
756
|
-
maxScriptTimeoutMs: this.config.maxScriptTimeoutMs,
|
|
757
|
-
};
|
|
718
|
+
return (0, tool_section_builder_ts_1.buildToolContext)(this.toolSectionDeps, options, internalAbort);
|
|
758
719
|
}
|
|
759
720
|
/** 汇总准备阶段,生成 LoopState */
|
|
760
721
|
async prepareRun(options, internalAbort) {
|
|
@@ -793,28 +754,7 @@ ${textHistory.join('\n')}`;
|
|
|
793
754
|
/** 动态构建工具区 prompt(Available Tools + Tool Usage Guidelines)。
|
|
794
755
|
* 从 state.toolDefs 现场拼装,确保与可执行工具集一致,消除静态穿透。 */
|
|
795
756
|
buildDynamicToolSection(toolDefs) {
|
|
796
|
-
|
|
797
|
-
return this.config.buildToolSection(toolDefs, this.config.toolRegistry);
|
|
798
|
-
}
|
|
799
|
-
if (toolDefs.length === 0)
|
|
800
|
-
return '';
|
|
801
|
-
// 可用工具名集合:用于占位符 {{TOOL:name}} 渲染时判定引用是否真实可用
|
|
802
|
-
const available = new Set(toolDefs.map(d => d.function.name));
|
|
803
|
-
const lines = toolDefs.map(d => `- \`${d.function.name}\`: ${this.renderToolRefs(d.function.description || '', available)}`);
|
|
804
|
-
let section = `\n\n## Available Tools\n${lines.join('\n')}`;
|
|
805
|
-
// 收集工具自带的使用引导(tool.prompt),并对其中对其他工具的引用做可用裁剪。
|
|
806
|
-
// tool.relatedTools 是声明式的「本工具引用的其它工具」清单,
|
|
807
|
-
// 用于:若某占位符 {{TOOL:x}} 未注册,则整段引用被剔除(见 renderToolRefs)。
|
|
808
|
-
const prompts = [];
|
|
809
|
-
for (const def of toolDefs) {
|
|
810
|
-
const tool = this.config.toolRegistry.get(def.function.name);
|
|
811
|
-
if (tool?.prompt)
|
|
812
|
-
prompts.push(this.renderToolRefs(tool.prompt, available, tool.relatedTools));
|
|
813
|
-
}
|
|
814
|
-
if (prompts.length > 0) {
|
|
815
|
-
section += `\n\n## Tool Usage Guidelines\n\n${prompts.join('\n\n')}`;
|
|
816
|
-
}
|
|
817
|
-
return section;
|
|
757
|
+
return (0, tool_section_builder_ts_1.buildDynamicToolSection)(this.toolSectionDeps, toolDefs);
|
|
818
758
|
}
|
|
819
759
|
/**
|
|
820
760
|
* 渲染工具提示中对其它工具的引用,避免「提示穿透」:
|
|
@@ -829,45 +769,11 @@ ${textHistory.join('\n')}`;
|
|
|
829
769
|
* 显式声明在 relatedTools 中的工具名也可被识别为「已知引用」参与裁剪。
|
|
830
770
|
*/
|
|
831
771
|
renderToolRefs(text, available, relatedTools) {
|
|
832
|
-
|
|
833
|
-
// - name 确实注册(available)时才渲染为 `name`;
|
|
834
|
-
// - 否则用哨兵标记,后续做子句级清除,避免留下 "do NOT call after" 这类残缺。
|
|
835
|
-
// 不在 relatedTools 且未注册的占位符视为误写,保留原文。
|
|
836
|
-
const knownRefs = relatedTools && relatedTools.length > 0 ? new Set(relatedTools) : null;
|
|
837
|
-
const SENTINEL = '\x00'; // 哨兵:标记被剔除的占位符位置
|
|
838
|
-
// 1) 替换:可用 -> name;不可用且为已知引用 -> 哨兵;其余保留原文
|
|
839
|
-
let out = text.replace(/\{\{TOOL:([a-zA-Z0-9_-]+)\}\}/g, (m, name) => {
|
|
840
|
-
if (available.has(name))
|
|
841
|
-
return `\`${name}\``;
|
|
842
|
-
if (knownRefs && !knownRefs.has(name))
|
|
843
|
-
return m;
|
|
844
|
-
return SENTINEL;
|
|
845
|
-
});
|
|
846
|
-
// 2) 子句级清除:以 " - " 或 ", " 分隔的子句中含哨兵,则移除整个子句
|
|
847
|
-
out = out
|
|
848
|
-
.split(/(?<=\S)\s+-\s+|(?<=\S),\s+/)
|
|
849
|
-
.filter(clause => !clause.includes(SENTINEL))
|
|
850
|
-
.join(', ');
|
|
851
|
-
// 3) 行级清除:多行 prompt 中,整行仅剩哨兵/标点/空白的予以移除
|
|
852
|
-
out = out
|
|
853
|
-
.split('\n')
|
|
854
|
-
.filter(line => {
|
|
855
|
-
const trimmed = line.trim();
|
|
856
|
-
if (trimmed === '')
|
|
857
|
-
return true;
|
|
858
|
-
const meaningful = trimmed.replace(/[`.,;:()\-]+/g, '').replace(/\s+/g, '');
|
|
859
|
-
return meaningful.length > 0 && !trimmed.includes(SENTINEL);
|
|
860
|
-
})
|
|
861
|
-
.join('\n');
|
|
862
|
-
// 4) 清理残留哨兵 + 收缩多余空格
|
|
863
|
-
out = out.replace(/\x00/g, '').replace(/ {2,}/g, ' ').replace(/\s+\n/g, '\n').trim();
|
|
864
|
-
return out;
|
|
772
|
+
return (0, tool_section_builder_ts_1.renderToolRefs)(text, available, relatedTools);
|
|
865
773
|
}
|
|
866
774
|
/** 刷新 system prompt 中的工具区,确保与 state.toolDefs 一致 */
|
|
867
775
|
refreshToolSection(state) {
|
|
868
|
-
|
|
869
|
-
state.messages[0].content = state.stableSystemPrompt + this.buildDynamicToolSection(state.toolDefs);
|
|
870
|
-
}
|
|
776
|
+
(0, tool_section_builder_ts_1.refreshToolSection)(this.toolSectionDeps, state);
|
|
871
777
|
}
|
|
872
778
|
// ---- Agent Loop ----
|
|
873
779
|
/** 主循环:迭代调用 LLM → 执行工具 → 直到完成或达到上限 */
|
|
@@ -1278,27 +1184,11 @@ ${textHistory.join('\n')}`;
|
|
|
1278
1184
|
* 消息将在下次 LLM 调用前注入对话上下文
|
|
1279
1185
|
*/
|
|
1280
1186
|
steer(sessionId, message) {
|
|
1281
|
-
|
|
1282
|
-
return false;
|
|
1283
|
-
if (!this.steeringMap.has(sessionId)) {
|
|
1284
|
-
this.steeringMap.set(sessionId, []);
|
|
1285
|
-
}
|
|
1286
|
-
this.steeringMap.get(sessionId).push(message);
|
|
1287
|
-
return true;
|
|
1187
|
+
return (0, session_state_manager_ts_1.steer)(this.sessionStateDeps, sessionId, message);
|
|
1288
1188
|
}
|
|
1289
1189
|
/** 消费当前会话的 steering 消息,注入到 messages 中 */
|
|
1290
1190
|
drainSteering(state) {
|
|
1291
|
-
|
|
1292
|
-
if (!msgs || msgs.length === 0)
|
|
1293
|
-
return null;
|
|
1294
|
-
const drained = [...msgs];
|
|
1295
|
-
msgs.length = 0;
|
|
1296
|
-
for (const msg of drained) {
|
|
1297
|
-
const userMsg = { role: 'user', content: msg };
|
|
1298
|
-
state.messages.push(userMsg);
|
|
1299
|
-
this.historyManager.addHistory(state.sessionId, userMsg);
|
|
1300
|
-
}
|
|
1301
|
-
return { messages: drained, count: drained.length };
|
|
1191
|
+
return (0, session_state_manager_ts_1.drainSteering)(this.sessionStateDeps, state);
|
|
1302
1192
|
}
|
|
1303
1193
|
/**
|
|
1304
1194
|
* 进度叙述提醒
|
|
@@ -1306,23 +1196,7 @@ ${textHistory.join('\n')}`;
|
|
|
1306
1196
|
* 确保用户在对话中有可见的文字输出,而不是所有内容都收在执行步骤中。
|
|
1307
1197
|
*/
|
|
1308
1198
|
injectProgressNudge(state) {
|
|
1309
|
-
|
|
1310
|
-
role: 'user',
|
|
1311
|
-
content: [
|
|
1312
|
-
'[SYSTEM: PROGRESS NARRATION]',
|
|
1313
|
-
'',
|
|
1314
|
-
'You have been calling tools without providing visible text to the user.',
|
|
1315
|
-
'Please provide a brief progress update in the user\'s language:',
|
|
1316
|
-
'- What have you accomplished so far?',
|
|
1317
|
-
'- What are you working on next?',
|
|
1318
|
-
'- If you found important data, summarize the key findings.',
|
|
1319
|
-
'',
|
|
1320
|
-
'Keep it to 1-3 sentences. This text is displayed directly to the user.',
|
|
1321
|
-
].join('\n'),
|
|
1322
|
-
};
|
|
1323
|
-
state.messages.push(msg);
|
|
1324
|
-
this.historyManager.addHistory(state.sessionId, msg);
|
|
1325
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.progress_nudge', sessionId: state.sessionId, data: { iteration: state.iteration } });
|
|
1199
|
+
(0, guard_controller_ts_1.injectProgressNudge)(this.guardControllerDeps, state);
|
|
1326
1200
|
}
|
|
1327
1201
|
/**
|
|
1328
1202
|
* 迭代预算提醒
|
|
@@ -1330,49 +1204,7 @@ ${textHistory.join('\n')}`;
|
|
|
1330
1204
|
* 解决 agent 在数据查询循环中耗尽迭代、永远无法进入文档生成/委托阶段的问题。
|
|
1331
1205
|
*/
|
|
1332
1206
|
injectIterationGuard(state) {
|
|
1333
|
-
|
|
1334
|
-
return;
|
|
1335
|
-
const max = this.config.maxIterations;
|
|
1336
|
-
const cur = state.iteration;
|
|
1337
|
-
const remaining = max - cur;
|
|
1338
|
-
const ratio = cur / max;
|
|
1339
|
-
if (ratio >= this.guardConfig.iterationGuardThreshold && remaining > 0) {
|
|
1340
|
-
state.iterationGuardInjected = true;
|
|
1341
|
-
const toolCallCount = state.toolCallRecords.length;
|
|
1342
|
-
const targets = this.guardConfig.delegateTargets;
|
|
1343
|
-
const reportAgent = targets.report ? `"${targets.report}"` : 'the appropriate report agent';
|
|
1344
|
-
const docAgent = targets.document ? `"${targets.document}"` : 'the appropriate document agent';
|
|
1345
|
-
const pptAgent = targets.presentation ? `"${targets.presentation}"` : docAgent;
|
|
1346
|
-
// P1 #6: 使用可配置的提示文本,默认为通用英文提示(不绑定业务 Agent 名称)
|
|
1347
|
-
// 仅引用当前 registry 实际注册的工具,避免引导 LLM 调用未绑定工具
|
|
1348
|
-
const hasDelegate = this.hasTool('delegate_task');
|
|
1349
|
-
const delegateLines = [];
|
|
1350
|
-
if (hasDelegate) {
|
|
1351
|
-
delegateLines.push(` - For reports/dashboards: call \`delegate_task\` with agent ${reportAgent}.`);
|
|
1352
|
-
delegateLines.push(` - For documents: call \`delegate_task\` with agent ${docAgent}.`);
|
|
1353
|
-
delegateLines.push(` - For PPT: call \`delegate_task\` with agent ${pptAgent}.`);
|
|
1354
|
-
}
|
|
1355
|
-
const promptText = this.guardConfig.iterationGuardPrompt || [
|
|
1356
|
-
`[SYSTEM ITERATION BUDGET: iteration ${cur}/${max}, ${remaining} remaining]`,
|
|
1357
|
-
'',
|
|
1358
|
-
`⚠️ You have used ${cur} of ${max} iterations (${toolCallCount} tool calls). Budget is running low.`,
|
|
1359
|
-
'',
|
|
1360
|
-
'**MANDATORY rules for remaining iterations — violating these will result in task failure:**',
|
|
1361
|
-
'1. **STOP all data gathering immediately.** You already have enough data from previous tool calls.',
|
|
1362
|
-
'2. **DO NOT call web_fetch, execute_command, write_file, or run_script again.**',
|
|
1363
|
-
...(hasDelegate ? [`3. **NOW delegate remaining work (only if the user explicitly requested file/document generation):**`, ...delegateLines] : []),
|
|
1364
|
-
'4. If you cannot delegate, produce the final output NOW with the data you have.',
|
|
1365
|
-
'5. **Do NOT proactively generate files (PPT/PDF/HTML/Word) unless the user explicitly asked for them.** If the user only asked for analysis or information, present your findings directly in the conversation as text/markdown.',
|
|
1366
|
-
'',
|
|
1367
|
-
'Do NOT write any more scripts or fetch any more data. Your data collection phase is OVER.',
|
|
1368
|
-
].join('\n');
|
|
1369
|
-
const msg = { role: 'user', content: promptText };
|
|
1370
|
-
state.messages.push(msg);
|
|
1371
|
-
this.historyManager.addHistory(state.sessionId, msg);
|
|
1372
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.iteration_guard', sessionId: state.sessionId, data: { iteration: cur, max } });
|
|
1373
|
-
// 硬性禁用数据获取工具,防止 LLM 无视文字提示继续调用
|
|
1374
|
-
this.disableDataFetchTools(state);
|
|
1375
|
-
}
|
|
1207
|
+
(0, guard_controller_ts_1.injectIterationGuard)(this.guardControllerDeps, state);
|
|
1376
1208
|
}
|
|
1377
1209
|
/**
|
|
1378
1210
|
* 从可用工具列表中移除数据获取类工具,强制 LLM 转向产出。
|
|
@@ -1380,20 +1212,7 @@ ${textHistory.join('\n')}`;
|
|
|
1380
1212
|
* 仅移除尚未执行的 toolDefs,不影响正在执行的工具。
|
|
1381
1213
|
*/
|
|
1382
1214
|
disableDataFetchTools(state) {
|
|
1383
|
-
|
|
1384
|
-
state.toolDefs = state.toolDefs.filter(t => !this.dataFetchTools.has(t.function.name));
|
|
1385
|
-
const removed = before - state.toolDefs.length;
|
|
1386
|
-
// 同步将禁用的工具名加入 blockedTools 集合,供 tool executor 在执行层拦截
|
|
1387
|
-
// LLM 基于对话历史的幻觉调用(toolDefs 仅控制 LLM 可见的工具列表,
|
|
1388
|
-
// 但 tool executor 检查的是 toolRegistry,不会拦截已注册但被禁用的工具)
|
|
1389
|
-
if (!state.blockedTools)
|
|
1390
|
-
state.blockedTools = new Set();
|
|
1391
|
-
for (const name of this.dataFetchTools) {
|
|
1392
|
-
state.blockedTools.add(name);
|
|
1393
|
-
}
|
|
1394
|
-
if (removed > 0) {
|
|
1395
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.tools_disabled', sessionId: state.sessionId, data: { removed, remaining: state.toolDefs.length, blocked: state.blockedTools.size } });
|
|
1396
|
-
}
|
|
1215
|
+
(0, guard_controller_ts_1.disableDataFetchTools)(this.guardControllerDeps, state);
|
|
1397
1216
|
}
|
|
1398
1217
|
/**
|
|
1399
1218
|
* 数据获取循环检测 + 连续失败熔断
|
|
@@ -1403,90 +1222,11 @@ ${textHistory.join('\n')}`;
|
|
|
1403
1222
|
* 2. 连续失败熔断:最近 5+ 条工具调用中 4+ 条失败,强制停止试错、转向产出
|
|
1404
1223
|
*/
|
|
1405
1224
|
checkDataFetchLoop(state) {
|
|
1406
|
-
|
|
1407
|
-
return;
|
|
1408
|
-
// 数据获取类工具(非产出型)— 使用实例配置
|
|
1409
|
-
const DATA_FETCH_TOOLS = this.dataFetchTools;
|
|
1410
|
-
// 产出型工具(有这些就不算数据获取循环)— 使用实例配置
|
|
1411
|
-
const OUTPUT_TOOLS = this.outputTools;
|
|
1412
|
-
const hasOutput = state.toolCallRecords.some(r => OUTPUT_TOOLS.has(r.tool));
|
|
1413
|
-
if (hasOutput)
|
|
1414
|
-
return; // 已调用过产出型工具,不再干预
|
|
1415
|
-
const recent = state.toolCallRecords.slice(-6);
|
|
1416
|
-
// --- 条件 1:数据获取循环(最近 N+ 条全是数据获取类) ---
|
|
1417
|
-
const loopMin = this.guardConfig.dataFetchLoopMinCount;
|
|
1418
|
-
if (recent.length >= loopMin) {
|
|
1419
|
-
const lastN = recent.slice(-loopMin);
|
|
1420
|
-
const allDataFetch = lastN.every(r => DATA_FETCH_TOOLS.has(r.tool));
|
|
1421
|
-
if (allDataFetch) {
|
|
1422
|
-
this.injectDataFetchGuard(state, recent, 'loop');
|
|
1423
|
-
return;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
// --- 条件 2:连续失败熔断(最近 N+ 条中 M+ 条失败) ---
|
|
1427
|
-
const failMin = this.guardConfig.consecutiveFailMinCount;
|
|
1428
|
-
if (recent.length >= failMin) {
|
|
1429
|
-
const errorCount = recent.filter(r => r.isError).length;
|
|
1430
|
-
if (errorCount >= this.guardConfig.consecutiveFailErrorThreshold) {
|
|
1431
|
-
this.injectDataFetchGuard(state, recent, 'failures');
|
|
1432
|
-
return;
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
// --- 条件 3:跨迭代累计失败(总调用 >=8 且失败率 >=70%) ---
|
|
1436
|
-
// 解决 LLM 在不同迭代中切换工具类型(web_fetch -> http_request -> browser_navigate)
|
|
1437
|
-
// 导致每种工具的连续失败计数都不够触发条件 2 的问题。
|
|
1438
|
-
const totalCalls = state.toolCallRecords.length;
|
|
1439
|
-
if (totalCalls >= 8) {
|
|
1440
|
-
const totalErrors = state.toolCallRecords.filter(r => r.isError).length;
|
|
1441
|
-
if (totalErrors >= Math.floor(totalCalls * 0.7)) {
|
|
1442
|
-
this.injectDataFetchGuard(state, state.toolCallRecords.slice(-6), 'cumulative_failures');
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1225
|
+
(0, guard_controller_ts_1.checkDataFetchLoop)(this.guardControllerDeps, state);
|
|
1446
1226
|
}
|
|
1447
1227
|
/** 注入数据获取循环/连续失败熔断提示 */
|
|
1448
1228
|
injectDataFetchGuard(state, recent, reason) {
|
|
1449
|
-
|
|
1450
|
-
// 触发 guardrail 可观测事件(fire-and-forget,不阻塞主流程)
|
|
1451
|
-
void this.runHooks('on_data_fetch_loop', {
|
|
1452
|
-
sessionId: state.sessionId,
|
|
1453
|
-
iteration: state.iteration,
|
|
1454
|
-
traceId: state.toolContext?.custom?.traceId,
|
|
1455
|
-
});
|
|
1456
|
-
const toolSummary = recent.map(r => `${r.tool}(${r.isError ? 'err' : 'ok'})`).join(', ');
|
|
1457
|
-
const errorCount = recent.filter(r => r.isError).length;
|
|
1458
|
-
const reasonText = reason === 'loop'
|
|
1459
|
-
? `Your last ${recent.length} tool calls are all data-fetching without any output: ${toolSummary}`
|
|
1460
|
-
: `${errorCount} of your last ${recent.length} tool calls FAILED: ${toolSummary}`;
|
|
1461
|
-
const msg = {
|
|
1462
|
-
role: 'user',
|
|
1463
|
-
content: [
|
|
1464
|
-
`[SYSTEM: ${reason === 'loop' ? 'DATA GATHERING LOOP' : 'CONSECUTIVE FAILURES'} DETECTED]`,
|
|
1465
|
-
'',
|
|
1466
|
-
reasonText,
|
|
1467
|
-
'',
|
|
1468
|
-
'⛔ **You MUST stop trying to fetch more data NOW.**',
|
|
1469
|
-
'',
|
|
1470
|
-
'**Required action — do ONE of the following immediately:**',
|
|
1471
|
-
...(this.hasTool('delegate_task')
|
|
1472
|
-
? ['1. Call `delegate_task` with whatever data/context you have to let a specialist generate the output.']
|
|
1473
|
-
: []),
|
|
1474
|
-
'2. If delegation is not suitable, produce the final output NOW with available data.',
|
|
1475
|
-
'3. At minimum, provide a clear text summary to the user explaining what you found and what failed.',
|
|
1476
|
-
'',
|
|
1477
|
-
'**Do NOT:**',
|
|
1478
|
-
'- Write another script to fetch data',
|
|
1479
|
-
'- Try another API, URL, or npm package',
|
|
1480
|
-
'- Debug the current failure — accept it and move on',
|
|
1481
|
-
'',
|
|
1482
|
-
'The user is waiting for OUTPUT, not more failed attempts.',
|
|
1483
|
-
].join('\n'),
|
|
1484
|
-
};
|
|
1485
|
-
state.messages.push(msg);
|
|
1486
|
-
this.historyManager.addHistory(state.sessionId, msg);
|
|
1487
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.data_fetch_guard', sessionId: state.sessionId, data: { reason, iteration: state.iteration, recent: toolSummary } });
|
|
1488
|
-
// 硬性禁用数据获取工具,防止 LLM 无视文字提示继续调用
|
|
1489
|
-
this.disableDataFetchTools(state);
|
|
1229
|
+
(0, guard_controller_ts_1.injectDataFetchGuard)(this.guardControllerDeps, state, recent, reason);
|
|
1490
1230
|
}
|
|
1491
1231
|
/**
|
|
1492
1232
|
* 任务继续提示
|
|
@@ -1494,28 +1234,7 @@ ${textHistory.join('\n')}`;
|
|
|
1494
1234
|
* 典型场景:多步委托任务中,第一步数据采集完成后 LLM 未生成后续步骤的 delegate_task。
|
|
1495
1235
|
*/
|
|
1496
1236
|
injectContinuationNudge(state) {
|
|
1497
|
-
|
|
1498
|
-
const msg = {
|
|
1499
|
-
role: 'user',
|
|
1500
|
-
content: [
|
|
1501
|
-
'[SYSTEM: TASK CONTINUATION]',
|
|
1502
|
-
'',
|
|
1503
|
-
`You have completed ${toolCallCount} tool call(s) so far, but the original user request has NOT been fully fulfilled.`,
|
|
1504
|
-
'',
|
|
1505
|
-
'Please review the original request and continue with the remaining steps:',
|
|
1506
|
-
'- If you planned multi-step tasks (e.g., data gathering → PPT/report generation), **NOW execute the remaining steps**.',
|
|
1507
|
-
...(this.hasTool('delegate_task')
|
|
1508
|
-
? ['- Use `delegate_task` to delegate remaining work to appropriate specialists.']
|
|
1509
|
-
: []),
|
|
1510
|
-
'- Only if the user **explicitly requested** document/PPT/report generation, call the relevant tools now. Do NOT proactively generate files the user did not ask for.',
|
|
1511
|
-
'- Do NOT re-gather data you already have. Use the results from previous tool calls.',
|
|
1512
|
-
'',
|
|
1513
|
-
'Continue your work now.',
|
|
1514
|
-
].join('\n'),
|
|
1515
|
-
};
|
|
1516
|
-
state.messages.push(msg);
|
|
1517
|
-
this.historyManager.addHistory(state.sessionId, msg);
|
|
1518
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.continuation_nudge_injected', sessionId: state.sessionId, data: { iteration: state.iteration, nudge: state.continuationNudges } });
|
|
1237
|
+
(0, guard_controller_ts_1.injectContinuationNudge)(this.guardControllerDeps, state);
|
|
1519
1238
|
}
|
|
1520
1239
|
/**
|
|
1521
1240
|
* 渐进式结果交付
|
|
@@ -1523,28 +1242,7 @@ ${textHistory.join('\n')}`;
|
|
|
1523
1242
|
* 而不是等所有结果全部返回后才开始输出。减少用户感知等待时间。
|
|
1524
1243
|
*/
|
|
1525
1244
|
injectProgressiveNudge(state, toolCalls) {
|
|
1526
|
-
|
|
1527
|
-
if (delegateCalls.length < 2)
|
|
1528
|
-
return;
|
|
1529
|
-
const msg = {
|
|
1530
|
-
role: 'user',
|
|
1531
|
-
content: [
|
|
1532
|
-
'[SYSTEM: PROGRESSIVE DELIVERY]',
|
|
1533
|
-
'',
|
|
1534
|
-
`You dispatched ${delegateCalls.length} sub-tasks in parallel. Some may succeed while others fail or take longer.`,
|
|
1535
|
-
'',
|
|
1536
|
-
'When presenting results to the user:',
|
|
1537
|
-
'1. **Present each completed result as it becomes available** — do NOT wait for all tasks to finish.',
|
|
1538
|
-
'2. If a sub-agent reports network/sandbox restrictions or fails, **acknowledge it briefly and move on** with available data.',
|
|
1539
|
-
'3. **Do NOT re-dispatch** a failed task to the same or different agent — use what you already have.',
|
|
1540
|
-
'4. Start your final analysis/report with whatever data is available, noting which parts are missing.',
|
|
1541
|
-
'',
|
|
1542
|
-
'The user values SPEED over COMPLETENESS. A partial result delivered in 2 minutes is better than a perfect result delivered in 15 minutes.',
|
|
1543
|
-
].join('\n'),
|
|
1544
|
-
};
|
|
1545
|
-
state.messages.push(msg);
|
|
1546
|
-
this.historyManager.addHistory(state.sessionId, msg);
|
|
1547
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.progressive_nudge', sessionId: state.sessionId, data: { iteration: state.iteration, delegates: delegateCalls.length } });
|
|
1245
|
+
(0, guard_controller_ts_1.injectProgressiveNudge)(this.guardControllerDeps, state, toolCalls);
|
|
1548
1246
|
}
|
|
1549
1247
|
// ---- Hooks ----
|
|
1550
1248
|
/** 执行指定事件类型的所有 Hook */
|
|
@@ -1664,12 +1362,7 @@ ${textHistory.join('\n')}`;
|
|
|
1664
1362
|
}
|
|
1665
1363
|
/** 中断指定会话的 Agent 执行 */
|
|
1666
1364
|
abort(sessionId) {
|
|
1667
|
-
|
|
1668
|
-
if (controller) {
|
|
1669
|
-
controller.abort();
|
|
1670
|
-
this.statusMap.set(sessionId, 'aborting');
|
|
1671
|
-
(0, logger_ts_1.logEvent)({ event: 'engine.abort', sessionId, data: { reason: 'abort() called' } });
|
|
1672
|
-
}
|
|
1365
|
+
(0, session_state_manager_ts_1.abortSession)(this.sessionStateDeps, sessionId);
|
|
1673
1366
|
}
|
|
1674
1367
|
/**
|
|
1675
1368
|
* 中断指定会话及其所有子会话的 Agent 执行(级联 abort)。
|
|
@@ -1678,14 +1371,7 @@ ${textHistory.join('\n')}`;
|
|
|
1678
1371
|
* 用于确保父会话异常终止时,所有 delegate_task 派生的子任务也被终止。
|
|
1679
1372
|
*/
|
|
1680
1373
|
abortCascade(sessionId) {
|
|
1681
|
-
this.
|
|
1682
|
-
// 遍历直接子会话,递归 abort
|
|
1683
|
-
const children = this.getChildSessions(sessionId);
|
|
1684
|
-
for (const childId of children) {
|
|
1685
|
-
this.abortCascade(childId);
|
|
1686
|
-
}
|
|
1687
|
-
// 清理父子关系
|
|
1688
|
-
this.cleanupSessionRelations(sessionId);
|
|
1374
|
+
(0, session_state_manager_ts_1.abortCascade)(this.sessionStateDeps, sessionId);
|
|
1689
1375
|
}
|
|
1690
1376
|
/** 查询指定会话的 Agent 状态 */
|
|
1691
1377
|
getStatus(sessionId) {
|
|
@@ -1765,25 +1451,14 @@ ${textHistory.join('\n')}`;
|
|
|
1765
1451
|
* - 如果是子会话:从父会话的子集中移除自身
|
|
1766
1452
|
*/
|
|
1767
1453
|
cleanupSessionRelations(sessionId) {
|
|
1768
|
-
|
|
1769
|
-
const parentId = this.parentSessionMap.get(sessionId);
|
|
1770
|
-
if (parentId) {
|
|
1771
|
-
this.childSessionMap.get(parentId)?.delete(sessionId);
|
|
1772
|
-
this.parentSessionMap.delete(sessionId);
|
|
1773
|
-
}
|
|
1774
|
-
// 删除自身作为父会话的所有子关系记录(但保留子会话本身仍在运行)
|
|
1775
|
-
this.childSessionMap.delete(sessionId);
|
|
1454
|
+
(0, session_state_manager_ts_1.cleanupSessionRelations)(this.sessionStateDeps, sessionId);
|
|
1776
1455
|
}
|
|
1777
1456
|
// ---- 内部辅助 ----
|
|
1778
1457
|
createEvent(sessionId, event) {
|
|
1779
1458
|
return { ...event, timestamp: Date.now(), sessionId };
|
|
1780
1459
|
}
|
|
1781
1460
|
createNoopShell() {
|
|
1782
|
-
return
|
|
1783
|
-
exec: async () => 'Error: Shell executor not configured',
|
|
1784
|
-
write: () => { },
|
|
1785
|
-
read: () => '',
|
|
1786
|
-
};
|
|
1461
|
+
return (0, tool_section_builder_ts_1.createNoopShell)();
|
|
1787
1462
|
}
|
|
1788
1463
|
}
|
|
1789
1464
|
exports.AgentEngine = AgentEngine;
|