@ai-zen/agents-sdk 1.1.0 → 1.2.0-alpha.1
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/README.md +5 -17
- package/README.zh.md +5 -17
- package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +28 -1
- package/dist/agent-plugins/AutoRefreshToolsPlugin.js +29 -8
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +64 -0
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +68 -0
- package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +0 -1
- package/dist/agent-plugins/UnknownToolHintPlugin.js +0 -1
- package/dist/config/ConfigManager.d.ts +30 -10
- package/dist/config/ConfigManager.js +42 -17
- package/dist/config/constants.d.ts +5 -3
- package/dist/config/constants.js +10 -4
- package/dist/config/migrate.d.ts +15 -6
- package/dist/config/migrate.js +16 -12
- package/dist/index.d.ts +13 -4
- package/dist/index.js +9 -4
- package/dist/runtime/HandoffService.d.ts +1 -1
- package/dist/runtime/HandoffService.js +17 -19
- package/dist/runtime/SdkAgent.d.ts +11 -4
- package/dist/runtime/SdkAgent.js +10 -4
- package/dist/runtime/completeOnce.d.ts +43 -0
- package/dist/runtime/completeOnce.js +38 -0
- package/dist/runtime/createAgent.d.ts +27 -1
- package/dist/runtime/createAgent.js +37 -7
- package/dist/runtime/createModel.d.ts +13 -1
- package/dist/runtime/createModel.js +14 -1
- package/dist/runtime/resolveModel.d.ts +93 -0
- package/dist/runtime/resolveModel.js +78 -0
- package/dist/scope/Scope.d.ts +1 -2
- package/dist/scope/Scope.js +1 -1
- package/dist/scope/ScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/allInOne.d.ts +1 -1
- package/dist/scope/plugins/allInOne.js +1 -1
- package/dist/scope/plugins/builtin/ExecTool.js +4 -0
- package/dist/scope/plugins/builtin/SdkCallbackTool.d.ts +1 -2
- package/dist/scope/plugins/builtin/SdkCallbackTool.js +0 -1
- package/dist/scope/plugins/builtin/SpawnTool.js +2 -2
- package/dist/scope/plugins/builtin/ViewImageTool.d.ts +1 -1
- package/dist/scope/plugins/builtin/ViewImageTool.js +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.js +1 -1
- package/dist/scope/plugins/mcp/mcpTools.d.ts +1 -1
- package/dist/scope/plugins/mcp/mcpTools.js +4 -4
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +1 -1
- package/dist/scope/plugins/skills/discover.js +1 -1
- package/dist/scope/plugins/usertools/discover.d.ts +24 -0
- package/dist/scope/plugins/usertools/discover.js +17 -5
- package/dist/shared/content-blocks.d.ts +6 -9
- package/dist/shared/content-blocks.js +38 -58
- package/dist/types/index.d.ts +76 -30
- package/dist/types/index.js +0 -4
- package/package.json +5 -5
package/dist/config/migrate.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `maxContextChars` 是 token 口径之前的历史遗留,按 `floor(chars / 4)` 折成 tokens
|
|
10
10
|
* (与旧代码的回退算法一致)后并入 `handoff`。
|
|
11
11
|
* 2. **`Model.reasoning` → `Model.reasoningPreset`**
|
|
12
|
-
*
|
|
12
|
+
* 老配置用 `reasoning: { efforts, disable? }` 在模型上声明思考能力,现在是
|
|
13
13
|
* 「引用策略表里的名字」。未标 `custom` 的模型会被出厂定义整块覆盖,但**标了 `custom`
|
|
14
14
|
* 的模型会原地保留**,于是留下一个无人认识的 `reasoning` 死字段,同时因为缺
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
19
|
*
|
|
20
|
+
* ## `defaultModel` 是**反例**:它不需要迁移,也绝不能清
|
|
21
|
+
*
|
|
22
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在
|
|
23
|
+
* `runtime/resolveModel.ts`),`defaultModel` 就是**全局兜底层**。字段名从未变过,
|
|
24
|
+
* 所以这里**什么都不用搬**:老配置里写着的原样保留、继续生效。绝对不能再清 ——
|
|
25
|
+
* 清掉等于用户升级一次就静默丢一次自己配的兜底模型,而这属于「默认值缺位」里最坏的
|
|
26
|
+
* 一种:丢的是用户明确填过的值。
|
|
27
|
+
*
|
|
20
28
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
21
29
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
22
30
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -61,7 +69,8 @@ export declare function migrateModelReasoning(model: Model): {
|
|
|
61
69
|
* 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
62
70
|
*
|
|
63
71
|
* 同时做两件字段级收敛:
|
|
64
|
-
* -
|
|
72
|
+
* - **保留** `defaultModel`(三级解析的全局兜底层,见文件头):它不在这里被删、
|
|
73
|
+
* 也不在这里被补 —— 用户没配就没有兜底层,`createAgent` 会给出明确报错;
|
|
65
74
|
* - 补齐中断策略(`abortedMessageStrategy` / `abortedToolRoundStrategy`):把缺失或
|
|
66
75
|
* 非法值写成出厂默认。这样「配置即事实」——文件里写着的就是运行时用的,不再需要
|
|
67
76
|
* 使用方各自 `?? "keep"` 地兵分两路兜底。
|
|
@@ -78,12 +87,12 @@ export declare function normalizeAbortStrategies(config: AppConfig): boolean;
|
|
|
78
87
|
/**
|
|
79
88
|
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
80
89
|
*
|
|
81
|
-
* ##
|
|
90
|
+
* ## 为什么要补
|
|
82
91
|
*
|
|
83
|
-
* `capabilities.filesApi`
|
|
84
|
-
*
|
|
92
|
+
* `capabilities.filesApi` 是后来才引入的能力位 —— 它把 `view_image` 的判定从「端点 id
|
|
93
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
85
94
|
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
86
|
-
* 迁移此前也完全不碰 `endpoints` ——
|
|
95
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是在这之前就已写下的配置,其 deepseek
|
|
87
96
|
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
88
97
|
*
|
|
89
98
|
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
package/dist/config/migrate.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `maxContextChars` 是 token 口径之前的历史遗留,按 `floor(chars / 4)` 折成 tokens
|
|
10
10
|
* (与旧代码的回退算法一致)后并入 `handoff`。
|
|
11
11
|
* 2. **`Model.reasoning` → `Model.reasoningPreset`**
|
|
12
|
-
*
|
|
12
|
+
* 老配置用 `reasoning: { efforts, disable? }` 在模型上声明思考能力,现在是
|
|
13
13
|
* 「引用策略表里的名字」。未标 `custom` 的模型会被出厂定义整块覆盖,但**标了 `custom`
|
|
14
14
|
* 的模型会原地保留**,于是留下一个无人认识的 `reasoning` 死字段,同时因为缺
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
19
|
*
|
|
20
|
+
* ## `defaultModel` 是**反例**:它不需要迁移,也绝不能清
|
|
21
|
+
*
|
|
22
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在
|
|
23
|
+
* `runtime/resolveModel.ts`),`defaultModel` 就是**全局兜底层**。字段名从未变过,
|
|
24
|
+
* 所以这里**什么都不用搬**:老配置里写着的原样保留、继续生效。绝对不能再清 ——
|
|
25
|
+
* 清掉等于用户升级一次就静默丢一次自己配的兜底模型,而这属于「默认值缺位」里最坏的
|
|
26
|
+
* 一种:丢的是用户明确填过的值。
|
|
27
|
+
*
|
|
20
28
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
21
29
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
22
30
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -68,7 +76,7 @@ export function migrateModelThresholds(model) {
|
|
|
68
76
|
return { model, changed: false };
|
|
69
77
|
const fromChars = legacyChars !== undefined ? Math.max(1, Math.floor(legacyChars / 4)) : undefined;
|
|
70
78
|
const handoff = current.handoff ?? legacyTokens ?? fromChars ?? legacySingle ?? DEFAULT_HANDOFF_THRESHOLD;
|
|
71
|
-
// 旧数据里没有 guard
|
|
79
|
+
// 旧数据里没有 guard 这一项:按 1.5 倍(历史上护栏用的默认倍数)折算一次,
|
|
72
80
|
// 让迁移后的实际行为与迁移前一致。这是**一次性**换算,落盘后两个值都是整数,
|
|
73
81
|
// 运行时不再有任何倍数关系(想调硬线就直接改 guard 的数字)。
|
|
74
82
|
const guard = current.guard ?? Math.round(handoff * 1.5);
|
|
@@ -104,7 +112,8 @@ export function migrateModelReasoning(model) {
|
|
|
104
112
|
* 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
105
113
|
*
|
|
106
114
|
* 同时做两件字段级收敛:
|
|
107
|
-
* -
|
|
115
|
+
* - **保留** `defaultModel`(三级解析的全局兜底层,见文件头):它不在这里被删、
|
|
116
|
+
* 也不在这里被补 —— 用户没配就没有兜底层,`createAgent` 会给出明确报错;
|
|
108
117
|
* - 补齐中断策略(`abortedMessageStrategy` / `abortedToolRoundStrategy`):把缺失或
|
|
109
118
|
* 非法值写成出厂默认。这样「配置即事实」——文件里写着的就是运行时用的,不再需要
|
|
110
119
|
* 使用方各自 `?? "keep"` 地兵分两路兜底。
|
|
@@ -124,11 +133,6 @@ export function migrateConfig(config) {
|
|
|
124
133
|
// 端点数组浅拷贝:能力位补齐会改元素,不把副作用浇到调用方手里的旧对象上
|
|
125
134
|
endpoints: (config.endpoints ?? []).map((endpoint) => ({ ...endpoint })),
|
|
126
135
|
};
|
|
127
|
-
// 已废弃字段:不参与运行,也不允许再写回磁盘
|
|
128
|
-
if ("defaultModel" in next) {
|
|
129
|
-
delete next.defaultModel;
|
|
130
|
-
changed = true;
|
|
131
|
-
}
|
|
132
136
|
if (normalizeAbortStrategies(next))
|
|
133
137
|
changed = true;
|
|
134
138
|
if (normalizeEndpointCapabilities(next))
|
|
@@ -156,12 +160,12 @@ export function normalizeAbortStrategies(config) {
|
|
|
156
160
|
/**
|
|
157
161
|
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
158
162
|
*
|
|
159
|
-
* ##
|
|
163
|
+
* ## 为什么要补
|
|
160
164
|
*
|
|
161
|
-
* `capabilities.filesApi`
|
|
162
|
-
*
|
|
165
|
+
* `capabilities.filesApi` 是后来才引入的能力位 —— 它把 `view_image` 的判定从「端点 id
|
|
166
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
163
167
|
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
164
|
-
* 迁移此前也完全不碰 `endpoints` ——
|
|
168
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是在这之前就已写下的配置,其 deepseek
|
|
165
169
|
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
166
170
|
*
|
|
167
171
|
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
|
8
8
|
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
9
9
|
export type { SkillInfo, Frontmatter } from "./scope/plugins/skills/discover.js";
|
|
10
10
|
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
11
|
-
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
11
|
+
export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
|
|
12
|
+
export type { UserToolFile } from "./scope/plugins/usertools/discover.js";
|
|
12
13
|
export { Scope } from "./scope/Scope.js";
|
|
13
14
|
export type { FilterOutput, ExcludeOptions, FilterOptions } from "./scope/Scope.js";
|
|
14
15
|
export type { ScopePlugin, ScopeCandidates } from "./scope/ScopePlugin.js";
|
|
@@ -20,17 +21,23 @@ export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePl
|
|
|
20
21
|
export { allInOne } from "./scope/plugins/allInOne.js";
|
|
21
22
|
export type { AllInOneOptions } from "./scope/plugins/allInOne.js";
|
|
22
23
|
export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
|
|
24
|
+
export type { ConfigRecoveredHandler } from "./config/ConfigManager.js";
|
|
23
25
|
export { FACTORY_SKILLS, HANDOFF_SKILL_ID, FALLBACK_HANDOFF_TEMPLATE, isCustomSkill, } from "./config/factory-skills.js";
|
|
24
26
|
export { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./config/reasoning-presets.js";
|
|
25
27
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
26
28
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
27
|
-
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash,
|
|
29
|
+
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash, MIME_BY_EXT, DEFAULT_MAX_INLINE_BYTES, } from "./shared/content-blocks.js";
|
|
28
30
|
export type { FileSource, FileToSectionInput, FileToSectionResult, ContentTransport, UploadFn, } from "./shared/content-blocks.js";
|
|
29
|
-
export { createModel } from "./runtime/createModel.js";
|
|
31
|
+
export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
32
|
+
export type { AgentModel } from "./runtime/createModel.js";
|
|
33
|
+
export { completeOnce } from "./runtime/completeOnce.js";
|
|
34
|
+
export type { CompleteOnceInput } from "./runtime/completeOnce.js";
|
|
30
35
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
31
36
|
export type { AgentPlugin, SendContext } from "./runtime/SdkAgent.js";
|
|
32
37
|
export { createAgent } from "./runtime/createAgent.js";
|
|
33
38
|
export type { CreateAgentOptions } from "./runtime/createAgent.js";
|
|
39
|
+
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
40
|
+
export type { ModelLevel, ModelResolutionInput, ModelParamsResolutionInput, ResolvedModel, } from "./runtime/resolveModel.js";
|
|
34
41
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
35
42
|
export type { McpConnectOptions } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
36
43
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
@@ -40,10 +47,12 @@ export type { HandoffContext, HandoffMode, HandoffParams, HandoffServiceOptions,
|
|
|
40
47
|
export { HandoffGuardPlugin } from "./runtime/HandoffGuardPlugin.js";
|
|
41
48
|
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
42
49
|
export type { AutoMigrateOptions, AutoMigrateTriggerInfo, AutoMigrateModeResolver, } from "./agent-plugins/AutoMigratePlugin.js";
|
|
43
|
-
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
50
|
+
export { AutoRefreshToolsPlugin, type AutoRefreshWhen, } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
44
51
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
45
52
|
export type { ContextGuardOptions } from "./agent-plugins/ContextGuardPlugin.js";
|
|
46
53
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
54
|
+
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
55
|
+
export type { SubAgentGuardOptions } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
47
56
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
48
57
|
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
49
58
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { discoverBuiltinTools } from "./scope/plugins/builtin/discover.js";
|
|
|
6
6
|
export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
7
7
|
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
8
8
|
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
9
|
-
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
9
|
+
export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
|
|
10
10
|
// Scope — 全局上下文 + 能力装配编排容器
|
|
11
11
|
export { Scope } from "./scope/Scope.js";
|
|
12
12
|
export { BuiltinToolsScopePlugin } from "./scope/plugins/builtin/BuiltinToolsScopePlugin.js";
|
|
@@ -26,20 +26,25 @@ export { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./config/reas
|
|
|
26
26
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
27
27
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
28
28
|
// 文件 → 内容块(统一入口)— 上层应用构造媒体消息时请走这里,不要自己判断上传还是内联
|
|
29
|
-
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash,
|
|
29
|
+
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash, MIME_BY_EXT, DEFAULT_MAX_INLINE_BYTES, } from "./shared/content-blocks.js";
|
|
30
30
|
// 运行时
|
|
31
|
-
export { createModel } from "./runtime/createModel.js";
|
|
31
|
+
export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
32
|
+
// 一次性模型调用(不流式 / 不带工具):交接摘要、会话自动标题共用这一份请求体形状
|
|
33
|
+
export { completeOnce } from "./runtime/completeOnce.js";
|
|
32
34
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
33
35
|
export { createAgent } from "./runtime/createAgent.js";
|
|
36
|
+
// 模型三级解析(唯一实现):档位类型也导出,服务端与客户端要按它渲染「当前生效档」
|
|
37
|
+
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
34
38
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
35
39
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
36
40
|
export { HandoffAbortedError, HandoffService } from "./runtime/HandoffService.js";
|
|
37
41
|
export { HandoffGuardPlugin } from "./runtime/HandoffGuardPlugin.js";
|
|
38
42
|
// 插件
|
|
39
43
|
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
40
|
-
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
44
|
+
export { AutoRefreshToolsPlugin, } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
41
45
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
42
46
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
47
|
+
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
43
48
|
// 工具 — 内置工具类 + 动态工具工厂
|
|
44
49
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
45
50
|
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
@@ -116,7 +116,7 @@ export interface MigrateParams extends HandoffParams {
|
|
|
116
116
|
*
|
|
117
117
|
* 职责分层(这是本模块唯一的设计主线):
|
|
118
118
|
* - `handoff()`:**只产出交接文档**(停工 → 写文档 → 校验 → 失败降级),不动会话;
|
|
119
|
-
* - `migrate()`:`handoff()`
|
|
119
|
+
* - `migrate()`:`handoff()` 之后清历史并开新会话。
|
|
120
120
|
*
|
|
121
121
|
* 模板的唯一真相源是 `handoff` Skill(`SKILL.md`);代码只负责
|
|
122
122
|
* 「读正文 → 注入 → 校验文件 → 读不到时用兜底模板」,不持有第二份章节清单。
|
|
@@ -4,6 +4,7 @@ import { Message } from "@ai-zen/agents-core";
|
|
|
4
4
|
import { getLogger } from "../shared/logger.js";
|
|
5
5
|
import { readSkill } from "../scope/plugins/skills/discover.js";
|
|
6
6
|
import { FALLBACK_HANDOFF_TEMPLATE, HANDOFF_SKILL_ID } from "../config/factory-skills.js";
|
|
7
|
+
import { completeOnce } from "./completeOnce.js";
|
|
7
8
|
import { HandoffGuardPlugin } from "./HandoffGuardPlugin.js";
|
|
8
9
|
/**
|
|
9
10
|
* 交接被调用方取消(`AbortSignal` 触发)。
|
|
@@ -49,7 +50,7 @@ function mergeSignals(own, external) {
|
|
|
49
50
|
*
|
|
50
51
|
* 职责分层(这是本模块唯一的设计主线):
|
|
51
52
|
* - `handoff()`:**只产出交接文档**(停工 → 写文档 → 校验 → 失败降级),不动会话;
|
|
52
|
-
* - `migrate()`:`handoff()`
|
|
53
|
+
* - `migrate()`:`handoff()` 之后清历史并开新会话。
|
|
53
54
|
*
|
|
54
55
|
* 模板的唯一真相源是 `handoff` Skill(`SKILL.md`);代码只负责
|
|
55
56
|
* 「读正文 → 注入 → 校验文件 → 读不到时用兜底模板」,不持有第二份章节清单。
|
|
@@ -468,25 +469,22 @@ export class HandoffService {
|
|
|
468
469
|
const modelConfig = this.modelConfig ?? agent.modelConfig;
|
|
469
470
|
const skillContent = await this.readSkillContent();
|
|
470
471
|
this.throwIfAborted(signal);
|
|
471
|
-
//
|
|
472
|
-
//
|
|
473
|
-
|
|
472
|
+
// 请求体形状(system + user、modelConfig 展开、signal 走 RequestOptions)的唯一实现在
|
|
473
|
+
// `completeOnce`:会话自动标题那一类「辅助小请求」走同一条路,两边不会一份带 stream、
|
|
474
|
+
// 另一份不带
|
|
475
|
+
const handoffDoc = await completeOnce({
|
|
476
|
+
client,
|
|
474
477
|
model,
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
{ role: "user", content: historyText },
|
|
486
|
-
],
|
|
487
|
-
}, signal ? { signal } : undefined);
|
|
488
|
-
const handoffDoc = response.choices[0]?.message?.content;
|
|
489
|
-
if (!handoffDoc || !handoffDoc.trim()) {
|
|
478
|
+
modelConfig,
|
|
479
|
+
system: HandoffService.createHandoffInstruction({
|
|
480
|
+
skillContent,
|
|
481
|
+
handoffPath,
|
|
482
|
+
toolsAvailable: false,
|
|
483
|
+
}),
|
|
484
|
+
user: historyText,
|
|
485
|
+
signal,
|
|
486
|
+
});
|
|
487
|
+
if (!handoffDoc.trim()) {
|
|
490
488
|
throw new Error("Failed to generate the handoff document");
|
|
491
489
|
}
|
|
492
490
|
return handoffDoc;
|
|
@@ -3,6 +3,7 @@ import { Agent } from "@ai-zen/agents-core";
|
|
|
3
3
|
import type { AbortedMessageStrategy, AbortedToolRoundStrategy, AgentNS, Tool } from "@ai-zen/agents-core";
|
|
4
4
|
import type { AgentDefinition } from "../types/index.js";
|
|
5
5
|
import type { Scope } from "../scope/Scope.js";
|
|
6
|
+
import type { ModelLevel } from "./resolveModel.js";
|
|
6
7
|
export type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
|
|
7
8
|
/**
|
|
8
9
|
* SDK Agent — 继承 Core Agent,携带 SDK 层额外信息。
|
|
@@ -10,20 +11,26 @@ export type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
|
|
|
10
11
|
* Core Agent 不感知权限、文件系统等业务逻辑;
|
|
11
12
|
* SdkAgent 在 Core Agent 基础上增加了 SDK 层需要的元数据:
|
|
12
13
|
* - scope:全局 Scope 实例
|
|
13
|
-
* - definition:Agent
|
|
14
|
+
* - definition:Agent 定义(含权限 permissions)。**模型解析生效之后的那一份**:
|
|
15
|
+
* 会话级覆盖会写进它的 `modelId`(见 `createAgent`),于是「读哪个字段都不会跑偏」;
|
|
16
|
+
* - modelLevel:这个模型是从哪一级解析出来的(会话 / Agent 定义 / 全局兜底)。
|
|
17
|
+
* 值是 `resolveModel` 的副产品,客户端用它把「当前生效档」标在 `/model` 选择器上。
|
|
14
18
|
*
|
|
15
|
-
* 插件能力(use / init / send 钩子分发)继承自 Core Agent
|
|
19
|
+
* 插件能力(use / init / send 钩子分发)继承自 Core Agent,此处不重复实现。
|
|
16
20
|
* 未知工具的 MCP 智能提示由独立插件 `UnknownToolHintPlugin` 提供(调用方显式 use)。
|
|
17
|
-
* 权限统一从 `definition.permissions`
|
|
21
|
+
* 权限统一从 `definition.permissions` 读取。
|
|
18
22
|
*/
|
|
19
23
|
export declare class SdkAgent extends Agent {
|
|
20
24
|
/** 全局 Scope 实例 */
|
|
21
25
|
readonly scope: Scope;
|
|
22
|
-
/** Agent
|
|
26
|
+
/** Agent 定义(模型解析生效之后的那一份:`modelId` 是**实际在用**的模型) */
|
|
23
27
|
readonly definition: AgentDefinition;
|
|
28
|
+
/** 生效模型来自哪一级(三级解析的结果,见 `resolveModel`) */
|
|
29
|
+
readonly modelLevel: ModelLevel;
|
|
24
30
|
constructor(params: {
|
|
25
31
|
scope: Scope;
|
|
26
32
|
definition: AgentDefinition;
|
|
33
|
+
modelLevel: ModelLevel;
|
|
27
34
|
client: OpenAI;
|
|
28
35
|
model: string;
|
|
29
36
|
modelConfig?: Record<string, unknown>;
|
package/dist/runtime/SdkAgent.js
CHANGED
|
@@ -5,17 +5,22 @@ import { Agent } from "@ai-zen/agents-core";
|
|
|
5
5
|
* Core Agent 不感知权限、文件系统等业务逻辑;
|
|
6
6
|
* SdkAgent 在 Core Agent 基础上增加了 SDK 层需要的元数据:
|
|
7
7
|
* - scope:全局 Scope 实例
|
|
8
|
-
* - definition:Agent
|
|
8
|
+
* - definition:Agent 定义(含权限 permissions)。**模型解析生效之后的那一份**:
|
|
9
|
+
* 会话级覆盖会写进它的 `modelId`(见 `createAgent`),于是「读哪个字段都不会跑偏」;
|
|
10
|
+
* - modelLevel:这个模型是从哪一级解析出来的(会话 / Agent 定义 / 全局兜底)。
|
|
11
|
+
* 值是 `resolveModel` 的副产品,客户端用它把「当前生效档」标在 `/model` 选择器上。
|
|
9
12
|
*
|
|
10
|
-
* 插件能力(use / init / send 钩子分发)继承自 Core Agent
|
|
13
|
+
* 插件能力(use / init / send 钩子分发)继承自 Core Agent,此处不重复实现。
|
|
11
14
|
* 未知工具的 MCP 智能提示由独立插件 `UnknownToolHintPlugin` 提供(调用方显式 use)。
|
|
12
|
-
* 权限统一从 `definition.permissions`
|
|
15
|
+
* 权限统一从 `definition.permissions` 读取。
|
|
13
16
|
*/
|
|
14
17
|
export class SdkAgent extends Agent {
|
|
15
18
|
/** 全局 Scope 实例 */
|
|
16
19
|
scope;
|
|
17
|
-
/** Agent
|
|
20
|
+
/** Agent 定义(模型解析生效之后的那一份:`modelId` 是**实际在用**的模型) */
|
|
18
21
|
definition;
|
|
22
|
+
/** 生效模型来自哪一级(三级解析的结果,见 `resolveModel`) */
|
|
23
|
+
modelLevel;
|
|
19
24
|
constructor(params) {
|
|
20
25
|
super({
|
|
21
26
|
client: params.client,
|
|
@@ -30,5 +35,6 @@ export class SdkAgent extends Agent {
|
|
|
30
35
|
});
|
|
31
36
|
this.scope = params.scope;
|
|
32
37
|
this.definition = params.definition;
|
|
38
|
+
this.modelLevel = params.modelLevel;
|
|
33
39
|
}
|
|
34
40
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次性模型调用 —— 「不流式、不带工具、问一句答一句」的唯一实现。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么要有它
|
|
5
|
+
*
|
|
6
|
+
* 产品里有几处「辅助小请求」:交接文档的 `summary` 模式、会话自动起名。它们的共同点是
|
|
7
|
+
* **不是对话**:没有消息历史要维护、没有工具、不流式、结果用完即弃。如果各自
|
|
8
|
+
* `client.chat.completions.create(...)` 一遍,就会各写一份「要不要 stream / 带不带 tools /
|
|
9
|
+
* modelConfig 怎么摊开 / signal 怎么传」—— 这四件事写错任何一样都不会报错,只会让请求
|
|
10
|
+
* 变成另一种东西(例如带了 `stream: true` 于是拿到的正文永远是空的)。
|
|
11
|
+
*
|
|
12
|
+
* 所以:请求体的形状只在这里拼一次,两处(`HandoffService.generateSummary`、服务端的
|
|
13
|
+
* 自动标题)都从这里走。
|
|
14
|
+
*
|
|
15
|
+
* ## 为什么返回字符串而不是整条 response
|
|
16
|
+
*
|
|
17
|
+
* 调用方要的都是「模型说了什么」。把 response 交出去,每个调用方都会再写一次
|
|
18
|
+
* `choices[0]?.message?.content ?? ""`,而 `?? ""` 与「空正文算失败」是两种不同的态度:
|
|
19
|
+
* 前者交给调用方判(`summary` 模式把空正文当失败并抛错,标题直接留空),本函数不替它们选。
|
|
20
|
+
*
|
|
21
|
+
* ## 为什么取消信号走第二参数
|
|
22
|
+
*
|
|
23
|
+
* 与 `core/Agent.ts` 调用模型时一致:`signal` 属于 `RequestOptions`(HTTP 层),塞进 body
|
|
24
|
+
* 不会被 OpenAI SDK 当成取消信号,请求照样会跑完。
|
|
25
|
+
*/
|
|
26
|
+
import type OpenAI from "openai";
|
|
27
|
+
import type { ModelParams } from "../types/index.js";
|
|
28
|
+
export interface CompleteOnceInput {
|
|
29
|
+
/** 已装配好的客户端(`createModel` / `createModelFromConfig` 的产物) */
|
|
30
|
+
client: OpenAI;
|
|
31
|
+
/** 发给端点的模型名(`modelName || id`) */
|
|
32
|
+
model: string;
|
|
33
|
+
/** 模型参数(同 `model.defaultParams` + 覆盖),展开进 body */
|
|
34
|
+
modelConfig?: ModelParams;
|
|
35
|
+
/** 一次性指令(角色是 system) */
|
|
36
|
+
system: string;
|
|
37
|
+
/** 这一次要处理的输入(角色是 user) */
|
|
38
|
+
user: string;
|
|
39
|
+
/** 取消 / 超时信号;触发后请求真的被中断 */
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}
|
|
42
|
+
/** 发一次非流式请求,返回正文(模型没给正文时是空串,由调用方判成败) */
|
|
43
|
+
export declare function completeOnce(input: CompleteOnceInput): Promise<string>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次性模型调用 —— 「不流式、不带工具、问一句答一句」的唯一实现。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么要有它
|
|
5
|
+
*
|
|
6
|
+
* 产品里有几处「辅助小请求」:交接文档的 `summary` 模式、会话自动起名。它们的共同点是
|
|
7
|
+
* **不是对话**:没有消息历史要维护、没有工具、不流式、结果用完即弃。如果各自
|
|
8
|
+
* `client.chat.completions.create(...)` 一遍,就会各写一份「要不要 stream / 带不带 tools /
|
|
9
|
+
* modelConfig 怎么摊开 / signal 怎么传」—— 这四件事写错任何一样都不会报错,只会让请求
|
|
10
|
+
* 变成另一种东西(例如带了 `stream: true` 于是拿到的正文永远是空的)。
|
|
11
|
+
*
|
|
12
|
+
* 所以:请求体的形状只在这里拼一次,两处(`HandoffService.generateSummary`、服务端的
|
|
13
|
+
* 自动标题)都从这里走。
|
|
14
|
+
*
|
|
15
|
+
* ## 为什么返回字符串而不是整条 response
|
|
16
|
+
*
|
|
17
|
+
* 调用方要的都是「模型说了什么」。把 response 交出去,每个调用方都会再写一次
|
|
18
|
+
* `choices[0]?.message?.content ?? ""`,而 `?? ""` 与「空正文算失败」是两种不同的态度:
|
|
19
|
+
* 前者交给调用方判(`summary` 模式把空正文当失败并抛错,标题直接留空),本函数不替它们选。
|
|
20
|
+
*
|
|
21
|
+
* ## 为什么取消信号走第二参数
|
|
22
|
+
*
|
|
23
|
+
* 与 `core/Agent.ts` 调用模型时一致:`signal` 属于 `RequestOptions`(HTTP 层),塞进 body
|
|
24
|
+
* 不会被 OpenAI SDK 当成取消信号,请求照样会跑完。
|
|
25
|
+
*/
|
|
26
|
+
/** 发一次非流式请求,返回正文(模型没给正文时是空串,由调用方判成败) */
|
|
27
|
+
export async function completeOnce(input) {
|
|
28
|
+
const { client, model, modelConfig, system, user, signal } = input;
|
|
29
|
+
const response = await client.chat.completions.create({
|
|
30
|
+
model,
|
|
31
|
+
...(modelConfig ?? {}),
|
|
32
|
+
messages: [
|
|
33
|
+
{ role: "system", content: system },
|
|
34
|
+
{ role: "user", content: user },
|
|
35
|
+
],
|
|
36
|
+
}, signal ? { signal } : undefined);
|
|
37
|
+
return response.choices?.[0]?.message?.content ?? "";
|
|
38
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SdkAgent } from "./SdkAgent.js";
|
|
2
2
|
import type { Scope } from "../scope/Scope.js";
|
|
3
|
+
import type { ModelParams } from "../types/index.js";
|
|
3
4
|
import type { AbortedMessageStrategy, AbortedToolRoundStrategy } from "@ai-zen/agents-core";
|
|
4
5
|
/**
|
|
5
6
|
* `createAgent` 的可选行为开关。
|
|
@@ -18,15 +19,40 @@ export interface CreateAgentOptions {
|
|
|
18
19
|
* `keep` 可让模型在下一轮接着半截往下说,而不是忘掉自己说过什么。
|
|
19
20
|
*/
|
|
20
21
|
abortedMessageStrategy?: AbortedMessageStrategy;
|
|
22
|
+
/**
|
|
23
|
+
* **会话级**模型覆盖(三级解析的第一级)。
|
|
24
|
+
*
|
|
25
|
+
* 只有「这一段会话」该换模型时才传(服务端从 `SessionRecord.modelId` 取,`/model`
|
|
26
|
+
* 不带作用级别的写法写的就是它)。不传就落到 Agent 定义,再落到 `config.defaultModel`。
|
|
27
|
+
*
|
|
28
|
+
* 为什么由调用方传、而不是 SDK 自己去读会话存档:本层不认识会话(它只认识 Scope 与
|
|
29
|
+
* Agent 定义),会话存档是服务端的财产。**解析顺序仍只在这里实现**(见 `resolveModel`)。
|
|
30
|
+
*/
|
|
31
|
+
modelId?: string;
|
|
32
|
+
/**
|
|
33
|
+
* **会话级**模型参数覆盖(三级解析里与 `modelId` 同一级的那一份,服务端从会话存档的
|
|
34
|
+
* `modelParams` 取)。
|
|
35
|
+
*
|
|
36
|
+
* 只有 `modelId` 那一级赢了它才会真正生效 —— 取哪一份由 `resolveModelParams` 按档位
|
|
37
|
+
* 决定(同一处规则)。**它不会与 `AgentDefinition.modelParams` 合并**:定义那份是配给
|
|
38
|
+
* 定义绑定的模型的,会话把模型换掉之后把旧参数发给新模型就是端点 400。
|
|
39
|
+
*/
|
|
40
|
+
modelParams?: ModelParams;
|
|
21
41
|
}
|
|
22
42
|
/**
|
|
23
43
|
* 从磁盘创建 Agent。
|
|
24
44
|
*
|
|
25
45
|
* 通过 Scope 获取已发现的能力,读取 Agent 定义,过滤并实例化工具,产出 SdkAgent。
|
|
46
|
+
* 模型按 **会话级覆盖 > Agent 定义 > 全局兜底** 解析(唯一实现:`resolveModel`);
|
|
47
|
+
* **参数取「模型来自哪一级」那一份**、绝不跨级混合(同一处实现:`resolveModelParams`)。
|
|
26
48
|
*
|
|
27
49
|
* ```ts
|
|
28
50
|
* const agent = await createAgent(scope, "my-agent");
|
|
29
|
-
* //
|
|
51
|
+
* // 这一段会话临时换个模型(不动 Agent 定义):模型与参数都取会话级那一份
|
|
52
|
+
* const scoped = await createAgent(scope, "my-agent", {
|
|
53
|
+
* modelId: "gpt-6-astra",
|
|
54
|
+
* modelParams: { reasoning_effort: "high" },
|
|
55
|
+
* });
|
|
30
56
|
* ```
|
|
31
57
|
*/
|
|
32
58
|
export declare function createAgent(scope: Scope, agentId: string, options?: CreateAgentOptions): Promise<SdkAgent>;
|
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
import { AgentRepository } from "../crud/AgentRepository.js";
|
|
2
2
|
import { SdkAgent } from "./SdkAgent.js";
|
|
3
3
|
import { createModel } from "./createModel.js";
|
|
4
|
+
import { resolveModel, resolveModelParams } from "./resolveModel.js";
|
|
4
5
|
/**
|
|
5
6
|
* 从磁盘创建 Agent。
|
|
6
7
|
*
|
|
7
8
|
* 通过 Scope 获取已发现的能力,读取 Agent 定义,过滤并实例化工具,产出 SdkAgent。
|
|
9
|
+
* 模型按 **会话级覆盖 > Agent 定义 > 全局兜底** 解析(唯一实现:`resolveModel`);
|
|
10
|
+
* **参数取「模型来自哪一级」那一份**、绝不跨级混合(同一处实现:`resolveModelParams`)。
|
|
8
11
|
*
|
|
9
12
|
* ```ts
|
|
10
13
|
* const agent = await createAgent(scope, "my-agent");
|
|
11
|
-
* //
|
|
14
|
+
* // 这一段会话临时换个模型(不动 Agent 定义):模型与参数都取会话级那一份
|
|
15
|
+
* const scoped = await createAgent(scope, "my-agent", {
|
|
16
|
+
* modelId: "gpt-6-astra",
|
|
17
|
+
* modelParams: { reasoning_effort: "high" },
|
|
18
|
+
* });
|
|
12
19
|
* ```
|
|
13
20
|
*/
|
|
14
21
|
export async function createAgent(scope, agentId, options = {}) {
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
22
|
+
const stored = await new AgentRepository(scope.agentsDir).read(agentId);
|
|
23
|
+
if (!stored)
|
|
17
24
|
throw new Error(`Agent "${agentId}" not found`);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
const resolved = resolveModel({
|
|
26
|
+
sessionModelId: options.modelId,
|
|
27
|
+
agentModelId: stored.modelId,
|
|
28
|
+
defaultModel: scope.config?.defaultModel,
|
|
29
|
+
});
|
|
30
|
+
// 三级都没有就是**真的没有模型**:不静默挑一个出厂模型顶上 —— 用户会以为自己在用
|
|
31
|
+
// 配置里那个,实际请求(和账单)落在别的模型上。带上 agentId 是因为同一条错误在
|
|
32
|
+
// 服务端日志里必须能指出是哪份定义没绑。
|
|
33
|
+
if (!resolved) {
|
|
34
|
+
throw new Error(`Agent "${agentId}" has no model bound: no session override, no "modelId" in its definition, ` +
|
|
35
|
+
`and no "defaultModel" in the config`);
|
|
21
36
|
}
|
|
22
|
-
|
|
37
|
+
// 生效的模型写进**这一份**(内存里的)定义:运行期所有读 `definition.modelId` 的地方
|
|
38
|
+
// —— 状态栏快照、上下文阈值(`tokenThresholds`)、插件 —— 必须看到同一个模型,否则
|
|
39
|
+
// 就又回到「界面写着 A、请求发给 B」。磁盘上的定义一个字都不动:会话级覆盖只属于这一段
|
|
40
|
+
// 会话,落盘走的是会话存档的 `modelId`(见服务端 `SessionManager.recordOf`)。
|
|
41
|
+
const definition = { ...stored, modelId: resolved.modelId };
|
|
42
|
+
// 参数跟着「模型来自哪一级」走:档位是上面那次解析的产物,这里只按它取那一份
|
|
43
|
+
// (规则只有一处实现,见 `resolveModelParams`)。会话级没设参数、或模型来自全局兜底时
|
|
44
|
+
// 拿到的是 `undefined` —— 那就一个字段都不覆盖,让模型走自己的 `defaultParams`。
|
|
45
|
+
const params = resolveModelParams({
|
|
46
|
+
level: resolved.level,
|
|
47
|
+
sessionModelParams: options.modelParams,
|
|
48
|
+
agentModelParams: definition.modelParams,
|
|
49
|
+
});
|
|
50
|
+
const { client, model, modelConfig } = createModel(scope, resolved.modelId, params);
|
|
23
51
|
const tools = scope.buildTools(definition, {
|
|
24
52
|
exclude: {
|
|
25
53
|
subagents: definition.function?.name ? [definition.function.name] : undefined,
|
|
@@ -31,6 +59,8 @@ export async function createAgent(scope, agentId, options = {}) {
|
|
|
31
59
|
client,
|
|
32
60
|
model,
|
|
33
61
|
modelConfig,
|
|
62
|
+
// 合出来的是哪一级,客户端要把「当前生效档」标在选择器上
|
|
63
|
+
modelLevel: resolved.level,
|
|
34
64
|
// 在 createAgent 层做模板快照(拷贝),隔离 definition.messages 的引用。
|
|
35
65
|
// AgentContext.messages 是 mutable 运行时数组,若直接把 definition.messages
|
|
36
66
|
// 传入,对话期间 append() 会反向污染 Agent 定义模板——definition.messages
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
2
|
import type { Scope } from "../scope/Scope.js";
|
|
3
|
-
import type { ModelParams } from "../types/index.js";
|
|
3
|
+
import type { AppConfig, ModelParams } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Agent 模型装配结果:openai SDK client + 模型名 + 模型参数。
|
|
6
6
|
* Agent 构造时直接消费此结构。
|
|
@@ -21,5 +21,17 @@ export interface AgentModel {
|
|
|
21
21
|
*
|
|
22
22
|
* `overrides` 是 **Agent 级参数覆盖**(`AgentDefinition.modelParams`):
|
|
23
23
|
* 同一个模型可以给不同 Agent 配不同参数,而模型自身的 `defaultParams` 保持不变。
|
|
24
|
+
*
|
|
25
|
+
* 本体在 {@link createModelFromConfig}:有的调用方(服务端的辅助小请求,如会话自动标题)
|
|
26
|
+
* **只拿到配置、没有 Scope**,而建一个 Scope 会连带拉起 MCP 连接 —— 为了发一次几十 token
|
|
27
|
+
* 的请求去起一套能力发现,代价与收益完全不成比例。两条路共用同一份「模型 → 端点 → client」
|
|
28
|
+
* 解析,否则「Agent 用的端点」与「辅助请求用的端点」迟早是两份会漂的事实。
|
|
24
29
|
*/
|
|
25
30
|
export declare function createModel(scope: Scope, modelId: string, overrides?: ModelParams): AgentModel;
|
|
31
|
+
/**
|
|
32
|
+
* 从**配置本身**装配模型(不需要 Scope)。
|
|
33
|
+
*
|
|
34
|
+
* 只在「不经过 Agent 的一次性小请求」里用;Agent 一律走 {@link createModel}(它多一层
|
|
35
|
+
* `scope.config` 的取法,两者最终落到这里)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function createModelFromConfig(config: AppConfig, modelId: string, overrides?: ModelParams): AgentModel;
|
|
@@ -21,9 +21,22 @@ function mergeParams(base, overrides) {
|
|
|
21
21
|
*
|
|
22
22
|
* `overrides` 是 **Agent 级参数覆盖**(`AgentDefinition.modelParams`):
|
|
23
23
|
* 同一个模型可以给不同 Agent 配不同参数,而模型自身的 `defaultParams` 保持不变。
|
|
24
|
+
*
|
|
25
|
+
* 本体在 {@link createModelFromConfig}:有的调用方(服务端的辅助小请求,如会话自动标题)
|
|
26
|
+
* **只拿到配置、没有 Scope**,而建一个 Scope 会连带拉起 MCP 连接 —— 为了发一次几十 token
|
|
27
|
+
* 的请求去起一套能力发现,代价与收益完全不成比例。两条路共用同一份「模型 → 端点 → client」
|
|
28
|
+
* 解析,否则「Agent 用的端点」与「辅助请求用的端点」迟早是两份会漂的事实。
|
|
24
29
|
*/
|
|
25
30
|
export function createModel(scope, modelId, overrides) {
|
|
26
|
-
|
|
31
|
+
return createModelFromConfig(scope.config, modelId, overrides);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 从**配置本身**装配模型(不需要 Scope)。
|
|
35
|
+
*
|
|
36
|
+
* 只在「不经过 Agent 的一次性小请求」里用;Agent 一律走 {@link createModel}(它多一层
|
|
37
|
+
* `scope.config` 的取法,两者最终落到这里)。
|
|
38
|
+
*/
|
|
39
|
+
export function createModelFromConfig(config, modelId, overrides) {
|
|
27
40
|
const modelConfig = config.models.find((m) => m.id === modelId);
|
|
28
41
|
if (!modelConfig)
|
|
29
42
|
throw new Error(`Model "${modelId}" not found`);
|