@ai-zen/agents-sdk 0.9.1 → 0.9.3
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.3] - 2026-09-01
|
|
4
|
+
|
|
5
|
+
### 🔧 Fixed
|
|
6
|
+
|
|
7
|
+
- **`createAgent` 不再污染 Agent 定义模板(`definition.messages` 引用隔离)** — 创建 Agent 时对 `definition.messages` 做模板快照(`[...(definition.messages ?? [])]`)而非直接引用。此前把定义数组直接传给 `AgentContext.messages`(mutable 运行时数组),对话期间 `append()` 会反向把完整对话历史写入 `definition.messages`,导致:
|
|
8
|
+
- 任务迁移 `prune` 分支展开的是被污染的"完整历史"而非模板 → 旧消息既未被物理删除、也未被标记 `omit`,却能看到新注入的断点消息;
|
|
9
|
+
- `omit` 分支的 `preserveCount` 因 `definition.messages` 与 `agent.messages` 指向同一数组而等于全长 → 历史消息无法被标记 `omit`;
|
|
10
|
+
- `/new` 基于被污染的模板拷贝,新对话会继承旧历史。
|
|
11
|
+
- 顺带修复 Agent 定义缺少 `messages` 字段(`undefined`)时创建 Agent 的崩溃问题(`?? []` 兜底)。
|
|
12
|
+
|
|
13
|
+
### ✅ Tests
|
|
14
|
+
|
|
15
|
+
- `createAgent.test.ts` 新增:`append` 不污染 `definition.messages`(引用隔离);Agent 定义缺少 `messages` 字段时正常创建
|
|
16
|
+
|
|
17
|
+
## [0.9.2] - 2026-08-31
|
|
18
|
+
|
|
19
|
+
### 🎯 Optimized
|
|
20
|
+
|
|
21
|
+
- **默认 Agent 提示词重构(`DEFAULT_AGENT_DEFINITION`)** — 精简并统一风格:
|
|
22
|
+
- 人格设定调整为"幽默风趣、严谨可靠"
|
|
23
|
+
- 原有 8 条原则压缩为一条核心规则:遇到任何不明确、不确定、有矛盾或可能影响结果的状况,立即停下并直接询问用户,而不是自行脑补、猜测或硬干
|
|
24
|
+
- 新增"惜字如金"原则:只交代结果与必要说明,执行过程(工具调用、读写、搜索等)用户均已可见,不必再复述,以节省 token
|
|
25
|
+
- 保留护栏:主动调用工具、如实汇报、并只在你被指定的工作范围内行事
|
|
26
|
+
- 注入"当前操作系统"信息,动态使用 `process.platform`,适配不同平台
|
|
27
|
+
- **`ViewImageTool` 增加本地 URL 校验** — 新增 `isLocalUrl()`,拒绝 `file://` 协议及指向本机回环地址(`localhost`/`127.0.0.1`/`[::1]`/`0.0.0.0`)的 http(s) URL(API 服务商无法下载访问),在调用早期直接报错;`function.description` 与 `path_or_url` 参数说明同步补充"不支持本地 URL,本地图片请使用文件路径"
|
|
28
|
+
|
|
3
29
|
## [0.9.1] - 2026-08-28
|
|
4
30
|
|
|
5
31
|
### 🔧 Fixed
|
|
@@ -3,6 +3,16 @@ import { promises as fs } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
|
|
5
5
|
const SUPPORTED_EXT = [".jpg", ".jpeg", ".png", ".gif", ".webp"];
|
|
6
|
+
/**
|
|
7
|
+
* 是否为"本地 URL"——指向本地/回环地址,API 服务商无法下载访问。
|
|
8
|
+
* 覆盖 file:// 等本地协议,以及指向本机的 http(s) 地址(localhost、127.0.0.1、[::1]、0.0.0.0)。
|
|
9
|
+
*/
|
|
10
|
+
function isLocalUrl(value) {
|
|
11
|
+
if (/^file:\/\//i.test(value))
|
|
12
|
+
return true;
|
|
13
|
+
const m = value.match(/^https?:\/\/([^/?#]+)/i);
|
|
14
|
+
return !!m && /^(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)$/i.test(m[1]);
|
|
15
|
+
}
|
|
6
16
|
/**
|
|
7
17
|
* 查看图片工具 — 让 Agent 主动查看/分析一张图片。**仅对视觉模型可用**:
|
|
8
18
|
* 由 `isAvailable(config, definition)` 声明(从 definition.modelId 解析模型,检查 Model.vision),
|
|
@@ -24,13 +34,13 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
24
34
|
}
|
|
25
35
|
function = {
|
|
26
36
|
name: "viewImage",
|
|
27
|
-
description: "查看一张图片并分析其内容。传入本地图片路径或 http(s) 图片 URL。本地图片会自动上传(Files API
|
|
37
|
+
description: "查看一张图片并分析其内容。传入本地图片路径或 http(s) 图片 URL。本地图片会自动上传(Files API)后引用,网络图片直接引用。不支持本地 URL(如 file:// 协议、指向本机 localhost/127.0.0.1 的 http(s) 地址),本地图片请使用文件路径。适合识别图片文字、描述图片内容、分析图表等。",
|
|
28
38
|
parameters: {
|
|
29
39
|
type: "object",
|
|
30
40
|
properties: {
|
|
31
41
|
path_or_url: {
|
|
32
42
|
type: "string",
|
|
33
|
-
description: "本地图片路径(相对/绝对)或 http(s) 图片 URL。支持的格式:JPEG、PNG、GIF、WebP
|
|
43
|
+
description: "本地图片路径(相对/绝对)或 http(s) 图片 URL。支持的格式:JPEG、PNG、GIF、WebP。不支持本地 URL(如 file:// 协议、指向本机 localhost/127.0.0.1 的 http(s) 地址),本地图片请使用文件路径。",
|
|
34
44
|
},
|
|
35
45
|
},
|
|
36
46
|
required: ["path_or_url"],
|
|
@@ -47,6 +57,10 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
47
57
|
return "viewImage 需要提供 path_or_url 参数(本地图片路径或 http(s) URL)。";
|
|
48
58
|
}
|
|
49
59
|
const value = target.trim();
|
|
60
|
+
// 拒绝服务商无法访问的"本地 URL":file:// 等本地协议,或指向本机回环地址(localhost/127.0.0.1/[::1]/0.0.0.0)的 http(s) 地址
|
|
61
|
+
if (isLocalUrl(value)) {
|
|
62
|
+
return "不支持本地 URL(API 服务商无法下载访问)。本地图片请使用文件路径,而不是本地链接。";
|
|
63
|
+
}
|
|
50
64
|
try {
|
|
51
65
|
// 网络图片:直接返回 image_url 内容块(无需上传)
|
|
52
66
|
if (/^https?:\/\//i.test(value)) {
|
package/dist/config/constants.js
CHANGED
|
@@ -10,14 +10,9 @@ export const DEFAULT_AGENT_DEFINITION = {
|
|
|
10
10
|
name: "默认助手",
|
|
11
11
|
description: "默认的 AI 助手,适用于日常问答和任务执行。",
|
|
12
12
|
messages: [
|
|
13
|
-
Message.System(
|
|
13
|
+
Message.System(`你是一个幽默风趣、严谨可靠的智能助手,请用中文回复。当前操作系统:${process.platform}。
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- 实事求是 — 知之为知之,不知为不知,而不是凭空编造;如果用户意图不明确,应先提问澄清,而不是自行脑补
|
|
17
|
-
- 一切行动听指挥 — 严格遵循用户指令,而不是自作主张
|
|
18
|
-
- 安全第一 — 风险操作先告知确认,而不是盲目执行
|
|
19
|
-
- 能打胜仗 — 写优秀的代码,而不是只限于能用的代码
|
|
20
|
-
- 有矛盾就问 — 如果用户指令中存在自相矛盾之处,应指出矛盾并请求澄清,而不是自行取舍`),
|
|
15
|
+
惜字如金:只交代结果和必要说明,执行过程(工具调用、读写、搜索等)用户均已可见,不必再复述。遇到任何不明确、不确定、有矛盾或可能影响结果的状况,立即停下并直接询问用户,而不是自行脑补、猜测或硬干。除此之外,主动调用工具、如实汇报,并只在你被指定的工作范围内行事。`),
|
|
21
16
|
],
|
|
22
17
|
permissions: {
|
|
23
18
|
tools: { allow: ["*"] },
|
|
@@ -32,7 +32,12 @@ export async function createAgent(provider, agentId) {
|
|
|
32
32
|
client,
|
|
33
33
|
model,
|
|
34
34
|
modelConfig,
|
|
35
|
-
|
|
35
|
+
// 在 createAgent 层做模板快照(拷贝),隔离 definition.messages 的引用。
|
|
36
|
+
// AgentContext.messages 是 mutable 运行时数组,若直接把 definition.messages
|
|
37
|
+
// 传入,对话期间 append() 会反向污染 Agent 定义模板——definition.messages
|
|
38
|
+
// 被塞入完整历史后,迁移 prune/omit 失效、/new 继承旧历史。
|
|
39
|
+
// 快照后,运行时改动只作用于会话副本,模板保持纯净。
|
|
40
|
+
messages: [...(definition.messages ?? [])],
|
|
36
41
|
tools,
|
|
37
42
|
});
|
|
38
43
|
return agent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-zen/agents-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "AI-Zen Agents SDK — shared business logic for CLI and Desktop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"author": "LZQCN",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@ai-zen/agents-core": "^4.1.0",
|
|
19
20
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
20
21
|
"dayjs": "^1.11.21",
|
|
21
|
-
"openai": "^7.5.0"
|
|
22
|
-
"@ai-zen/agents-core": "^4.1.0"
|
|
22
|
+
"openai": "^7.5.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^24.12.2",
|