create-deepagent-server 0.1.0 → 0.2.0
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 +82 -8
- package/package.json +1 -1
- package/src/args.js +6 -4
- package/src/cli.js +1 -1
- package/src/dependencies.js +1 -1
- package/src/prompts.js +1 -0
- package/src/registry.js +8 -8
- package/src/scaffold.js +6 -7
- package/src/setup.js +2 -0
- package/src/version.js +1 -1
- package/src/versions.js +1 -1
- package/templates/deepagent/js/scripts/check.js +34 -11
- package/templates/deepagent/js/scripts/dev.js +9 -0
- package/templates/deepagent/js/src/agents/factory.js +2 -1
- package/templates/deepagent/js/src/agents/prompts/loader.js +9 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.js +4 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.md +1 -2
- package/templates/deepagent/js/src/agents/state/types.js +1 -0
- package/templates/deepagent/js/src/agents/subagents/analyst.js +4 -3
- package/templates/deepagent/js/src/agents/subagents/coder.js +1 -0
- package/templates/deepagent/js/src/agents/subagents/index.js +5 -4
- package/templates/deepagent/js/src/agents/supervisor.js +12 -4
- package/templates/deepagent/js/src/api/app.js +7 -0
- package/templates/deepagent/js/src/api/middleware/auth.js +9 -0
- package/templates/deepagent/js/src/api/middleware/error.js +4 -0
- package/templates/deepagent/js/src/api/routes/agent.js +19 -49
- package/templates/deepagent/js/src/api/routes/health.js +12 -3
- package/templates/deepagent/js/src/api/routes/session.js +28 -48
- package/templates/deepagent/js/src/app.js +31 -12
- package/templates/deepagent/js/src/backends/composite.js +2 -0
- package/templates/deepagent/js/src/backends/filesystem.js +1 -0
- package/templates/deepagent/js/src/backends/index.js +35 -3
- package/templates/deepagent/js/src/backends/sandbox.js +3 -0
- package/templates/deepagent/js/src/config/agent.js +1 -0
- package/templates/deepagent/js/src/config/database.js +19 -0
- package/templates/deepagent/js/src/config/env.js +46 -23
- package/templates/deepagent/js/src/config/index.js +13 -3
- package/templates/deepagent/js/src/graph/checkpointer.js +10 -2
- package/templates/deepagent/js/src/graph/compile.js +1 -0
- package/templates/deepagent/js/src/graph/store.js +10 -2
- package/templates/deepagent/js/src/index.js +9 -2
- package/templates/deepagent/js/src/memory/index.js +2 -0
- package/templates/deepagent/js/src/memory/manager.js +21 -10
- package/templates/deepagent/js/src/memory/store.js +7 -0
- package/templates/deepagent/js/src/middleware/approval.js +6 -1
- package/templates/deepagent/js/src/middleware/context.js +5 -0
- package/templates/deepagent/js/src/middleware/logging.js +47 -43
- package/templates/deepagent/js/src/middleware/security.js +7 -0
- package/templates/deepagent/js/src/model/config.js +38 -0
- package/templates/deepagent/js/src/model/index.js +9 -0
- package/templates/deepagent/js/src/model/openai-compatible.js +18 -0
- package/templates/deepagent/js/src/model/presets.js +71 -0
- package/templates/deepagent/js/src/sandbox/config.js +12 -0
- package/templates/deepagent/js/src/sandbox/index.js +3 -0
- package/templates/deepagent/js/src/sandbox/manager.js +161 -0
- package/templates/deepagent/js/src/sandbox/opensandbox.js +195 -0
- package/templates/deepagent/js/src/schemas/agent.js +7 -0
- package/templates/deepagent/js/src/schemas/common.js +5 -0
- package/templates/deepagent/js/src/schemas/locale.js +1 -0
- package/templates/deepagent/js/src/schemas/session.js +4 -0
- package/templates/deepagent/js/src/services/{agent.service.js → agent.js} +39 -20
- package/templates/deepagent/js/src/services/{memory.service.js → memory.js} +13 -7
- package/templates/deepagent/js/src/services/{session.service.js → session.js} +43 -17
- package/templates/deepagent/js/src/skills/index.js +4 -0
- package/templates/deepagent/js/src/skills/loader.js +20 -10
- package/templates/deepagent/js/src/storage/database/client.js +57 -0
- package/templates/deepagent/{ts/src/infrastructure → js/src/storage}/database/migrations/001_init.sql +1 -1
- package/templates/deepagent/js/src/{infrastructure → storage}/logger/index.js +2 -0
- package/templates/deepagent/js/src/{infrastructure → storage}/redis/client.js +25 -19
- package/templates/deepagent/js/src/{infrastructure → storage}/shutdown/index.js +20 -13
- package/templates/deepagent/js/src/tools/database/index.js +1 -1
- package/templates/deepagent/js/src/tools/database/query.js +44 -32
- package/templates/deepagent/js/src/tools/filesystem/index.js +16 -0
- package/templates/deepagent/js/src/tools/index.js +6 -11
- package/templates/deepagent/js/src/tools/mcp/client.js +7 -0
- package/templates/deepagent/js/src/tools/mcp/connections.js +13 -3
- package/templates/deepagent/js/src/tools/mcp/index.js +2 -0
- package/templates/deepagent/js/src/tools/mcp/registry.js +15 -11
- package/templates/deepagent/js/src/utils/errors.js +9 -0
- package/templates/deepagent/js/src/utils/helpers.js +15 -0
- package/templates/deepagent/js/src/utils/validation.js +15 -0
- package/templates/deepagent/js/tests/agents/prompts.test.js +9 -3
- package/templates/deepagent/js/tests/agents/supervisor.test.js +13 -5
- package/templates/deepagent/js/tests/config/database.test.js +40 -0
- package/templates/deepagent/js/tests/integration/api.test.js +18 -3
- package/templates/deepagent/js/tests/middleware/security.test.js +4 -1
- package/templates/deepagent/js/tests/model/config.test.js +61 -0
- package/templates/deepagent/js/tests/sandbox/config.test.js +46 -0
- package/templates/deepagent/js/tests/sandbox/manager.test.js +236 -0
- package/templates/deepagent/js/tests/sandbox/opensandbox.test.js +173 -0
- package/templates/deepagent/js/tests/services/session.test.js +41 -0
- package/templates/deepagent/js/tests/tools/query.test.js +5 -1
- package/templates/deepagent/shared/README.md +101 -14
- package/templates/deepagent/shared/_env.example +40 -10
- package/templates/deepagent/shared/deployment/docker-compose.yml +8 -4
- package/templates/deepagent/shared/resources/AGENTS.md +1 -1
- package/templates/deepagent/ts/scripts/check.ts +19 -11
- package/templates/deepagent/ts/scripts/copy-assets.ts +2 -0
- package/templates/deepagent/ts/src/agents/factory.ts +1 -1
- package/templates/deepagent/ts/src/agents/prompts/loader.ts +1 -0
- package/templates/deepagent/ts/src/agents/prompts/supervisor.md +1 -2
- package/templates/deepagent/ts/src/agents/prompts/supervisor.ts +1 -1
- package/templates/deepagent/ts/src/agents/subagents/analyst.ts +7 -3
- package/templates/deepagent/ts/src/agents/subagents/index.ts +4 -5
- package/templates/deepagent/ts/src/agents/supervisor.ts +11 -9
- package/templates/deepagent/ts/src/api/app.ts +4 -4
- package/templates/deepagent/ts/src/api/middleware/auth.ts +1 -0
- package/templates/deepagent/ts/src/api/middleware/error.ts +1 -1
- package/templates/deepagent/ts/src/api/routes/agent.ts +13 -58
- package/templates/deepagent/ts/src/api/routes/health.ts +5 -3
- package/templates/deepagent/ts/src/api/routes/session.ts +21 -51
- package/templates/deepagent/ts/src/app.ts +19 -12
- package/templates/deepagent/ts/src/backends/index.ts +41 -7
- package/templates/deepagent/ts/src/backends/sandbox.ts +1 -0
- package/templates/deepagent/ts/src/config/database.ts +21 -0
- package/templates/deepagent/ts/src/config/env.ts +32 -28
- package/templates/deepagent/ts/src/config/index.ts +12 -4
- package/templates/deepagent/ts/src/graph/checkpointer.ts +5 -2
- package/templates/deepagent/ts/src/graph/store.ts +5 -2
- package/templates/deepagent/ts/src/index.ts +2 -2
- package/templates/deepagent/ts/src/memory/manager.ts +12 -10
- package/templates/deepagent/ts/src/memory/store.ts +2 -0
- package/templates/deepagent/ts/src/middleware/approval.ts +2 -2
- package/templates/deepagent/ts/src/middleware/logging.ts +43 -44
- package/templates/deepagent/ts/src/middleware/security.ts +1 -0
- package/templates/deepagent/ts/src/model/config.ts +56 -0
- package/templates/deepagent/ts/src/model/index.ts +14 -0
- package/templates/deepagent/ts/src/model/openai-compatible.ts +21 -0
- package/templates/deepagent/ts/src/model/presets.ts +82 -0
- package/templates/deepagent/ts/src/sandbox/config.ts +30 -0
- package/templates/deepagent/ts/src/sandbox/index.ts +7 -0
- package/templates/deepagent/ts/src/sandbox/manager.ts +176 -0
- package/templates/deepagent/ts/src/sandbox/opensandbox.ts +216 -0
- package/templates/deepagent/ts/src/services/{agent.service.ts → agent.ts} +22 -22
- package/templates/deepagent/ts/src/services/{memory.service.ts → memory.ts} +7 -7
- package/templates/deepagent/ts/src/services/{session.service.ts → session.ts} +29 -19
- package/templates/deepagent/ts/src/skills/loader.ts +6 -10
- package/templates/deepagent/ts/src/storage/database/client.ts +65 -0
- package/templates/deepagent/{js/src/infrastructure → ts/src/storage}/database/migrations/001_init.sql +1 -1
- package/templates/deepagent/ts/src/{infrastructure → storage}/redis/client.ts +14 -21
- package/templates/deepagent/ts/src/{infrastructure → storage}/shutdown/index.ts +10 -13
- package/templates/deepagent/ts/src/tools/database/index.ts +5 -1
- package/templates/deepagent/ts/src/tools/database/query.ts +40 -32
- package/templates/deepagent/ts/src/tools/filesystem/index.ts +2 -0
- package/templates/deepagent/ts/src/tools/index.ts +10 -8
- package/templates/deepagent/ts/src/tools/mcp/client.ts +1 -0
- package/templates/deepagent/ts/src/tools/mcp/connections.ts +3 -3
- package/templates/deepagent/ts/src/tools/mcp/registry.ts +9 -12
- package/templates/deepagent/ts/src/utils/helpers.ts +5 -0
- package/templates/deepagent/ts/src/utils/validation.ts +17 -0
- package/templates/deepagent/ts/tests/agents/prompts.test.ts +3 -3
- package/templates/deepagent/ts/tests/agents/supervisor.test.ts +5 -5
- package/templates/deepagent/ts/tests/config/database.test.ts +40 -0
- package/templates/deepagent/ts/tests/integration/api.test.ts +5 -6
- package/templates/deepagent/ts/tests/middleware/security.test.ts +1 -1
- package/templates/deepagent/ts/tests/model/config.test.ts +61 -0
- package/templates/deepagent/ts/tests/sandbox/config.test.ts +46 -0
- package/templates/deepagent/ts/tests/sandbox/manager.test.ts +241 -0
- package/templates/deepagent/ts/tests/sandbox/opensandbox.test.ts +188 -0
- package/templates/deepagent/ts/tests/services/session.test.ts +45 -0
- package/templates/deepagent/ts/tests/tools/query.test.ts +1 -1
- package/templates/deepagent/js/src/agents/prompts/subagents/researcher.md +0 -16
- package/templates/deepagent/js/src/agents/subagents/researcher.js +0 -12
- package/templates/deepagent/js/src/config/model.js +0 -34
- package/templates/deepagent/js/src/infrastructure/database/client.js +0 -43
- package/templates/deepagent/js/src/tools/search/index.js +0 -1
- package/templates/deepagent/js/src/tools/search/web-search.js +0 -54
- package/templates/deepagent/shared/skills/research/SKILL.md +0 -31
- package/templates/deepagent/ts/src/agents/prompts/subagents/researcher.md +0 -16
- package/templates/deepagent/ts/src/agents/subagents/researcher.ts +0 -15
- package/templates/deepagent/ts/src/config/model.ts +0 -49
- package/templates/deepagent/ts/src/infrastructure/database/client.ts +0 -61
- package/templates/deepagent/ts/src/tools/search/index.ts +0 -1
- package/templates/deepagent/ts/src/tools/search/web-search.ts +0 -82
- /package/templates/deepagent/ts/src/{infrastructure → storage}/logger/index.ts +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { resolveDatabaseUrl } from "../../src/config/database.js";
|
|
5
|
+
import { loadEnv } from "../../src/config/env.js";
|
|
6
|
+
|
|
7
|
+
const envFor = (source: Record<string, string>) => {
|
|
8
|
+
return loadEnv({ NODE_ENV: "test", ...source }, { requireModelCredentials: false });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
test("内存模式不生成数据库连接串", () => {
|
|
12
|
+
assert.equal(resolveDatabaseUrl(envFor({ POSTGRES_HOST: "db.internal" })), undefined);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("postgres 模式用 POSTGRES_* 分项拼装连接串", () => {
|
|
16
|
+
const url = resolveDatabaseUrl(
|
|
17
|
+
envFor({
|
|
18
|
+
CHECKPOINTER: "postgres",
|
|
19
|
+
POSTGRES_HOST: "db.internal",
|
|
20
|
+
POSTGRES_PORT: "6543",
|
|
21
|
+
POSTGRES_USERNAME: "agent user",
|
|
22
|
+
POSTGRES_PASSWORD: "p@ss:word",
|
|
23
|
+
POSTGRES_DATABASE: "agent_db",
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
assert.equal(url, "postgresql://agent%20user:p%40ss%3Aword@db.internal:6543/agent_db");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("DATABASE_URL 优先于分项配置", () => {
|
|
31
|
+
const url = resolveDatabaseUrl(
|
|
32
|
+
envFor({
|
|
33
|
+
DATABASE_URL: "postgresql://custom:secret@example.com:5432/app",
|
|
34
|
+
CHECKPOINTER: "postgres",
|
|
35
|
+
POSTGRES_HOST: "ignored.internal",
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
assert.equal(url, "postgresql://custom:secret@example.com:5432/app");
|
|
40
|
+
});
|
|
@@ -5,12 +5,11 @@ import type { Server } from "node:http";
|
|
|
5
5
|
import test from "node:test";
|
|
6
6
|
|
|
7
7
|
import { createApiApp } from "../../src/api/app.js";
|
|
8
|
-
import { loadConfig } from "../../src/config/index.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type { SessionService } from "../../src/services/session.service.js";
|
|
8
|
+
import { loadConfig, loadEnv } from "../../src/config/index.js";
|
|
9
|
+
import { createLogger } from "../../src/storage/logger/index.js";
|
|
10
|
+
import type { AgentService } from "../../src/services/agent.js";
|
|
11
|
+
import type { MemoryService } from "../../src/services/memory.js";
|
|
12
|
+
import type { SessionService } from "../../src/services/session.js";
|
|
14
13
|
|
|
15
14
|
const config = loadConfig({
|
|
16
15
|
env: loadEnv({ NODE_ENV: "test", LOG_LEVEL: "silent" }, { requireModelCredentials: false }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
|
-
import { findSecurityViolation } from "../../src/middleware/
|
|
4
|
+
import { findSecurityViolation } from "../../src/middleware/index.js";
|
|
5
5
|
|
|
6
6
|
test("拦截破坏性 shell 命令", () => {
|
|
7
7
|
for (const command of [
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { loadEnv } from "../../src/config/index.js";
|
|
5
|
+
import { resolveModelConfig } from "../../src/model/index.js";
|
|
6
|
+
|
|
7
|
+
const envFor = (source: Record<string, string>) => {
|
|
8
|
+
return loadEnv({ NODE_ENV: "test", ...source }, { requireModelCredentials: false });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
test("默认使用 MiniMax M3(OpenAI 兼容协议)", () => {
|
|
12
|
+
const config = resolveModelConfig(envFor({}));
|
|
13
|
+
|
|
14
|
+
assert.equal(config.provider, "minimax");
|
|
15
|
+
assert.equal(config.label, "MiniMax");
|
|
16
|
+
assert.equal(config.name, "MiniMax-M3");
|
|
17
|
+
assert.equal(config.baseUrl, "https://api.minimaxi.com/v1");
|
|
18
|
+
assert.equal(config.maxCompletionTokens, 32768);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("预设切换服务商,并允许用 MODEL_* 覆盖", () => {
|
|
22
|
+
const config = resolveModelConfig(
|
|
23
|
+
envFor({
|
|
24
|
+
MODEL_PROVIDER: "deepseek",
|
|
25
|
+
MODEL_NAME: "deepseek-reasoner",
|
|
26
|
+
MODEL_BASE_URL: "https://gateway.internal/v1",
|
|
27
|
+
MODEL_API_KEY: "sk-test",
|
|
28
|
+
MODEL_TEMPERATURE: "0.5",
|
|
29
|
+
MODEL_MAX_COMPLETION_TOKENS: "1024",
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
assert.equal(config.provider, "deepseek");
|
|
34
|
+
assert.equal(config.name, "deepseek-reasoner");
|
|
35
|
+
assert.equal(config.baseUrl, "https://gateway.internal/v1");
|
|
36
|
+
assert.equal(config.apiKey, "sk-test");
|
|
37
|
+
assert.equal(config.temperature, 0.5);
|
|
38
|
+
assert.equal(config.maxCompletionTokens, 1024);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("旧变量 MODEL_MAX_TOKENS 仍然兼容,新变量优先", () => {
|
|
42
|
+
assert.equal(resolveModelConfig(envFor({ MODEL_MAX_TOKENS: "2048" })).maxCompletionTokens, 2048);
|
|
43
|
+
|
|
44
|
+
const config = resolveModelConfig(
|
|
45
|
+
envFor({ MODEL_MAX_COMPLETION_TOKENS: "8192", MODEL_MAX_TOKENS: "2048" }),
|
|
46
|
+
);
|
|
47
|
+
assert.equal(config.maxCompletionTokens, 8192);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("MiniMax 预设使用国内 OpenAI 兼容地址", () => {
|
|
51
|
+
const config = resolveModelConfig(envFor({ MODEL_PROVIDER: "minimax" }));
|
|
52
|
+
|
|
53
|
+
assert.equal(config.label, "MiniMax");
|
|
54
|
+
assert.equal(config.name, "MiniMax-M3");
|
|
55
|
+
assert.equal(config.baseUrl, "https://api.minimaxi.com/v1");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("缺少地址或模型名时给出明确的配置错误", () => {
|
|
59
|
+
assert.throws(() => resolveModelConfig(envFor({ MODEL_PROVIDER: "custom" })), /MODEL_BASE_URL/);
|
|
60
|
+
assert.throws(() => resolveModelConfig(envFor({ MODEL_PROVIDER: "vllm" })), /MODEL_NAME/);
|
|
61
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { loadEnv } from "../../src/config/index.js";
|
|
5
|
+
import { resolveSandboxConfig } from "../../src/sandbox/config.js";
|
|
6
|
+
|
|
7
|
+
const envFor = (source: Record<string, string>) => {
|
|
8
|
+
return loadEnv({ NODE_ENV: "test", ...source }, { requireModelCredentials: false });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
test("默认不启用沙箱", () => {
|
|
12
|
+
const config = resolveSandboxConfig(envFor({}));
|
|
13
|
+
|
|
14
|
+
assert.equal(config.enabled, false);
|
|
15
|
+
assert.equal(config.domain, "localhost:8080");
|
|
16
|
+
assert.equal(config.protocol, "http");
|
|
17
|
+
assert.equal(config.image, "python:3.12");
|
|
18
|
+
assert.equal(config.timeoutSeconds, 1800);
|
|
19
|
+
assert.equal(config.workspaceRoot, "/workspace");
|
|
20
|
+
assert.equal(config.apiKey, undefined);
|
|
21
|
+
assert.equal(config.sandboxId, undefined);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("启用沙箱时解析 OpenSandbox 配置", () => {
|
|
25
|
+
const config = resolveSandboxConfig(
|
|
26
|
+
envFor({
|
|
27
|
+
SANDBOX_ENABLED: "true",
|
|
28
|
+
OPEN_SANDBOX_DOMAIN: "sandbox.example.com",
|
|
29
|
+
OPEN_SANDBOX_PROTOCOL: "https",
|
|
30
|
+
OPEN_SANDBOX_API_KEY: "sk-test",
|
|
31
|
+
OPEN_SANDBOX_ID: "sbx-existing",
|
|
32
|
+
SANDBOX_IMAGE: "node:22",
|
|
33
|
+
SANDBOX_TIMEOUT_SECONDS: "600",
|
|
34
|
+
SANDBOX_WORKSPACE_ROOT: "/home/agent",
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
assert.equal(config.enabled, true);
|
|
39
|
+
assert.equal(config.domain, "sandbox.example.com");
|
|
40
|
+
assert.equal(config.protocol, "https");
|
|
41
|
+
assert.equal(config.apiKey, "sk-test");
|
|
42
|
+
assert.equal(config.sandboxId, "sbx-existing");
|
|
43
|
+
assert.equal(config.image, "node:22");
|
|
44
|
+
assert.equal(config.timeoutSeconds, 600);
|
|
45
|
+
assert.equal(config.workspaceRoot, "/home/agent");
|
|
46
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import type { SandboxConfig } from "../../src/sandbox/config.js";
|
|
5
|
+
import {
|
|
6
|
+
SandboxManager,
|
|
7
|
+
threadIdFromRuntime,
|
|
8
|
+
type OpenSandboxBackend,
|
|
9
|
+
} from "../../src/sandbox/index.js";
|
|
10
|
+
|
|
11
|
+
const sandboxConfig = (overrides: Partial<SandboxConfig> = {}): SandboxConfig => ({
|
|
12
|
+
enabled: true,
|
|
13
|
+
domain: "localhost:8080",
|
|
14
|
+
protocol: "http",
|
|
15
|
+
image: "python:3.12",
|
|
16
|
+
workspaceRoot: "/workspace",
|
|
17
|
+
...overrides,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const createFactory = () => {
|
|
21
|
+
const created: string[] = [];
|
|
22
|
+
const destroyed: string[] = [];
|
|
23
|
+
const renewed: number[] = [];
|
|
24
|
+
let count = 0;
|
|
25
|
+
|
|
26
|
+
const create = async (): Promise<OpenSandboxBackend> => {
|
|
27
|
+
count += 1;
|
|
28
|
+
const id = `sbx-${count}`;
|
|
29
|
+
created.push(id);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
renew: async (timeoutSeconds: number) => {
|
|
34
|
+
renewed.push(timeoutSeconds);
|
|
35
|
+
},
|
|
36
|
+
destroy: async () => {
|
|
37
|
+
destroyed.push(id);
|
|
38
|
+
},
|
|
39
|
+
} as unknown as OpenSandboxBackend;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return { create, created, destroyed, renewed };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
test("同一会话复用同一个沙箱", async () => {
|
|
46
|
+
const factory = createFactory();
|
|
47
|
+
const manager = new SandboxManager(sandboxConfig(), { create: factory.create });
|
|
48
|
+
|
|
49
|
+
const first = await manager.get("thread-a");
|
|
50
|
+
const second = await manager.get("thread-a");
|
|
51
|
+
|
|
52
|
+
assert.equal(first, second);
|
|
53
|
+
assert.deepEqual(factory.created, ["sbx-1"]);
|
|
54
|
+
assert.equal(manager.size, 1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("不同会话使用不同的沙箱", async () => {
|
|
58
|
+
const factory = createFactory();
|
|
59
|
+
const manager = new SandboxManager(sandboxConfig(), { create: factory.create });
|
|
60
|
+
|
|
61
|
+
const first = await manager.get("thread-a");
|
|
62
|
+
const second = await manager.get("thread-b");
|
|
63
|
+
|
|
64
|
+
assert.notEqual(first, second);
|
|
65
|
+
assert.deepEqual(factory.created, ["sbx-1", "sbx-2"]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("释放会话后再次使用时创建新沙箱", async () => {
|
|
69
|
+
const factory = createFactory();
|
|
70
|
+
const manager = new SandboxManager(sandboxConfig(), { create: factory.create });
|
|
71
|
+
|
|
72
|
+
await manager.get("thread-a");
|
|
73
|
+
await manager.release("thread-a");
|
|
74
|
+
|
|
75
|
+
assert.deepEqual(factory.destroyed, ["sbx-1"]);
|
|
76
|
+
assert.equal(manager.size, 0);
|
|
77
|
+
|
|
78
|
+
const next = await manager.get("thread-a");
|
|
79
|
+
assert.equal(next.id, "sbx-2");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("closeAll 销毁所有会话的沙箱", async () => {
|
|
83
|
+
const factory = createFactory();
|
|
84
|
+
const manager = new SandboxManager(sandboxConfig(), { create: factory.create });
|
|
85
|
+
|
|
86
|
+
await manager.get("thread-a");
|
|
87
|
+
await manager.get("thread-b");
|
|
88
|
+
await manager.closeAll();
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(factory.destroyed.sort(), ["sbx-1", "sbx-2"]);
|
|
91
|
+
assert.equal(manager.size, 0);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("创建失败后清理缓存,下一次可重试", async () => {
|
|
95
|
+
const factory = createFactory();
|
|
96
|
+
let attempts = 0;
|
|
97
|
+
|
|
98
|
+
const create = async (): Promise<OpenSandboxBackend> => {
|
|
99
|
+
attempts += 1;
|
|
100
|
+
if (attempts === 1) throw new Error("sandbox server unavailable");
|
|
101
|
+
|
|
102
|
+
return factory.create();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const manager = new SandboxManager(sandboxConfig(), { create });
|
|
106
|
+
|
|
107
|
+
await assert.rejects(() => manager.get("thread-a"), /unavailable/);
|
|
108
|
+
assert.equal(manager.size, 0);
|
|
109
|
+
|
|
110
|
+
const backend = await manager.get("thread-a");
|
|
111
|
+
assert.equal(backend.id, "sbx-1");
|
|
112
|
+
assert.equal(attempts, 2);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("未配置 TTL 时不续期", async () => {
|
|
116
|
+
let now = 0;
|
|
117
|
+
const factory = createFactory();
|
|
118
|
+
const manager = new SandboxManager(sandboxConfig(), { create: factory.create, now: () => now });
|
|
119
|
+
|
|
120
|
+
await manager.get("thread-a");
|
|
121
|
+
now += 24 * 60 * 60 * 1_000;
|
|
122
|
+
await manager.get("thread-a");
|
|
123
|
+
|
|
124
|
+
assert.deepEqual(factory.renewed, []);
|
|
125
|
+
assert.equal(factory.created.length, 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("使用中按 TTL 的三分之一续期", async () => {
|
|
129
|
+
let now = 0;
|
|
130
|
+
const factory = createFactory();
|
|
131
|
+
const manager = new SandboxManager(sandboxConfig({ timeoutSeconds: 1800 }), {
|
|
132
|
+
create: factory.create,
|
|
133
|
+
now: () => now,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const first = await manager.get("thread-a");
|
|
137
|
+
|
|
138
|
+
assert.equal(await manager.get("thread-a"), first);
|
|
139
|
+
assert.deepEqual(factory.renewed, []);
|
|
140
|
+
|
|
141
|
+
now += 600_000;
|
|
142
|
+
assert.equal(await manager.get("thread-a"), first);
|
|
143
|
+
assert.deepEqual(factory.renewed, [1800]);
|
|
144
|
+
assert.equal(factory.created.length, 1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("续期发现沙箱已被回收时重建", async () => {
|
|
148
|
+
let now = 0;
|
|
149
|
+
let count = 0;
|
|
150
|
+
const destroyed: string[] = [];
|
|
151
|
+
|
|
152
|
+
const create = async (): Promise<OpenSandboxBackend> => {
|
|
153
|
+
count += 1;
|
|
154
|
+
const id = `sbx-${count}`;
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
id,
|
|
158
|
+
renew: async () => {
|
|
159
|
+
if (id === "sbx-1") throw new Error("sandbox not found");
|
|
160
|
+
},
|
|
161
|
+
destroy: async () => {
|
|
162
|
+
destroyed.push(id);
|
|
163
|
+
},
|
|
164
|
+
} as unknown as OpenSandboxBackend;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const manager = new SandboxManager(sandboxConfig({ timeoutSeconds: 1800 }), {
|
|
168
|
+
create,
|
|
169
|
+
now: () => now,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const first = await manager.get("thread-a");
|
|
173
|
+
|
|
174
|
+
now += 600_000;
|
|
175
|
+
const second = await manager.get("thread-a");
|
|
176
|
+
|
|
177
|
+
assert.notEqual(first, second);
|
|
178
|
+
assert.equal(second.id, "sbx-2");
|
|
179
|
+
assert.deepEqual(destroyed, ["sbx-1"]);
|
|
180
|
+
assert.equal(manager.size, 1);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("续期失败但沙箱仍在时继续复用", async () => {
|
|
184
|
+
let now = 0;
|
|
185
|
+
let renewals = 0;
|
|
186
|
+
let count = 0;
|
|
187
|
+
|
|
188
|
+
const create = async (): Promise<OpenSandboxBackend> => {
|
|
189
|
+
count += 1;
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
id: `sbx-${count}`,
|
|
193
|
+
renew: async () => {
|
|
194
|
+
renewals += 1;
|
|
195
|
+
throw new Error("upstream timeout");
|
|
196
|
+
},
|
|
197
|
+
destroy: async () => {},
|
|
198
|
+
} as unknown as OpenSandboxBackend;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const manager = new SandboxManager(sandboxConfig({ timeoutSeconds: 1800 }), {
|
|
202
|
+
create,
|
|
203
|
+
now: () => now,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const first = await manager.get("thread-a");
|
|
207
|
+
|
|
208
|
+
now += 600_000;
|
|
209
|
+
assert.equal(await manager.get("thread-a"), first);
|
|
210
|
+
assert.equal(renewals, 1);
|
|
211
|
+
assert.equal(count, 1);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("设置 OPEN_SANDBOX_ID 时所有会话共享同一个沙箱", async () => {
|
|
215
|
+
const factory = createFactory();
|
|
216
|
+
const manager = new SandboxManager(sandboxConfig({ sandboxId: "sbx-existing" }), {
|
|
217
|
+
create: factory.create,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const first = await manager.get("thread-a");
|
|
221
|
+
const second = await manager.get("thread-b");
|
|
222
|
+
|
|
223
|
+
assert.equal(first, second);
|
|
224
|
+
assert.deepEqual(factory.created, ["sbx-1"]);
|
|
225
|
+
|
|
226
|
+
await manager.release("thread-a");
|
|
227
|
+
assert.deepEqual(factory.destroyed, []);
|
|
228
|
+
|
|
229
|
+
await manager.closeAll();
|
|
230
|
+
assert.deepEqual(factory.destroyed, ["sbx-1"]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("threadIdFromRuntime 支持 context 与 configurable", () => {
|
|
234
|
+
assert.equal(threadIdFromRuntime({ context: { threadId: "from-context" } }), "from-context");
|
|
235
|
+
assert.equal(
|
|
236
|
+
threadIdFromRuntime({ config: { configurable: { thread_id: "from-config" } } }),
|
|
237
|
+
"from-config",
|
|
238
|
+
);
|
|
239
|
+
assert.equal(threadIdFromRuntime({ state: {} }), undefined);
|
|
240
|
+
assert.equal(threadIdFromRuntime(undefined), undefined);
|
|
241
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { SandboxApiException, type Sandbox } from "@alibaba-group/opensandbox";
|
|
5
|
+
|
|
6
|
+
import { OpenSandboxBackend } from "../../src/sandbox/index.js";
|
|
7
|
+
|
|
8
|
+
interface FakeSandboxCalls {
|
|
9
|
+
sessions: Array<{ workingDirectory?: string }>;
|
|
10
|
+
run: Array<{ sessionId: string; command: string }>;
|
|
11
|
+
deleted: string[];
|
|
12
|
+
directories: string[];
|
|
13
|
+
writes: string[];
|
|
14
|
+
reads: string[];
|
|
15
|
+
renewals: number[];
|
|
16
|
+
killed: boolean;
|
|
17
|
+
closed: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const createFakeSandbox = ({ failFirstRun = false }: { failFirstRun?: boolean } = {}): {
|
|
21
|
+
sandbox: Sandbox;
|
|
22
|
+
calls: FakeSandboxCalls;
|
|
23
|
+
} => {
|
|
24
|
+
const calls: FakeSandboxCalls = {
|
|
25
|
+
sessions: [],
|
|
26
|
+
run: [],
|
|
27
|
+
deleted: [],
|
|
28
|
+
directories: [],
|
|
29
|
+
writes: [],
|
|
30
|
+
reads: [],
|
|
31
|
+
renewals: [],
|
|
32
|
+
killed: false,
|
|
33
|
+
closed: false,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let created = 0;
|
|
37
|
+
let remainingFailures = failFirstRun ? 1 : 0;
|
|
38
|
+
|
|
39
|
+
const sandbox = {
|
|
40
|
+
id: "sbx-test",
|
|
41
|
+
commands: {
|
|
42
|
+
createSession: async (options?: { workingDirectory?: string }) => {
|
|
43
|
+
calls.sessions.push({ workingDirectory: options?.workingDirectory });
|
|
44
|
+
created += 1;
|
|
45
|
+
return `session-${created}`;
|
|
46
|
+
},
|
|
47
|
+
runInSession: async (sessionId: string, command: string) => {
|
|
48
|
+
if (remainingFailures > 0) {
|
|
49
|
+
remainingFailures -= 1;
|
|
50
|
+
throw new SandboxApiException({ statusCode: 404, message: "session not found" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
calls.run.push({ sessionId, command });
|
|
54
|
+
return {
|
|
55
|
+
logs: {
|
|
56
|
+
stdout: [{ text: "hello", timestamp: 0 }],
|
|
57
|
+
stderr: [{ text: "boom", timestamp: 0 }],
|
|
58
|
+
},
|
|
59
|
+
exitCode: 0,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
deleteSession: async (sessionId: string) => {
|
|
63
|
+
calls.deleted.push(sessionId);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
files: {
|
|
67
|
+
createDirectories: async (entries: Array<{ path: string }>) => {
|
|
68
|
+
calls.directories.push(...entries.map((entry) => entry.path));
|
|
69
|
+
},
|
|
70
|
+
writeFiles: async (entries: Array<{ path: string }>) => {
|
|
71
|
+
calls.writes.push(...entries.map((entry) => entry.path));
|
|
72
|
+
},
|
|
73
|
+
readBytes: async (path: string) => {
|
|
74
|
+
calls.reads.push(path);
|
|
75
|
+
return new Uint8Array([104, 105]);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
renew: async (timeoutSeconds: number) => {
|
|
79
|
+
calls.renewals.push(timeoutSeconds);
|
|
80
|
+
},
|
|
81
|
+
kill: async () => {
|
|
82
|
+
calls.killed = true;
|
|
83
|
+
},
|
|
84
|
+
close: async () => {
|
|
85
|
+
calls.closed = true;
|
|
86
|
+
},
|
|
87
|
+
} as unknown as Sandbox;
|
|
88
|
+
|
|
89
|
+
return { sandbox, calls };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
test("execute 在持久 session 中组合 stdout/stderr", async () => {
|
|
93
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
94
|
+
const backend = new OpenSandboxBackend({ sandbox, workspaceRoot: "/workspace" });
|
|
95
|
+
|
|
96
|
+
const result = await backend.execute("echo hello");
|
|
97
|
+
|
|
98
|
+
assert.equal(result.output, "hello\n[stderr] boom");
|
|
99
|
+
assert.equal(result.exitCode, 0);
|
|
100
|
+
assert.equal(result.truncated, false);
|
|
101
|
+
assert.deepEqual(calls.sessions, [{ workingDirectory: "/workspace" }]);
|
|
102
|
+
assert.deepEqual(calls.run, [{ sessionId: "session-1", command: "echo hello" }]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("连续命令复用同一个 session,并按顺序执行", async () => {
|
|
106
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
107
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
108
|
+
|
|
109
|
+
await backend.execute("cd /tmp");
|
|
110
|
+
await backend.execute("pwd");
|
|
111
|
+
await Promise.all([backend.execute("echo a"), backend.execute("echo b")]);
|
|
112
|
+
|
|
113
|
+
assert.equal(calls.sessions.length, 1);
|
|
114
|
+
assert.deepEqual(
|
|
115
|
+
calls.run.map(({ sessionId }) => sessionId),
|
|
116
|
+
["session-1", "session-1", "session-1", "session-1"],
|
|
117
|
+
);
|
|
118
|
+
assert.deepEqual(
|
|
119
|
+
calls.run.map(({ command }) => command),
|
|
120
|
+
["cd /tmp", "pwd", "echo a", "echo b"],
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("session 失效时重建并重试一次", async () => {
|
|
125
|
+
const { sandbox, calls } = createFakeSandbox({ failFirstRun: true });
|
|
126
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
127
|
+
|
|
128
|
+
const result = await backend.execute("echo hello");
|
|
129
|
+
|
|
130
|
+
assert.equal(result.exitCode, 0);
|
|
131
|
+
assert.equal(calls.sessions.length, 2);
|
|
132
|
+
assert.deepEqual(calls.run, [{ sessionId: "session-2", command: "echo hello" }]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("renew 向服务端续期 TTL", async () => {
|
|
136
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
137
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
138
|
+
|
|
139
|
+
await backend.renew(1800);
|
|
140
|
+
|
|
141
|
+
assert.deepEqual(calls.renewals, [1800]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("uploadFiles 先创建父目录再写入文件", async () => {
|
|
145
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
146
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
147
|
+
|
|
148
|
+
const result = await backend.uploadFiles([
|
|
149
|
+
["/workspace/notes/today.md", new Uint8Array([35, 32])],
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
assert.deepEqual(result, [{ path: "/workspace/notes/today.md", error: null }]);
|
|
153
|
+
assert.deepEqual(calls.directories, ["/workspace/notes"]);
|
|
154
|
+
assert.deepEqual(calls.writes, ["/workspace/notes/today.md"]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("downloadFiles 返回文件字节", async () => {
|
|
158
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
159
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
160
|
+
|
|
161
|
+
const result = await backend.downloadFiles(["/workspace/notes/today.md"]);
|
|
162
|
+
|
|
163
|
+
assert.deepEqual(calls.reads, ["/workspace/notes/today.md"]);
|
|
164
|
+
assert.equal(result[0]?.error, null);
|
|
165
|
+
assert.deepEqual(result[0]?.content, new Uint8Array([104, 105]));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("destroy 删除 session、终止自建沙箱并关闭连接", async () => {
|
|
169
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
170
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
171
|
+
|
|
172
|
+
await backend.execute("echo hello");
|
|
173
|
+
await backend.destroy();
|
|
174
|
+
|
|
175
|
+
assert.deepEqual(calls.deleted, ["session-1"]);
|
|
176
|
+
assert.equal(calls.killed, true);
|
|
177
|
+
assert.equal(calls.closed, true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("复用已有沙箱时只关闭连接,不 kill", async () => {
|
|
181
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
182
|
+
const backend = new OpenSandboxBackend({ sandbox, owned: false });
|
|
183
|
+
|
|
184
|
+
await backend.destroy();
|
|
185
|
+
|
|
186
|
+
assert.equal(calls.killed, false);
|
|
187
|
+
assert.equal(calls.closed, true);
|
|
188
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import type { BaseCheckpointSaver, BaseStore } from "@langchain/langgraph";
|
|
5
|
+
|
|
6
|
+
import type { CompiledAgent } from "../../src/graph/index.js";
|
|
7
|
+
import type { SandboxManager } from "../../src/sandbox/index.js";
|
|
8
|
+
import { SessionService } from "../../src/services/session.js";
|
|
9
|
+
|
|
10
|
+
test("删除会话时释放对应沙箱", async () => {
|
|
11
|
+
const deletedThreads: string[] = [];
|
|
12
|
+
const deletedKeys: Array<[string[], string]> = [];
|
|
13
|
+
const released: string[] = [];
|
|
14
|
+
|
|
15
|
+
const checkpointer = {
|
|
16
|
+
deleteThread: async (threadId: string) => {
|
|
17
|
+
deletedThreads.push(threadId);
|
|
18
|
+
},
|
|
19
|
+
} as unknown as BaseCheckpointSaver;
|
|
20
|
+
|
|
21
|
+
const store = {
|
|
22
|
+
delete: async (key: string[], value: string) => {
|
|
23
|
+
deletedKeys.push([key, value]);
|
|
24
|
+
},
|
|
25
|
+
} as unknown as BaseStore;
|
|
26
|
+
|
|
27
|
+
const sandboxes = {
|
|
28
|
+
release: async (threadId: string) => {
|
|
29
|
+
released.push(threadId);
|
|
30
|
+
},
|
|
31
|
+
} as unknown as SandboxManager;
|
|
32
|
+
|
|
33
|
+
const service = new SessionService({
|
|
34
|
+
graph: {} as CompiledAgent,
|
|
35
|
+
checkpointer,
|
|
36
|
+
store,
|
|
37
|
+
sandboxes,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await service.remove("thread-1", "tenant-1");
|
|
41
|
+
|
|
42
|
+
assert.deepEqual(deletedThreads, ["thread-1"]);
|
|
43
|
+
assert.deepEqual(deletedKeys, [[["sessions", "tenant-1"], "thread-1"]]);
|
|
44
|
+
assert.deepEqual(released, ["thread-1"]);
|
|
45
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
|
-
import { assertReadOnlyQuery } from "../../src/tools/database/
|
|
4
|
+
import { assertReadOnlyQuery } from "../../src/tools/database/index.js";
|
|
5
5
|
|
|
6
6
|
test("接受 SELECT 与 WITH 语句", () => {
|
|
7
7
|
assert.doesNotThrow(() => assertReadOnlyQuery("select id, name from users"));
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
你是 researcher(研究)子 Agent。你负责收集可验证的信息,并整理成主 Agent 可信赖的笔记。
|
|
2
|
-
|
|
3
|
-
## 工作流程
|
|
4
|
-
|
|
5
|
-
1. 把问题拆成 2-5 个具体的子问题。
|
|
6
|
-
2. 使用 `web_search` 搜索。优先选择一手来源(官方文档、论文、源码),而不是聚合站点。
|
|
7
|
-
3. 阅读最有价值的来源,只提取能回答子问题的事实。
|
|
8
|
-
4. 把笔记写入 `/workspace/research/<主题>.md`,包含简短摘要和来源列表。
|
|
9
|
-
5. 返回摘要和文件路径。
|
|
10
|
-
|
|
11
|
-
## 规则
|
|
12
|
-
|
|
13
|
-
- 每个事实性结论都必须附 URL。无法验证的来源要明确说明。
|
|
14
|
-
- 时间敏感的信息要记录发布日期,并标注可能过时的内容。
|
|
15
|
-
- 控制引用篇幅,不要大段复制原文。
|
|
16
|
-
- 搜索工具不可用时明确说明,并标注所给信息为“未经验证”。
|