create-deepagent-server 0.1.0 → 1.0.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 +83 -8
- package/package.json +1 -1
- package/src/args.js +6 -4
- package/src/cli.js +1 -4
- package/src/dependencies.js +1 -1
- package/src/prompts.js +1 -0
- package/src/registry.js +8 -8
- package/src/scaffold.js +21 -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
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- **默认 JavaScript**,传 `--ts` 切换 TypeScript
|
|
8
8
|
- **仅使用 ESM**,现代 ES6+ 语法,相对导入显式带 `.js`
|
|
9
|
+
- **可选 OpenSandbox 沙箱**:`SANDBOX_ENABLED=true` 时按会话(threadId)惰性创建并复用远程沙箱,命令执行与 `/workspace/` 都在隔离环境中;`execute` 使用持久 bash session,支持 `OPEN_SANDBOX_ID` 共享已有沙箱
|
|
10
|
+
- **模型统一走 OpenAI 兼容协议**:`src/model/` 负责配置,默认 MiniMax M3(国内站),切换 OpenAI / DeepSeek / Kimi / MiniMax / 通义千问 / 智谱 / OpenRouter / vLLM / Ollama 只改环境变量
|
|
9
11
|
- **`deepagents` + LangGraph**:checkpointer/store 默认内存,可切换 PostgreSQL
|
|
10
12
|
- **Zod** 校验、**pino** 日志、优雅关闭、SSE 流式输出
|
|
11
13
|
- CLI 本身零运行时依赖
|
|
@@ -70,33 +72,36 @@ my-agent/
|
|
|
70
72
|
├── src/
|
|
71
73
|
│ ├── index.(js|ts) # 服务入口
|
|
72
74
|
│ ├── app.(js|ts) # 配置 → 基础设施 → Agent → HTTP
|
|
73
|
-
│ ├── config/ #
|
|
75
|
+
│ ├── config/ # 环境变量与 Agent 配置
|
|
76
|
+
│ ├── model/ # 模型配置:OpenAI 兼容接入 + 服务商预设
|
|
74
77
|
│ ├── agents/
|
|
75
78
|
│ │ ├── factory.ts # createDeepAgent 封装
|
|
76
79
|
│ │ ├── supervisor.ts # 主 Agent
|
|
77
|
-
│ │ ├── subagents/ #
|
|
80
|
+
│ │ ├── subagents/ # coder、analyst
|
|
78
81
|
│ │ ├── prompts/ # supervisor.md + subagents/*.md
|
|
79
82
|
│ │ └── state/ # 自定义 LangGraph 状态
|
|
80
|
-
│ ├── tools/ #
|
|
83
|
+
│ ├── tools/ # SQL、工作区文件、MCP
|
|
81
84
|
│ ├── middleware/ # 日志、安全、审批、上下文
|
|
82
85
|
│ ├── backends/ # 文件系统、沙箱、组合后端
|
|
86
|
+
│ ├── sandbox/ # OpenSandbox 远程沙箱(可选)
|
|
83
87
|
│ ├── memory/ # 长期记忆 store 与管理器
|
|
84
88
|
│ ├── skills/ # SKILL.md 发现与校验
|
|
85
89
|
│ ├── graph/ # 编译、checkpointer、store
|
|
86
90
|
│ ├── services/ # Agent、会话、记忆服务
|
|
87
91
|
│ ├── api/ # Express 应用、路由、中间件
|
|
88
92
|
│ ├── schemas/ # Zod 结构
|
|
89
|
-
│ ├──
|
|
93
|
+
│ ├── storage/ # PostgreSQL、Redis、日志、优雅关闭
|
|
90
94
|
│ └── utils/
|
|
91
95
|
├── resources/
|
|
92
96
|
│ ├── AGENTS.md # Agent 记忆 → /resources/AGENTS.md
|
|
93
97
|
│ └── knowledge/
|
|
94
|
-
├── skills/ #
|
|
98
|
+
├── skills/ # coding / analysis SKILL.md
|
|
95
99
|
├── workspaces/ # Agent 可写沙箱 → /workspace/
|
|
96
100
|
├── tests/ # agents、tools、middleware、integration
|
|
97
101
|
├── scripts/ # 交互终端 + 预检脚本
|
|
98
102
|
├── deployment/ # Dockerfile + docker-compose
|
|
99
103
|
├── .editorconfig
|
|
104
|
+
├── .env # 已生成,填入 MODEL_API_KEY
|
|
100
105
|
├── .env.example
|
|
101
106
|
├── package.json
|
|
102
107
|
└── tsconfig.json # 仅 TypeScript
|
|
@@ -106,8 +111,9 @@ my-agent/
|
|
|
106
111
|
|
|
107
112
|
`createSupervisorAgent` 构建一个 Deep Agent:
|
|
108
113
|
|
|
109
|
-
-
|
|
110
|
-
-
|
|
114
|
+
- **模型** —— `src/model/` 统一用 OpenAI 兼容协议接入:`resolveModelConfig()` 解析 `MODEL_*` 环境变量,`createChatModel()` 返回指向任意兼容地址的 `ChatOpenAI`。切换服务商只改 `.env`,不用动代码。
|
|
115
|
+
- **后端** —— `CompositeBackend` 把 `/workspace/`、`/resources/`、`/skills/` 挂载到磁盘,把 `/memories/` 挂载到 LangGraph store。`ENABLE_SHELL=true` 时默认后端切换为 `LocalShellBackend` 并暴露 `execute`;`SANDBOX_ENABLED=true` 时后端按 `threadId` 切换为对应会话的 OpenSandbox,`/workspace/` 与 `execute` 都落在该会话的远程沙箱内。
|
|
116
|
+
- **子 Agent** —— `coder`(工作区改代码)、`analyst`(只读 SQL)。每个都是声明式 `SubAgent`,拥有独立提示词与技能挂载。
|
|
111
117
|
- **提示词** —— `supervisor.md`、`subagents/*.md` 等 Markdown 文件,由 `loadPrompt()` 加载,`renderPrompt()` 填充 `{{占位符}}`(例如团队列表)。
|
|
112
118
|
- **中间件** —— 调用日志、危险命令拦截(返回 `ToolMessage` 错误)、按请求注入租户/用户上下文。
|
|
113
119
|
- **审批** —— `APPROVAL_MODE=sensitive`(默认)通过 `interruptOn` 暂停修改类工具;用同一个 `thread_id` 恢复。
|
|
@@ -126,6 +132,68 @@ my-agent/
|
|
|
126
132
|
| `npm run build` | — | `tsc` + `scripts/copy-assets.ts` |
|
|
127
133
|
| `npm run typecheck` | — | `tsc --noEmit` |
|
|
128
134
|
|
|
135
|
+
## 沙箱(OpenSandbox)
|
|
136
|
+
|
|
137
|
+
生成的项目默认直接读写宿主机的 `workspaces/`。需要把命令执行和文件读写放进隔离环境时,打开可选的 OpenSandbox 沙箱:`SANDBOX_ENABLED=true` 后,该会话的文件工具与 `execute` 都落在远程沙箱内,宿主机不再暴露执行能力。
|
|
138
|
+
|
|
139
|
+
关闭状态下不会连接任何远程服务,也不会创建沙箱。
|
|
140
|
+
|
|
141
|
+
### 1. 启动 OpenSandbox 服务
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
uvx opensandbox-server init-config ~/.sandbox.toml --example docker
|
|
145
|
+
uvx opensandbox-server # 默认监听 http://127.0.0.1:8080
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 2. 在生成项目的 `.env` 中启用
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
SANDBOX_ENABLED=true
|
|
152
|
+
OPEN_SANDBOX_DOMAIN=localhost:8080
|
|
153
|
+
OPEN_SANDBOX_PROTOCOL=http
|
|
154
|
+
OPEN_SANDBOX_API_KEY= # 服务开启鉴权时填写
|
|
155
|
+
SANDBOX_IMAGE=python:3.12 # 沙箱镜像,需要自带 bash
|
|
156
|
+
SANDBOX_WORKSPACE_ROOT=/workspace
|
|
157
|
+
SANDBOX_TIMEOUT_SECONDS=1800 # 默认 30 分钟;使用中按 TTL/3 自动续期,0 表示不过期
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`@alibaba-group/opensandbox` 已在生成项目的依赖中,无需额外安装。改完配置先跑 `npm run check`,它会打印解析后的沙箱地址、镜像或共享沙箱 ID,用来确认变量没拼错。
|
|
161
|
+
|
|
162
|
+
### 3. 运行时的行为
|
|
163
|
+
|
|
164
|
+
| 场景 | 行为 |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| 创建时机 | 每个 `threadId` 第一次运行 Agent(第一次模型调用)时惰性创建,进程启动、`npm run check`、`POST /api/sessions` 都不会创建;同一会话后续的消息、工具调用和子 Agent 复用同一个后端;创建失败会移出缓存,下次调用重试 |
|
|
167
|
+
| 隔离范围 | 不同 `threadId` 各自一个沙箱,互不影响 |
|
|
168
|
+
| 文件与命令 | 该会话的 `ls` / `read` / `write` / `edit` / `grep` / `glob` 与 `execute` 都在沙箱内执行,`execute` 的默认 cwd 为 `SANDBOX_WORKSPACE_ROOT` |
|
|
169
|
+
| 持久 shell | `execute` 在沙箱内维持一个持久 bash session,`cd`、`export`、函数定义跨命令保留;同一会话的命令串行排队,避免并发覆盖 shell 状态 |
|
|
170
|
+
| 输出上限 | 单次命令输出截断到 10 万字符,并标记 `truncated` |
|
|
171
|
+
| 与宿主机 shell | `SANDBOX_ENABLED=true` 时 `ENABLE_SHELL` 不再生效,宿主机的 `execute` 不会被暴露 |
|
|
172
|
+
| 提示词与记忆 | `AGENTS.md`、`SKILL.md` 仍在启动时从本地读取并注入提示词,`/memories/` 继续走 LangGraph store,都不经过沙箱 |
|
|
173
|
+
| 释放 | `DELETE /api/sessions/:threadId` 销毁该会话的沙箱;进程退出(`closeAll`)时销毁所有沙箱 |
|
|
174
|
+
| 共享模式 | 设置 `OPEN_SANDBOX_ID` 后所有会话连接同一个已有沙箱,退出时只关闭连接、不会 kill 它 |
|
|
175
|
+
| 过期与续期 | 默认 TTL 1800 秒:每次使用间隔超过 TTL/3 会调用 `renew` 续期,活跃会话不会到期;空闲超过 TTL 由服务端回收,下次访问自动重建(沙箱内文件丢失);`0` 关闭 TTL |
|
|
176
|
+
|
|
177
|
+
### 4. 验证一次
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
curl -s -X POST http://localhost:3000/api/agents/invoke \
|
|
181
|
+
-H 'content-type: application/json' \
|
|
182
|
+
-d '{"message":"在 /workspace 下执行 pwd 和 uname -a,把输出贴给我"}'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
返回的命令输出来自沙箱容器;宿主机的 `workspaces/` 不会被写入。
|
|
186
|
+
|
|
187
|
+
### 5. 注意事项
|
|
188
|
+
|
|
189
|
+
- 沙箱只在该会话真正跑起来时才创建,但仍然「按会话」而不是「按命令」:deepagents 要在第一次模型调用时解析后端来判断是否暴露 `execute`,所以即使这轮只聊天、没有执行命令,也会为该 `threadId` 建一个沙箱。默认 TTL 是 30 分钟且活跃会话会自动续期,闲置的沙箱由服务端回收。
|
|
190
|
+
- 服务端回收沙箱后再访问会重建一个空沙箱,里面的文件随之丢失;需要长期保留的产物要在会话结束前取回(或用 host 卷把 `/workspace` 落到本地)。
|
|
191
|
+
- 把 `SANDBOX_TIMEOUT_SECONDS` 设为 `0` 就关闭服务端 TTL,完全靠 `DELETE /api/sessions/:threadId` 和进程退出清理;进程崩溃时这种沙箱会一直留着,生产环境不建议。
|
|
192
|
+
- `SANDBOX_IMAGE` 要自带 bash 和常用工具链。精简镜像缺少命令时,`execute` 会返回非零退出码而不是报连接错误。
|
|
193
|
+
- `SANDBOX_WORKSPACE_ROOT` 建议保持 `/workspace`,与工具使用的虚拟路径一致;改成别的目录只会改变 `execute` 的默认 cwd。
|
|
194
|
+
|
|
195
|
+
实现位于生成项目的 `src/sandbox/`:`OpenSandboxBackend` 继承 deepagents 的 `BaseSandbox`,只实现 `execute` 与文件上传/下载,`ls`、`read`、`grep` 等由 `BaseSandbox` 复用同一个 session 完成;`SandboxManager` 负责按 `threadId` 缓存、续期与销毁,续期发现沙箱已被回收时会自动重建。
|
|
196
|
+
|
|
129
197
|
## 本 CLI 的仓库结构
|
|
130
198
|
|
|
131
199
|
```text
|
|
@@ -185,10 +253,17 @@ CLI 没有运行时依赖;开发依赖只有 TypeScript(生成模板、解
|
|
|
185
253
|
| 参数 | 剩余参数 `...args`、默认值 | `arguments` |
|
|
186
254
|
| 对象 | 展开 `{ ...source }`、属性简写 | `Object.assign({}, ...)`、`key: key` |
|
|
187
255
|
| 继承 | `class` | 原型链 |
|
|
256
|
+
| 私有成员 | `private` 修饰符、普通字段 | `#field` |
|
|
188
257
|
| 数组 | 字面量、`includes()` | `new Array()`、`indexOf() === -1` |
|
|
189
258
|
|
|
190
259
|
统一使用箭头函数:具名导出也写成 `const name = (...) => {}`,不再使用 `function` 声明;箭头函数没有提升,调用必须出现在定义之后。
|
|
191
260
|
|
|
261
|
+
相对导入优先走目录的 `index.js`(例如 `import { createCheckpointer } from "./graph/index.js"`);只有同一目录内部的模块之间才直接引用具体文件,避免通过 barrel 形成循环依赖。
|
|
262
|
+
|
|
263
|
+
错误处理优先用 Promise 的 `.then(onFulfilled, onRejected)`、`.catch()`、`.finally()` 表达分支;只有必须同步捕获(`JSON.parse`、`readFileSync`)或事务/资源清理时才使用 `try/catch`。不要用 `try/catch` 单纯转发错误 —— Express 5 会自动把 async handler 的拒绝交给错误中间件。
|
|
264
|
+
|
|
265
|
+
用空行分隔逻辑段落:初始化、校验、主流程、返回值之间留一行;紧耦合的几行(如声明与紧随其后的使用)保持紧凑。
|
|
266
|
+
|
|
192
267
|
三目运算尽量写在同一行:条件或分支过长时,优先提取局部变量、常量或提前返回,而不是让 Prettier 把 `? :` 拆成多行。
|
|
193
268
|
|
|
194
269
|
`npm run lint`(`scripts/check-es6.js`)用 TypeScript 编译器 API 解析语法树做校验,不会误伤注释和字符串,也不需要额外依赖;`npm test` 前会自动执行,违反约定会直接失败。
|
|
@@ -196,7 +271,7 @@ CLI 没有运行时依赖;开发依赖只有 TypeScript(生成模板、解
|
|
|
196
271
|
## 环境要求
|
|
197
272
|
|
|
198
273
|
- Node.js **22.6+**(生成项目的测试脚本使用 `node --test` glob 参数,并使用 ESM `NodeNext` 解析)
|
|
199
|
-
- 模型 API Key:`
|
|
274
|
+
- 模型 API Key:`MODEL_API_KEY`(任何兼容 OpenAI 协议的服务,服务地址由 `MODEL_PROVIDER` 或 `MODEL_BASE_URL` 决定)
|
|
200
275
|
|
|
201
276
|
`deepagents` 把 LangChain 运行时声明为 **peer dependencies**。npm 7+ 和 pnpm 8+ 会自动安装;**Yarn 用户需要显式添加**:
|
|
202
277
|
|
package/package.json
CHANGED
package/src/args.js
CHANGED
|
@@ -37,21 +37,23 @@ export const HELP_TEXT = `create-deepagent-server —— 快速创建 Deep Agent
|
|
|
37
37
|
├── src/
|
|
38
38
|
│ ├── index.(js|ts) # 服务入口
|
|
39
39
|
│ ├── app.(js|ts) # 应用装配
|
|
40
|
-
│ ├── config/ #
|
|
40
|
+
│ ├── config/ # 环境变量与 Agent 配置
|
|
41
|
+
│ ├── model/ # 模型配置与 OpenAI 兼容接入
|
|
41
42
|
│ ├── agents/ # 主 Agent、子 Agent、提示词与状态
|
|
42
|
-
│ ├── tools/ #
|
|
43
|
+
│ ├── tools/ # 数据库、文件系统、MCP
|
|
43
44
|
│ ├── middleware/ # 日志、安全、审批、上下文
|
|
44
45
|
│ ├── backends/ # 文件系统 / 沙箱 / 组合后端
|
|
46
|
+
│ ├── sandbox/ # OpenSandbox 远程沙箱执行
|
|
45
47
|
│ ├── memory/ # 长期记忆存储与管理
|
|
46
48
|
│ ├── skills/ # SKILL.md 发现与校验
|
|
47
49
|
│ ├── graph/ # LangGraph 编译、checkpointer、store
|
|
48
50
|
│ ├── services/ # Agent、会话与记忆服务
|
|
49
51
|
│ ├── api/ # Express 路由与中间件
|
|
50
52
|
│ ├── schemas/ # Zod 请求/响应结构
|
|
51
|
-
│ ├──
|
|
53
|
+
│ ├── storage/ # PostgreSQL、Redis、日志与优雅关闭
|
|
52
54
|
│ └── utils/
|
|
53
55
|
├── resources/ # AGENTS.md 与知识库
|
|
54
|
-
├── skills/ #
|
|
56
|
+
├── skills/ # coding、analysis 技能
|
|
55
57
|
├── workspaces/ # Agent 工作目录
|
|
56
58
|
├── tests/ # 单元测试与集成测试
|
|
57
59
|
├── scripts/ # 交互终端与预检脚本
|
package/src/cli.js
CHANGED
|
@@ -58,10 +58,7 @@ const printNextSteps = ({ targetDir, cwd, packageManager, installed, language })
|
|
|
58
58
|
console.log(` ${installCommandText(packageManager)}`);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
process.platform === "win32" ? "copy .env.example .env" : "cp .env.example .env";
|
|
63
|
-
|
|
64
|
-
console.log(` ${copyEnvCommand} ${dim("# 填入 OPENAI_API_KEY 或 ANTHROPIC_API_KEY")}`);
|
|
61
|
+
console.log(` ${dim("# 编辑 .env,填入 MODEL_API_KEY")}`);
|
|
65
62
|
console.log(` ${runScriptText(packageManager, "check")} ${dim("# 可选:环境预检")}`);
|
|
66
63
|
console.log(
|
|
67
64
|
` ${runScriptText(packageManager, "dev")} ${dim("# http://localhost:3000/health")}`,
|
package/src/dependencies.js
CHANGED
package/src/prompts.js
CHANGED
package/src/registry.js
CHANGED
|
@@ -36,15 +36,14 @@ const fetchLatestVersion = async (name, timeoutMs) => {
|
|
|
36
36
|
export const resolveVersions = async (packages, { timeoutMs = 5000 } = {}) => {
|
|
37
37
|
const resolved = await Promise.all(
|
|
38
38
|
packages.map(async (name) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return { name, version: fallback, isFallback: true };
|
|
39
|
+
const version = await fetchLatestVersion(name, timeoutMs).catch(() => undefined);
|
|
40
|
+
if (version !== undefined) return { name, version, isFallback: false };
|
|
41
|
+
|
|
42
|
+
const fallback = FALLBACK_VERSIONS[name];
|
|
43
|
+
if (!fallback) {
|
|
44
|
+
throw new Error(`无法解析 ${name} 的版本,且没有内置回退版本。`);
|
|
47
45
|
}
|
|
46
|
+
return { name, version: fallback, isFallback: true };
|
|
48
47
|
}),
|
|
49
48
|
);
|
|
50
49
|
|
|
@@ -62,6 +61,7 @@ export const bundledVersions = (packages) => {
|
|
|
62
61
|
if (!version) {
|
|
63
62
|
throw new Error(`没有为 ${name} 内置回退版本。`);
|
|
64
63
|
}
|
|
64
|
+
|
|
65
65
|
return [name, version];
|
|
66
66
|
}),
|
|
67
67
|
);
|
package/src/scaffold.js
CHANGED
|
@@ -38,14 +38,12 @@ const walk = async (directory, prefix = "") => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
export const ensureEmptyTarget = async (targetDir, { force = false } = {}) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
stats = await fs.stat(targetDir);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
if (error.code === "ENOENT") return;
|
|
41
|
+
const stats = await fs.stat(targetDir).catch((error) => {
|
|
42
|
+
if (error.code === "ENOENT") return null;
|
|
47
43
|
throw error;
|
|
48
|
-
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (!stats) return;
|
|
49
47
|
|
|
50
48
|
if (!stats.isDirectory()) {
|
|
51
49
|
throw new Error(`目标路径不是目录:${targetDir}`);
|
|
@@ -168,6 +166,7 @@ export const scaffold = async ({
|
|
|
168
166
|
);
|
|
169
167
|
|
|
170
168
|
const packageJson = buildPackageJson({ packageName, language, versions });
|
|
169
|
+
|
|
171
170
|
await fs.writeFile(
|
|
172
171
|
path.join(targetDir, "package.json"),
|
|
173
172
|
`${JSON.stringify(packageJson, null, 2)}\n`,
|
|
@@ -175,6 +174,21 @@ export const scaffold = async ({
|
|
|
175
174
|
);
|
|
176
175
|
writtenFiles.push("package.json");
|
|
177
176
|
|
|
177
|
+
// 默认生成可直接编辑的 .env;写入已有目录(--force)时不覆盖用户配置。
|
|
178
|
+
const envCreated = await fs
|
|
179
|
+
.copyFile(
|
|
180
|
+
path.join(targetDir, ".env.example"),
|
|
181
|
+
path.join(targetDir, ".env"),
|
|
182
|
+
fs.constants.COPYFILE_EXCL,
|
|
183
|
+
)
|
|
184
|
+
.then(() => true)
|
|
185
|
+
.catch((error) => {
|
|
186
|
+
if (error?.code === "EEXIST") return false;
|
|
187
|
+
throw error;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (envCreated) writtenFiles.push(".env");
|
|
191
|
+
|
|
178
192
|
return {
|
|
179
193
|
targetDir,
|
|
180
194
|
files: writtenFiles.sort(),
|
package/src/setup.js
CHANGED
|
@@ -64,6 +64,7 @@ export const initGit = (cwd) => {
|
|
|
64
64
|
cwd,
|
|
65
65
|
stdio: "ignore",
|
|
66
66
|
});
|
|
67
|
+
|
|
67
68
|
return !result.error && result.status === 0;
|
|
68
69
|
};
|
|
69
70
|
|
|
@@ -73,5 +74,6 @@ export const runScriptText = (packageManager, script) => {
|
|
|
73
74
|
if (packageManager === "pnpm") {
|
|
74
75
|
return `${packageManager} ${script}`;
|
|
75
76
|
}
|
|
77
|
+
|
|
76
78
|
return `${packageManager} run ${script}`;
|
|
77
79
|
};
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "
|
|
1
|
+
export const VERSION = "1.0.0";
|
package/src/versions.js
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
+
|
|
2
3
|
import fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { loadEnv } from "../src/config/
|
|
5
|
-
import { checkDatabase } from "../src/
|
|
6
|
-
import { checkRedis } from "../src/
|
|
4
|
+
|
|
5
|
+
import { loadConfig, loadEnv } from "../src/config/index.js";
|
|
6
|
+
import { checkDatabase } from "../src/storage/database/client.js";
|
|
7
|
+
import { checkRedis } from "../src/storage/redis/client.js";
|
|
7
8
|
import { discoverSkills, validateSkills } from "../src/skills/index.js";
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* 启动前检查:模型凭证、目录、技能以及可选基础设施。
|
|
10
12
|
* 必需项缺失时以非零状态码退出。
|
|
11
13
|
*/
|
|
12
14
|
const env = loadEnv(process.env, { requireModelCredentials: false });
|
|
13
15
|
const config = loadConfig({ env });
|
|
16
|
+
|
|
14
17
|
let failures = 0;
|
|
18
|
+
|
|
15
19
|
const report = (label, ok, detail = "") => {
|
|
16
20
|
console.log(`${ok ? "✔" : "✖"} ${label}${detail ? ` — ${detail}` : ""}`);
|
|
17
21
|
if (!ok) failures += 1;
|
|
18
22
|
};
|
|
23
|
+
|
|
19
24
|
const note = (message) => {
|
|
20
25
|
console.log(` ▲ ${message}`);
|
|
21
26
|
};
|
|
22
|
-
|
|
27
|
+
|
|
28
|
+
const providerKey = env.MODEL_API_KEY;
|
|
29
|
+
|
|
23
30
|
report(
|
|
24
|
-
|
|
31
|
+
`模型 ${config.model.label}/${config.model.name}`,
|
|
25
32
|
Boolean(providerKey),
|
|
26
|
-
providerKey ?
|
|
33
|
+
providerKey ? config.model.baseUrl : `${config.model.baseUrl} — 未配置 MODEL_API_KEY`,
|
|
27
34
|
);
|
|
35
|
+
|
|
28
36
|
for (const [label, directory] of Object.entries({
|
|
29
37
|
workspaces: config.paths.workspaces,
|
|
30
38
|
resources: config.paths.resources,
|
|
@@ -33,39 +41,54 @@ for (const [label, directory] of Object.entries({
|
|
|
33
41
|
const stats = await fs.stat(directory).catch(() => null);
|
|
34
42
|
report(`${label} 目录`, Boolean(stats?.isDirectory()), directory);
|
|
35
43
|
}
|
|
44
|
+
|
|
36
45
|
const skills = await discoverSkills(config.paths.skills);
|
|
37
46
|
report(
|
|
38
47
|
"技能",
|
|
39
48
|
skills.length > 0,
|
|
40
49
|
skills.map((skill) => skill.name).join("、") || "未找到 SKILL.md",
|
|
41
50
|
);
|
|
51
|
+
|
|
42
52
|
for (const warning of validateSkills(skills)) {
|
|
43
53
|
note(warning);
|
|
44
54
|
}
|
|
55
|
+
|
|
45
56
|
const resourcesFile = `${config.paths.resources}/AGENTS.md`;
|
|
46
57
|
const hasAgentsFile = await fs
|
|
47
58
|
.stat(resourcesFile)
|
|
48
59
|
.then((stats) => stats.isFile())
|
|
49
60
|
.catch(() => false);
|
|
61
|
+
|
|
50
62
|
report("AGENTS.md", hasAgentsFile, resourcesFile);
|
|
63
|
+
|
|
51
64
|
if (config.database.url) {
|
|
52
|
-
const health = await checkDatabase();
|
|
65
|
+
const health = await checkDatabase(config.database.url);
|
|
53
66
|
report("postgres", health.ok, health.ok ? `${health.latencyMs}ms` : (health.error ?? "不可用"));
|
|
54
67
|
} else {
|
|
55
68
|
console.log("• postgres —— 未配置(使用内存 checkpointer/store)");
|
|
56
69
|
}
|
|
70
|
+
|
|
57
71
|
if (config.redis.url) {
|
|
58
72
|
const health = await checkRedis();
|
|
59
73
|
report("redis", health.ok, health.ok ? `${health.latencyMs}ms` : (health.error ?? "不可用"));
|
|
60
74
|
} else {
|
|
61
75
|
console.log("• redis —— 未配置(可选)");
|
|
62
76
|
}
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
|
|
78
|
+
if (config.sandbox.enabled) {
|
|
79
|
+
const ttl = config.sandbox.timeoutSeconds ? `TTL ${config.sandbox.timeoutSeconds}s` : "TTL 关闭";
|
|
80
|
+
const target = config.sandbox.sandboxId
|
|
81
|
+
? `共享 ${config.sandbox.sandboxId},${ttl}`
|
|
82
|
+
: `按会话创建,镜像 ${config.sandbox.image},${ttl}`;
|
|
83
|
+
console.log(
|
|
84
|
+
`• 沙箱 —— OpenSandbox ${config.sandbox.protocol}://${config.sandbox.domain}(${target})`,
|
|
85
|
+
);
|
|
65
86
|
} else {
|
|
66
|
-
console.log("•
|
|
87
|
+
console.log("• 沙箱 —— 未启用(设置 SANDBOX_ENABLED=true 后启用)");
|
|
67
88
|
}
|
|
89
|
+
|
|
68
90
|
console.log("");
|
|
91
|
+
|
|
69
92
|
if (failures > 0) {
|
|
70
93
|
console.error(`${failures} 项检查未通过。`);
|
|
71
94
|
process.exitCode = 1;
|
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
+
|
|
2
3
|
import { createInterface } from "node:readline/promises";
|
|
3
4
|
import { stdin, stdout } from "node:process";
|
|
5
|
+
|
|
4
6
|
import { createApplication } from "../src/app.js";
|
|
5
7
|
import { loadConfig } from "../src/config/index.js";
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* 主 Agent 的交互式终端。
|
|
8
11
|
* 使用 `npm run agent` 启动(不会启动 HTTP 服务)。
|
|
9
12
|
*/
|
|
10
13
|
const config = loadConfig();
|
|
11
14
|
const application = await createApplication(config);
|
|
15
|
+
|
|
12
16
|
const rl = createInterface({ input: stdin, output: stdout });
|
|
13
17
|
let threadId;
|
|
18
|
+
|
|
14
19
|
console.log(`\nDeep Agent "${config.agent.name}" 已就绪。输入 exit 退出。\n`);
|
|
20
|
+
|
|
15
21
|
try {
|
|
16
22
|
for (;;) {
|
|
17
23
|
const line = (await rl.question("你 > ")).trim();
|
|
18
24
|
if (!line) continue;
|
|
25
|
+
|
|
19
26
|
if (["exit", "quit", ":q"].includes(line.toLowerCase())) break;
|
|
27
|
+
|
|
20
28
|
const result = await application.services.agent.invoke({
|
|
21
29
|
message: line,
|
|
22
30
|
tenantId: "local",
|
|
23
31
|
...(threadId ? { threadId } : {}),
|
|
24
32
|
});
|
|
33
|
+
|
|
25
34
|
threadId = result.threadId;
|
|
26
35
|
console.log(`\nAgent > ${result.text || "(无文本回复)"}\n`);
|
|
27
36
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
3
4
|
const VALID_NAME = /^[a-z0-9][a-z0-9/_-]*$/i;
|
|
4
5
|
const cache = new Map();
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* 加载与本模块同目录的 Markdown 提示词。TypeScript 构建时由
|
|
7
9
|
* `scripts/copy-assets.ts` 把 `.md` 复制到 `dist/`,因此开发和生产的
|
|
@@ -11,12 +13,16 @@ export const loadPrompt = (name) => {
|
|
|
11
13
|
if (!VALID_NAME.test(name) || name.includes("..")) {
|
|
12
14
|
throw new Error(`非法的提示词名称:${name}`);
|
|
13
15
|
}
|
|
16
|
+
|
|
14
17
|
const cached = cache.get(name);
|
|
15
18
|
if (cached !== undefined) return cached;
|
|
19
|
+
|
|
16
20
|
const file = fileURLToPath(new URL(`${name}.md`, import.meta.url));
|
|
21
|
+
|
|
17
22
|
try {
|
|
18
23
|
const content = readFileSync(file, "utf8").trim();
|
|
19
24
|
cache.set(name, content);
|
|
25
|
+
|
|
20
26
|
return content;
|
|
21
27
|
} catch (error) {
|
|
22
28
|
throw new Error(`无法从 ${file} 加载提示词 "${name}"。`, {
|
|
@@ -24,6 +30,7 @@ export const loadPrompt = (name) => {
|
|
|
24
30
|
});
|
|
25
31
|
}
|
|
26
32
|
};
|
|
33
|
+
|
|
27
34
|
/**
|
|
28
35
|
* 替换提示词中的 `{{variable}}` 占位符。缺少变量时直接报错,
|
|
29
36
|
* 让拼写错误在启动时暴露,而不是把 `{{team}}` 原样发给模型。
|
|
@@ -36,9 +43,11 @@ export const renderPrompt = (template, variables) => {
|
|
|
36
43
|
}
|
|
37
44
|
return value;
|
|
38
45
|
});
|
|
46
|
+
|
|
39
47
|
const unrendered = rendered.match(/\{\{\s*[a-zA-Z0-9_]+\s*\}\}/);
|
|
40
48
|
if (unrendered) {
|
|
41
49
|
throw new Error(`存在未渲染的提示词变量 ${unrendered[0]}。`);
|
|
42
50
|
}
|
|
51
|
+
|
|
43
52
|
return rendered;
|
|
44
53
|
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { loadPrompt, renderPrompt } from "./loader.js";
|
|
2
|
+
|
|
2
3
|
const NO_APPROVAL_POLICY = "工具调用无需人工审批,直接执行。";
|
|
3
4
|
const APPROVAL_POLICY =
|
|
4
5
|
"有副作用的工具调用会暂停以等待人工审批。请说明为什么需要该工具,然后等待决定。";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* 主 Agent 提示词正文在 `supervisor.md` 中,
|
|
7
9
|
* 这里只组装动态片段(Agent 名称、团队列表、审批策略)。
|
|
8
10
|
*/
|
|
9
11
|
export const buildSupervisorPrompt = ({ name, subagents, approvalMode }) => {
|
|
10
12
|
const team = subagents.map((agent) => `- **${agent.name}** — ${agent.description}`).join("\n");
|
|
13
|
+
|
|
11
14
|
const approvalPolicy = approvalMode === "none" ? NO_APPROVAL_POLICY : APPROVAL_POLICY;
|
|
15
|
+
|
|
12
16
|
return renderPrompt(loadPrompt("supervisor"), {
|
|
13
17
|
agentName: name,
|
|
14
18
|
team,
|
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
使用内置文件系统工具(`ls`、`read_file`、`write_file`、`edit_file`、`glob`、`grep`)查看文件,不要猜测文件内容。给用户展示绝对虚拟路径(例如 `/workspace/report.md`)。
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## 数据
|
|
29
29
|
|
|
30
|
-
- `web_search` 返回标题、URL 和摘要。引用你实际使用的 URL,绝不编造来源。
|
|
31
30
|
- `query_database` 执行只读 SQL。先看表结构,并控制结果集大小。
|
|
32
31
|
|
|
33
32
|
## 审批策略
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createQueryDatabaseTool } from "../../tools/database/index.js";
|
|
2
2
|
import { loadPrompt } from "../prompts/index.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
export const createAnalystSubagent = ({ databaseUrl } = {}) => {
|
|
4
5
|
return {
|
|
5
6
|
name: "analyst",
|
|
6
7
|
description: "用只读 SQL 回答数据问题,校验数字,并把表格或摘要写入 /workspace/analysis/。",
|
|
7
8
|
systemPrompt: loadPrompt("subagents/analyst"),
|
|
8
|
-
tools: [
|
|
9
|
+
tools: databaseUrl ? [createQueryDatabaseTool({ connectionString: databaseUrl })] : [],
|
|
9
10
|
skills: ["/skills/analysis/"],
|
|
10
11
|
};
|
|
11
12
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createAnalystSubagent } from "./analyst.js";
|
|
2
2
|
import { createCoderSubagent } from "./coder.js";
|
|
3
|
-
|
|
4
|
-
export { createAnalystSubagent, createCoderSubagent
|
|
3
|
+
|
|
4
|
+
export { createAnalystSubagent, createCoderSubagent };
|
|
5
|
+
|
|
5
6
|
/** 默认专家团队,顺序即展示给主 Agent 的顺序。 */
|
|
6
|
-
export const createDefaultSubagents = () => {
|
|
7
|
-
return [
|
|
7
|
+
export const createDefaultSubagents = ({ databaseUrl } = {}) => {
|
|
8
|
+
return [createCoderSubagent(), createAnalystSubagent({ databaseUrl })];
|
|
8
9
|
};
|