create-deepagent-server 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +292 -2
- package/bin/create-deepagent-server.js +27 -0
- package/package.json +50 -4
- package/src/args.js +195 -0
- package/src/cli.js +269 -0
- package/src/dependencies.js +34 -0
- package/src/prompts.js +86 -0
- package/src/registry.js +68 -0
- package/src/scaffold.js +181 -0
- package/src/setup.js +79 -0
- package/src/ui.js +43 -0
- package/src/version.js +1 -0
- package/src/versions.js +29 -0
- package/templates/deepagent/js/deployment/Dockerfile +19 -0
- package/templates/deepagent/js/scripts/check.js +97 -0
- package/templates/deepagent/js/scripts/dev.js +40 -0
- package/templates/deepagent/js/src/agents/factory.js +11 -0
- package/templates/deepagent/js/src/agents/index.js +4 -0
- package/templates/deepagent/js/src/agents/prompts/index.js +2 -0
- package/templates/deepagent/js/src/agents/prompts/loader.js +53 -0
- package/templates/deepagent/js/src/agents/prompts/subagents/analyst.md +17 -0
- package/templates/deepagent/js/src/agents/prompts/subagents/coder.md +17 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.js +21 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.md +41 -0
- package/templates/deepagent/js/src/agents/state/index.js +1 -0
- package/templates/deepagent/js/src/agents/state/types.js +11 -0
- package/templates/deepagent/js/src/agents/subagents/analyst.js +12 -0
- package/templates/deepagent/js/src/agents/subagents/coder.js +12 -0
- package/templates/deepagent/js/src/agents/subagents/index.js +9 -0
- package/templates/deepagent/js/src/agents/supervisor.js +64 -0
- package/templates/deepagent/js/src/api/app.js +29 -0
- package/templates/deepagent/js/src/api/middleware/auth.js +36 -0
- package/templates/deepagent/js/src/api/middleware/error.js +30 -0
- package/templates/deepagent/js/src/api/routes/agent.js +43 -0
- package/templates/deepagent/js/src/api/routes/health.js +40 -0
- package/templates/deepagent/js/src/api/routes/session.js +42 -0
- package/templates/deepagent/js/src/app.js +98 -0
- package/templates/deepagent/js/src/backends/composite.js +22 -0
- package/templates/deepagent/js/src/backends/filesystem.js +9 -0
- package/templates/deepagent/js/src/backends/index.js +60 -0
- package/templates/deepagent/js/src/backends/sandbox.js +26 -0
- package/templates/deepagent/js/src/config/agent.js +14 -0
- package/templates/deepagent/js/src/config/database.js +19 -0
- package/templates/deepagent/js/src/config/env.js +96 -0
- package/templates/deepagent/js/src/config/index.js +45 -0
- package/templates/deepagent/js/src/graph/checkpointer.js +28 -0
- package/templates/deepagent/js/src/graph/compile.js +9 -0
- package/templates/deepagent/js/src/graph/index.js +3 -0
- package/templates/deepagent/js/src/graph/store.js +28 -0
- package/templates/deepagent/js/src/index.js +39 -0
- package/templates/deepagent/js/src/memory/index.js +8 -0
- package/templates/deepagent/js/src/memory/manager.js +50 -0
- package/templates/deepagent/js/src/memory/store.js +43 -0
- package/templates/deepagent/js/src/middleware/approval.js +47 -0
- package/templates/deepagent/js/src/middleware/context.js +35 -0
- package/templates/deepagent/js/src/middleware/index.js +9 -0
- package/templates/deepagent/js/src/middleware/logging.js +70 -0
- package/templates/deepagent/js/src/middleware/security.js +58 -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 +40 -0
- package/templates/deepagent/js/src/schemas/common.js +24 -0
- package/templates/deepagent/js/src/schemas/locale.js +4 -0
- package/templates/deepagent/js/src/schemas/session.js +27 -0
- package/templates/deepagent/js/src/services/agent.js +136 -0
- package/templates/deepagent/js/src/services/memory.js +33 -0
- package/templates/deepagent/js/src/services/session.js +118 -0
- package/templates/deepagent/js/src/skills/index.js +21 -0
- package/templates/deepagent/js/src/skills/loader.js +75 -0
- package/templates/deepagent/js/src/storage/database/client.js +57 -0
- package/templates/deepagent/js/src/storage/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/js/src/storage/logger/index.js +21 -0
- package/templates/deepagent/js/src/storage/redis/client.js +51 -0
- package/templates/deepagent/js/src/storage/shutdown/index.js +58 -0
- package/templates/deepagent/js/src/tools/database/index.js +1 -0
- package/templates/deepagent/js/src/tools/database/query.js +74 -0
- package/templates/deepagent/js/src/tools/filesystem/index.js +102 -0
- package/templates/deepagent/js/src/tools/index.js +25 -0
- package/templates/deepagent/js/src/tools/mcp/client.js +42 -0
- package/templates/deepagent/js/src/tools/mcp/connections.js +64 -0
- package/templates/deepagent/js/src/tools/mcp/index.js +10 -0
- package/templates/deepagent/js/src/tools/mcp/registry.js +36 -0
- package/templates/deepagent/js/src/utils/errors.js +73 -0
- package/templates/deepagent/js/src/utils/helpers.js +57 -0
- package/templates/deepagent/js/src/utils/validation.js +15 -0
- package/templates/deepagent/js/tests/agents/prompts.test.js +30 -0
- package/templates/deepagent/js/tests/agents/supervisor.test.js +42 -0
- package/templates/deepagent/js/tests/config/database.test.js +40 -0
- package/templates/deepagent/js/tests/integration/api.test.js +114 -0
- package/templates/deepagent/js/tests/middleware/security.test.js +27 -0
- 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 +27 -0
- package/templates/deepagent/shared/README.md +249 -0
- package/templates/deepagent/shared/_editorconfig +12 -0
- package/templates/deepagent/shared/_env.example +86 -0
- package/templates/deepagent/shared/_gitignore +22 -0
- package/templates/deepagent/shared/deployment/docker-compose.yml +60 -0
- package/templates/deepagent/shared/resources/AGENTS.md +32 -0
- package/templates/deepagent/shared/resources/knowledge/README.md +5 -0
- package/templates/deepagent/shared/skills/analysis/SKILL.md +28 -0
- package/templates/deepagent/shared/skills/coding/SKILL.md +28 -0
- package/templates/deepagent/shared/workspaces/README.md +5 -0
- package/templates/deepagent/ts/deployment/Dockerfile +25 -0
- package/templates/deepagent/ts/scripts/check.ts +99 -0
- package/templates/deepagent/ts/scripts/copy-assets.ts +37 -0
- package/templates/deepagent/ts/scripts/dev.ts +40 -0
- package/templates/deepagent/ts/src/agents/factory.ts +11 -0
- package/templates/deepagent/ts/src/agents/index.ts +4 -0
- package/templates/deepagent/ts/src/agents/prompts/index.ts +2 -0
- package/templates/deepagent/ts/src/agents/prompts/loader.ts +53 -0
- package/templates/deepagent/ts/src/agents/prompts/subagents/analyst.md +17 -0
- package/templates/deepagent/ts/src/agents/prompts/subagents/coder.md +17 -0
- package/templates/deepagent/ts/src/agents/prompts/supervisor.md +41 -0
- package/templates/deepagent/ts/src/agents/prompts/supervisor.ts +33 -0
- package/templates/deepagent/ts/src/agents/state/index.ts +1 -0
- package/templates/deepagent/ts/src/agents/state/types.ts +13 -0
- package/templates/deepagent/ts/src/agents/subagents/analyst.ts +18 -0
- package/templates/deepagent/ts/src/agents/subagents/coder.ts +14 -0
- package/templates/deepagent/ts/src/agents/subagents/index.ts +9 -0
- package/templates/deepagent/ts/src/agents/supervisor.ts +82 -0
- package/templates/deepagent/ts/src/api/app.ts +48 -0
- package/templates/deepagent/ts/src/api/middleware/auth.ts +38 -0
- package/templates/deepagent/ts/src/api/middleware/error.ts +33 -0
- package/templates/deepagent/ts/src/api/routes/agent.ts +48 -0
- package/templates/deepagent/ts/src/api/routes/health.ts +47 -0
- package/templates/deepagent/ts/src/api/routes/session.ts +47 -0
- package/templates/deepagent/ts/src/app.ts +111 -0
- package/templates/deepagent/ts/src/backends/composite.ts +34 -0
- package/templates/deepagent/ts/src/backends/filesystem.ts +19 -0
- package/templates/deepagent/ts/src/backends/index.ts +76 -0
- package/templates/deepagent/ts/src/backends/sandbox.ts +33 -0
- package/templates/deepagent/ts/src/config/agent.ts +37 -0
- package/templates/deepagent/ts/src/config/database.ts +21 -0
- package/templates/deepagent/ts/src/config/env.ts +106 -0
- package/templates/deepagent/ts/src/config/index.ts +84 -0
- package/templates/deepagent/ts/src/graph/checkpointer.ts +29 -0
- package/templates/deepagent/ts/src/graph/compile.ts +15 -0
- package/templates/deepagent/ts/src/graph/index.ts +3 -0
- package/templates/deepagent/ts/src/graph/store.ts +29 -0
- package/templates/deepagent/ts/src/index.ts +39 -0
- package/templates/deepagent/ts/src/memory/index.ts +11 -0
- package/templates/deepagent/ts/src/memory/manager.ts +76 -0
- package/templates/deepagent/ts/src/memory/store.ts +59 -0
- package/templates/deepagent/ts/src/middleware/approval.ts +49 -0
- package/templates/deepagent/ts/src/middleware/context.ts +37 -0
- package/templates/deepagent/ts/src/middleware/index.ts +9 -0
- package/templates/deepagent/ts/src/middleware/logging.ts +71 -0
- package/templates/deepagent/ts/src/middleware/security.ts +61 -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/schemas/agent.ts +48 -0
- package/templates/deepagent/ts/src/schemas/common.ts +26 -0
- package/templates/deepagent/ts/src/schemas/locale.ts +4 -0
- package/templates/deepagent/ts/src/schemas/session.ts +31 -0
- package/templates/deepagent/ts/src/services/agent.ts +170 -0
- package/templates/deepagent/ts/src/services/memory.ts +43 -0
- package/templates/deepagent/ts/src/services/session.ts +158 -0
- package/templates/deepagent/ts/src/skills/index.ts +26 -0
- package/templates/deepagent/ts/src/skills/loader.ts +90 -0
- package/templates/deepagent/ts/src/storage/database/client.ts +65 -0
- package/templates/deepagent/ts/src/storage/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/ts/src/storage/logger/index.ts +25 -0
- package/templates/deepagent/ts/src/storage/redis/client.ts +57 -0
- package/templates/deepagent/ts/src/storage/shutdown/index.ts +82 -0
- package/templates/deepagent/ts/src/tools/database/index.ts +5 -0
- package/templates/deepagent/ts/src/tools/database/query.ts +79 -0
- package/templates/deepagent/ts/src/tools/filesystem/index.ts +110 -0
- package/templates/deepagent/ts/src/tools/index.ts +43 -0
- package/templates/deepagent/ts/src/tools/mcp/client.ts +54 -0
- package/templates/deepagent/ts/src/tools/mcp/connections.ts +68 -0
- package/templates/deepagent/ts/src/tools/mcp/index.ts +10 -0
- package/templates/deepagent/ts/src/tools/mcp/registry.ts +45 -0
- package/templates/deepagent/ts/src/utils/errors.ts +95 -0
- package/templates/deepagent/ts/src/utils/helpers.ts +57 -0
- package/templates/deepagent/ts/src/utils/validation.ts +17 -0
- package/templates/deepagent/ts/tests/agents/prompts.test.ts +30 -0
- package/templates/deepagent/ts/tests/agents/supervisor.test.ts +42 -0
- package/templates/deepagent/ts/tests/config/database.test.ts +40 -0
- package/templates/deepagent/ts/tests/integration/api.test.ts +122 -0
- package/templates/deepagent/ts/tests/middleware/security.test.ts +27 -0
- 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 +27 -0
- package/templates/deepagent/ts/tsconfig.json +19 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
本文件作为项目记忆,从 `/resources/AGENTS.md` 注入主 Agent 的系统提示词。
|
|
4
|
+
|
|
5
|
+
## 项目说明
|
|
6
|
+
|
|
7
|
+
- Deep Agents + LangGraph 的 ESM 服务。
|
|
8
|
+
- 入口:`src/index.ts`(或 `.js`);应用装配:`src/app.ts`(或 `.js`)。
|
|
9
|
+
- 主 Agent 会把任务分派给 `coder`、`analyst` 两个子 Agent。
|
|
10
|
+
|
|
11
|
+
## 常用命令
|
|
12
|
+
|
|
13
|
+
- `npm run dev` —— 监听文件变化并启动 API。
|
|
14
|
+
- `npm run agent` —— 交互式终端会话。
|
|
15
|
+
- `npm run check` —— 启动前环境检查。
|
|
16
|
+
- `npm test` —— 运行测试。
|
|
17
|
+
- `npm run build` —— 编译 TypeScript(仅 TypeScript 项目)。
|
|
18
|
+
|
|
19
|
+
## 编码约定
|
|
20
|
+
|
|
21
|
+
- 仅使用 ESM 与现代 ES6+ 语法;相对导入必须带 `.js` 扩展名。
|
|
22
|
+
- Agent 提示词放在 `src/agents/prompts/**/*.md`,修改 Markdown 而不是代码。
|
|
23
|
+
- 外部输入在边界处用 Zod 校验。
|
|
24
|
+
- 路由层只负责 HTTP 转换,业务逻辑放在 services 中。
|
|
25
|
+
- Agent 产物写入 `/workspace/`;运行期不要修改 `/resources/`。
|
|
26
|
+
- 需要长期保留的事实通过 `MemoryManager` 写入 `/memories/`,不要写进 `.env`。
|
|
27
|
+
|
|
28
|
+
## 安全约束
|
|
29
|
+
|
|
30
|
+
- 不要执行破坏性 shell 命令,也不要写入 `/workspace/` 之外的路径。
|
|
31
|
+
- SQL 必须保持只读;工具内部使用 READ ONLY 事务。
|
|
32
|
+
- 当 `APPROVAL_MODE` 要求审批时,修改文件前必须先征得同意。
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: analysis
|
|
3
|
+
description: 当需要基于结构化数据回答问题、编写只读 SQL、校验数字,或在工作区产出表格/图表时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 分析(Analysis)
|
|
7
|
+
|
|
8
|
+
## 适用场景
|
|
9
|
+
|
|
10
|
+
- 问题可以用指标、分群或趋势来回答。
|
|
11
|
+
- 用户要求基于数据库或 `/workspace/` 中的数据集生成报告。
|
|
12
|
+
|
|
13
|
+
## 工作流程
|
|
14
|
+
|
|
15
|
+
1. 明确指标和对比口径(时间范围、分群、过滤条件)。
|
|
16
|
+
2. 写 SQL 前先查看表结构:表、列、类型、是否可空。
|
|
17
|
+
3. 每个问题写一条查询;尽早过滤并使用 `LIMIT`。
|
|
18
|
+
4. 校验数据:行数、日期范围、空值、重复、总计是否与已知数字一致。
|
|
19
|
+
5. 把支撑数据保存到 `/workspace/analysis/<问题>.csv`。
|
|
20
|
+
6. 报告结论、关键数字、查询语句和注意事项。
|
|
21
|
+
|
|
22
|
+
## 规则
|
|
23
|
+
|
|
24
|
+
- 只使用只读 SQL,绝不写入或修改表结构。
|
|
25
|
+
- 不要外推到数据范围之外。
|
|
26
|
+
- 每个百分比都要说明分母。
|
|
27
|
+
- 区分观察(“销售额下降 12%”)与解释(“因为……”)。
|
|
28
|
+
- 数据缺失时,明确列出缺什么,不要猜测。
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding
|
|
3
|
+
description: 当需要在工作区中实现、重构或调试代码,包括修改前阅读文件、修改后验证结果时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 编码(Coding)
|
|
7
|
+
|
|
8
|
+
## 适用场景
|
|
9
|
+
|
|
10
|
+
- 用户要求改代码、修 bug、做迁移或代码审查。
|
|
11
|
+
- 计划需要在 `/workspace/` 中落地为具体实现。
|
|
12
|
+
|
|
13
|
+
## 工作流程
|
|
14
|
+
|
|
15
|
+
1. 修改前先读相关文件(`ls`、`glob`、`grep`、`read_file`)。
|
|
16
|
+
2. 找出满足需求的最小改动。
|
|
17
|
+
3. 用 `edit_file` 修改;只有新文件才用 `write_file`。
|
|
18
|
+
4. 重新读取改动区域,确认修改正确。
|
|
19
|
+
5. 如果 `execute` 可用,先运行最窄的检查(单个测试,然后类型检查/lint),并报告准确的命令和退出状态。
|
|
20
|
+
6. 总结:改了哪些文件、行为变化、验证结果、后续事项。
|
|
21
|
+
|
|
22
|
+
## 规则
|
|
23
|
+
|
|
24
|
+
- 保持 ESM 约定;相对导入必须带 `.js` 扩展名。
|
|
25
|
+
- 不要格式化或重写无关代码。
|
|
26
|
+
- 未经要求不要新增依赖。
|
|
27
|
+
- 没有展示输出,就不要声称检查通过。
|
|
28
|
+
- 工作区不是 git 仓库时,不要执行 git 命令。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 安装依赖(包含 devDependencies,构建阶段需要 TypeScript)
|
|
2
|
+
FROM node:22-alpine AS deps
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
COPY package.json ./
|
|
5
|
+
RUN npm install
|
|
6
|
+
|
|
7
|
+
# 编译 TypeScript,并把提示词 Markdown / SQL 资源复制到 dist/
|
|
8
|
+
FROM deps AS build
|
|
9
|
+
COPY tsconfig.json ./
|
|
10
|
+
COPY src ./src
|
|
11
|
+
COPY scripts ./scripts
|
|
12
|
+
RUN npm run build
|
|
13
|
+
|
|
14
|
+
# 生产运行时只安装生产依赖
|
|
15
|
+
FROM node:22-alpine AS runtime
|
|
16
|
+
WORKDIR /app
|
|
17
|
+
ENV NODE_ENV=production
|
|
18
|
+
COPY package.json ./
|
|
19
|
+
RUN npm install --omit=dev
|
|
20
|
+
COPY --from=build /app/dist ./dist
|
|
21
|
+
COPY resources ./resources
|
|
22
|
+
COPY skills ./skills
|
|
23
|
+
COPY workspaces ./workspaces
|
|
24
|
+
EXPOSE 3000
|
|
25
|
+
CMD ["node", "dist/index.js"]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs/promises";
|
|
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";
|
|
8
|
+
import { discoverSkills, validateSkills } from "../src/skills/index.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 启动前检查:模型凭证、目录、技能以及可选基础设施。
|
|
12
|
+
* 必需项缺失时以非零状态码退出。
|
|
13
|
+
*/
|
|
14
|
+
const env = loadEnv(process.env, { requireModelCredentials: false });
|
|
15
|
+
const config = loadConfig({ env });
|
|
16
|
+
|
|
17
|
+
let failures = 0;
|
|
18
|
+
|
|
19
|
+
const report = (label: string, ok: boolean, detail = ""): void => {
|
|
20
|
+
console.log(`${ok ? "✔" : "✖"} ${label}${detail ? ` — ${detail}` : ""}`);
|
|
21
|
+
if (!ok) failures += 1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const note = (message: string): void => {
|
|
25
|
+
console.log(` ▲ ${message}`);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const providerKey = env.MODEL_API_KEY;
|
|
29
|
+
|
|
30
|
+
report(
|
|
31
|
+
`模型 ${config.model.label}/${config.model.name}`,
|
|
32
|
+
Boolean(providerKey),
|
|
33
|
+
providerKey ? config.model.baseUrl : `${config.model.baseUrl} — 未配置 MODEL_API_KEY`,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
for (const [label, directory] of Object.entries({
|
|
37
|
+
workspaces: config.paths.workspaces,
|
|
38
|
+
resources: config.paths.resources,
|
|
39
|
+
skills: config.paths.skills,
|
|
40
|
+
})) {
|
|
41
|
+
const stats = await fs.stat(directory).catch(() => null);
|
|
42
|
+
report(`${label} 目录`, Boolean(stats?.isDirectory()), directory);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const skills = await discoverSkills(config.paths.skills);
|
|
46
|
+
report(
|
|
47
|
+
"技能",
|
|
48
|
+
skills.length > 0,
|
|
49
|
+
skills.map((skill) => skill.name).join("、") || "未找到 SKILL.md",
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
for (const warning of validateSkills(skills)) {
|
|
53
|
+
note(warning);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const resourcesFile = `${config.paths.resources}/AGENTS.md`;
|
|
57
|
+
const hasAgentsFile = await fs
|
|
58
|
+
.stat(resourcesFile)
|
|
59
|
+
.then((stats) => stats.isFile())
|
|
60
|
+
.catch(() => false);
|
|
61
|
+
|
|
62
|
+
report("AGENTS.md", hasAgentsFile, resourcesFile);
|
|
63
|
+
|
|
64
|
+
if (config.database.url) {
|
|
65
|
+
const health = await checkDatabase(config.database.url);
|
|
66
|
+
report("postgres", health.ok, health.ok ? `${health.latencyMs}ms` : (health.error ?? "不可用"));
|
|
67
|
+
} else {
|
|
68
|
+
console.log("• postgres —— 未配置(使用内存 checkpointer/store)");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (config.redis.url) {
|
|
72
|
+
const health = await checkRedis();
|
|
73
|
+
report("redis", health.ok, health.ok ? `${health.latencyMs}ms` : (health.error ?? "不可用"));
|
|
74
|
+
} else {
|
|
75
|
+
console.log("• redis —— 未配置(可选)");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (config.sandbox.enabled) {
|
|
79
|
+
const ttl = config.sandbox.timeoutSeconds
|
|
80
|
+
? `TTL ${config.sandbox.timeoutSeconds}s`
|
|
81
|
+
: "TTL 关闭";
|
|
82
|
+
const target = config.sandbox.sandboxId
|
|
83
|
+
? `共享 ${config.sandbox.sandboxId},${ttl}`
|
|
84
|
+
: `按会话创建,镜像 ${config.sandbox.image},${ttl}`;
|
|
85
|
+
console.log(
|
|
86
|
+
`• 沙箱 —— OpenSandbox ${config.sandbox.protocol}://${config.sandbox.domain}(${target})`,
|
|
87
|
+
);
|
|
88
|
+
} else {
|
|
89
|
+
console.log("• 沙箱 —— 未启用(设置 SANDBOX_ENABLED=true 后启用)");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log("");
|
|
93
|
+
|
|
94
|
+
if (failures > 0) {
|
|
95
|
+
console.error(`${failures} 项检查未通过。`);
|
|
96
|
+
process.exitCode = 1;
|
|
97
|
+
} else {
|
|
98
|
+
console.log("全部检查通过。");
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { copyFile, mkdir, readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `tsc` 只输出 JavaScript。提示词 Markdown 和 SQL 迁移文件需要复制到编译产物
|
|
7
|
+
* 旁边,保证从 `dist/` 运行时仍能按相对路径找到它们。
|
|
8
|
+
*/
|
|
9
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
const SOURCE = path.join(ROOT, "src");
|
|
11
|
+
const TARGET = path.join(ROOT, "dist");
|
|
12
|
+
const ASSET_EXTENSIONS = new Set([".md", ".sql"]);
|
|
13
|
+
|
|
14
|
+
const copyAssets = async (sourceDir: string, targetDir: string): Promise<number> => {
|
|
15
|
+
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
16
|
+
await mkdir(targetDir, { recursive: true });
|
|
17
|
+
|
|
18
|
+
let copied = 0;
|
|
19
|
+
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const source = path.join(sourceDir, entry.name);
|
|
22
|
+
const target = path.join(targetDir, entry.name);
|
|
23
|
+
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
copied += await copyAssets(source, target);
|
|
26
|
+
} else if (entry.isFile() && ASSET_EXTENSIONS.has(path.extname(entry.name))) {
|
|
27
|
+
await copyFile(source, target);
|
|
28
|
+
copied += 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return copied;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const copied = await copyAssets(SOURCE, TARGET);
|
|
36
|
+
|
|
37
|
+
console.log(`已将 ${copied} 个资源文件复制到 dist/。`);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { stdin, stdout } from "node:process";
|
|
5
|
+
|
|
6
|
+
import { createApplication } from "../src/app.js";
|
|
7
|
+
import { loadConfig } from "../src/config/index.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 主 Agent 的交互式终端。
|
|
11
|
+
* 使用 `npm run agent` 启动(不会启动 HTTP 服务)。
|
|
12
|
+
*/
|
|
13
|
+
const config = loadConfig();
|
|
14
|
+
const application = await createApplication(config);
|
|
15
|
+
|
|
16
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
17
|
+
let threadId: string | undefined;
|
|
18
|
+
|
|
19
|
+
console.log(`\nDeep Agent "${config.agent.name}" 已就绪。输入 exit 退出。\n`);
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
for (;;) {
|
|
23
|
+
const line = (await rl.question("你 > ")).trim();
|
|
24
|
+
if (!line) continue;
|
|
25
|
+
|
|
26
|
+
if (["exit", "quit", ":q"].includes(line.toLowerCase())) break;
|
|
27
|
+
|
|
28
|
+
const result = await application.services.agent.invoke({
|
|
29
|
+
message: line,
|
|
30
|
+
tenantId: "local",
|
|
31
|
+
...(threadId ? { threadId } : {}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
threadId = result.threadId;
|
|
35
|
+
console.log(`\nAgent > ${result.text || "(无文本回复)"}\n`);
|
|
36
|
+
}
|
|
37
|
+
} finally {
|
|
38
|
+
rl.close();
|
|
39
|
+
await application.close();
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { compileAgentGraph, type AgentOptions, type CompiledAgent } from "../graph/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 对 `compileAgentGraph` 的轻量封装:共享默认配置(模型、后端、
|
|
5
|
+
* checkpointer、中间件)只定义一次,所有 Agent 复用。
|
|
6
|
+
*/
|
|
7
|
+
export const createAgentFactory = (defaults: AgentOptions = {}) => {
|
|
8
|
+
return (overrides: AgentOptions = {}): CompiledAgent => {
|
|
9
|
+
return compileAgentGraph({ ...defaults, ...overrides });
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createAgentFactory } from "./factory.js";
|
|
2
|
+
export { createSupervisorAgent, type SupervisorDependencies } from "./supervisor.js";
|
|
3
|
+
export { createDefaultSubagents } from "./subagents/index.js";
|
|
4
|
+
export { agentStateSchema, type AgentState } from "./state/index.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
const VALID_NAME = /^[a-z0-9][a-z0-9/_-]*$/i;
|
|
5
|
+
const cache = new Map<string, string>();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 加载与本模块同目录的 Markdown 提示词。TypeScript 构建时由
|
|
9
|
+
* `scripts/copy-assets.ts` 把 `.md` 复制到 `dist/`,因此开发和生产的
|
|
10
|
+
* 相对路径保持一致。
|
|
11
|
+
*/
|
|
12
|
+
export const loadPrompt = (name: string): string => {
|
|
13
|
+
if (!VALID_NAME.test(name) || name.includes("..")) {
|
|
14
|
+
throw new Error(`非法的提示词名称:${name}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const cached = cache.get(name);
|
|
18
|
+
if (cached !== undefined) return cached;
|
|
19
|
+
|
|
20
|
+
const file = fileURLToPath(new URL(`${name}.md`, import.meta.url));
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const content = readFileSync(file, "utf8").trim();
|
|
24
|
+
cache.set(name, content);
|
|
25
|
+
|
|
26
|
+
return content;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(`无法从 ${file} 加载提示词 "${name}"。`, {
|
|
29
|
+
cause: error,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 替换提示词中的 `{{variable}}` 占位符。缺少变量时直接报错,
|
|
36
|
+
* 让拼写错误在启动时暴露,而不是把 `{{team}}` 原样发给模型。
|
|
37
|
+
*/
|
|
38
|
+
export const renderPrompt = (template: string, variables: Record<string, string>): string => {
|
|
39
|
+
const rendered = template.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_match, key: string) => {
|
|
40
|
+
const value = variables[key];
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
throw new Error(`缺少提示词变量 "${key}"。`);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const unrendered = rendered.match(/\{\{\s*[a-zA-Z0-9_]+\s*\}\}/);
|
|
48
|
+
if (unrendered) {
|
|
49
|
+
throw new Error(`存在未渲染的提示词变量 ${unrendered[0]}。`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return rendered;
|
|
53
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
你是 analyst(分析)子 Agent。你负责把数据转化为可执行的结论。
|
|
2
|
+
|
|
3
|
+
## 工作流程
|
|
4
|
+
|
|
5
|
+
1. 明确要回答的问题,以及衡量它的指标。
|
|
6
|
+
2. 写 join 或聚合前,先用 `query_database` 查看表结构。
|
|
7
|
+
3. 编写小而清晰的查询,使用参数、明确的列名和 `LIMIT`。
|
|
8
|
+
4. 先校验数据(行数、空值、日期范围),再相信结果。
|
|
9
|
+
5. 需要时把表格或图表保存到 `/workspace/analysis/`。
|
|
10
|
+
6. 返回:结论、关键数字、产生这些数字的查询,以及注意事项。
|
|
11
|
+
|
|
12
|
+
## 规则
|
|
13
|
+
|
|
14
|
+
- 只使用只读 SQL,绝不尝试写入或 DDL。
|
|
15
|
+
- 不要用单个数据点或不完整区间推断趋势。
|
|
16
|
+
- 措辞上区分相关性与因果关系。
|
|
17
|
+
- 数据缺失或有歧义时,明确列出缺什么,不要自行填补。
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
你是 coder(编码)子 Agent。你负责在工作区中完成小而可验证的代码改动。
|
|
2
|
+
|
|
3
|
+
## 工作流程
|
|
4
|
+
|
|
5
|
+
1. 修改前先读相关文件,使用 `ls`、`glob`、`grep` 定位。
|
|
6
|
+
2. 用一句话说明要做的改动,然后实施能达成目标的最小修改。
|
|
7
|
+
3. 修改已有文件优先用 `edit_file`,新建文件用 `write_file`。
|
|
8
|
+
4. 修改后重新读取文件,确认改动已正确落盘。
|
|
9
|
+
5. 如果启用了 shell 后端,运行项目的 lint、类型检查或测试,并报告准确的命令和结果。
|
|
10
|
+
6. 返回总结:改了哪些文件、改了什么、如何验证。
|
|
11
|
+
|
|
12
|
+
## 规则
|
|
13
|
+
|
|
14
|
+
- 不要重写无关代码、整体格式化文件,或未经要求删除文件。
|
|
15
|
+
- 保持 ESM 和现代 JavaScript/TypeScript 风格;相对导入必须带 `.js` 扩展名。
|
|
16
|
+
- 没有实际运行并看到结果,就不要声称检查通过。
|
|
17
|
+
- 改动有风险或需求不明确时,停下来说明取舍,不要猜测。
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
你是 {{agentName}},一个基于 LangGraph 的 Deep Agents 工作区的主 Agent(Supervisor)。
|
|
2
|
+
|
|
3
|
+
你对用户请求的最终结果负责:规划、分派、验收,然后给出答复。
|
|
4
|
+
|
|
5
|
+
## 工作循环
|
|
6
|
+
|
|
7
|
+
1. 用一句话复述目标,并列出明确的交付物。
|
|
8
|
+
2. 调用 `write_todos` 制定简短、有序的计划,并随进展更新。
|
|
9
|
+
3. 用 `task` 工具把可独立开展的工作分派出去。给每个子 Agent 明确的范围、输入和期望输出。
|
|
10
|
+
4. 子 Agent 返回后,对照交付物检查结果。发现缺口就让它补齐,而不是自己重做。
|
|
11
|
+
5. 把需要保留的产物写入 `/workspace/`,然后为用户总结结果。
|
|
12
|
+
|
|
13
|
+
## 你的团队
|
|
14
|
+
|
|
15
|
+
{{team}}
|
|
16
|
+
|
|
17
|
+
当子 Agent 更合适时再分派;任务很小或需要完整对话上下文时,直接自己完成。
|
|
18
|
+
|
|
19
|
+
## 文件系统
|
|
20
|
+
|
|
21
|
+
- `/workspace/` —— 草稿和最终交付物,唯一可写区域。
|
|
22
|
+
- `/resources/` —— `AGENTS.md` 和知识文件。开始前先阅读。
|
|
23
|
+
- `/skills/` —— SKILL.md 说明。当技能描述与任务匹配时加载对应技能。
|
|
24
|
+
- `/memories/` —— 跨会话的长期记忆。读取相关内容,只写入需要长期保留的事实。
|
|
25
|
+
|
|
26
|
+
使用内置文件系统工具(`ls`、`read_file`、`write_file`、`edit_file`、`glob`、`grep`)查看文件,不要猜测文件内容。给用户展示绝对虚拟路径(例如 `/workspace/report.md`)。
|
|
27
|
+
|
|
28
|
+
## 数据
|
|
29
|
+
|
|
30
|
+
- `query_database` 执行只读 SQL。先看表结构,并控制结果集大小。
|
|
31
|
+
|
|
32
|
+
## 审批策略
|
|
33
|
+
|
|
34
|
+
{{approvalPolicy}}
|
|
35
|
+
|
|
36
|
+
## 规则
|
|
37
|
+
|
|
38
|
+
- 绝不伪造工具输出、文件内容、查询结果或引用。
|
|
39
|
+
- 选择满足需求的最小改动,不要重写无关文件。
|
|
40
|
+
- 工具失败时先读错误、调整参数,最多重试两次;仍失败则如实报告阻塞点。
|
|
41
|
+
- 最终答复保持简洁:做了什么、交付物在哪里、还剩什么。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentConfig } from "../../config/index.js";
|
|
2
|
+
|
|
3
|
+
import { loadPrompt, renderPrompt } from "./loader.js";
|
|
4
|
+
|
|
5
|
+
export interface SupervisorPromptOptions {
|
|
6
|
+
name: string;
|
|
7
|
+
subagents: ReadonlyArray<{ name: string; description: string }>;
|
|
8
|
+
approvalMode: AgentConfig["approvals"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const NO_APPROVAL_POLICY = "工具调用无需人工审批,直接执行。";
|
|
12
|
+
const APPROVAL_POLICY =
|
|
13
|
+
"有副作用的工具调用会暂停以等待人工审批。请说明为什么需要该工具,然后等待决定。";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 主 Agent 提示词正文在 `supervisor.md` 中,
|
|
17
|
+
* 这里只组装动态片段(Agent 名称、团队列表、审批策略)。
|
|
18
|
+
*/
|
|
19
|
+
export const buildSupervisorPrompt = ({
|
|
20
|
+
name,
|
|
21
|
+
subagents,
|
|
22
|
+
approvalMode,
|
|
23
|
+
}: SupervisorPromptOptions): string => {
|
|
24
|
+
const team = subagents.map((agent) => `- **${agent.name}** — ${agent.description}`).join("\n");
|
|
25
|
+
|
|
26
|
+
const approvalPolicy = approvalMode === "none" ? NO_APPROVAL_POLICY : APPROVAL_POLICY;
|
|
27
|
+
|
|
28
|
+
return renderPrompt(loadPrompt("supervisor"), {
|
|
29
|
+
agentName: name,
|
|
30
|
+
team,
|
|
31
|
+
approvalPolicy,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { agentStateSchema, type AgentState } from "./types.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 每个会话携带的自定义状态。Deep Agents 已提供 `messages`、`files` 和
|
|
5
|
+
* `todos`;这里补充多租户上下文,供服务和中间件读取。
|
|
6
|
+
*/
|
|
7
|
+
export const agentStateSchema = z.object({
|
|
8
|
+
tenantId: z.string().default("default"),
|
|
9
|
+
userId: z.string().optional(),
|
|
10
|
+
objective: z.string().default(""),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type AgentState = z.infer<typeof agentStateSchema>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SubAgent } from "deepagents";
|
|
2
|
+
|
|
3
|
+
import { createQueryDatabaseTool } from "../../tools/database/index.js";
|
|
4
|
+
import { loadPrompt } from "../prompts/index.js";
|
|
5
|
+
|
|
6
|
+
export interface AnalystSubagentOptions {
|
|
7
|
+
databaseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const createAnalystSubagent = ({ databaseUrl }: AnalystSubagentOptions = {}): SubAgent => {
|
|
11
|
+
return {
|
|
12
|
+
name: "analyst",
|
|
13
|
+
description: "用只读 SQL 回答数据问题,校验数字,并把表格或摘要写入 /workspace/analysis/。",
|
|
14
|
+
systemPrompt: loadPrompt("subagents/analyst"),
|
|
15
|
+
tools: databaseUrl ? [createQueryDatabaseTool({ connectionString: databaseUrl })] : [],
|
|
16
|
+
skills: ["/skills/analysis/"],
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SubAgent } from "deepagents";
|
|
2
|
+
|
|
3
|
+
import { loadPrompt } from "../prompts/index.js";
|
|
4
|
+
|
|
5
|
+
export const createCoderSubagent = (): SubAgent => {
|
|
6
|
+
return {
|
|
7
|
+
name: "coder",
|
|
8
|
+
description:
|
|
9
|
+
"在 /workspace/ 中完成聚焦的代码修改:先读后改,启用 shell 后端时运行检查,并准确报告改动内容。",
|
|
10
|
+
systemPrompt: loadPrompt("subagents/coder"),
|
|
11
|
+
tools: [],
|
|
12
|
+
skills: ["/skills/coding/"],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createAnalystSubagent, type AnalystSubagentOptions } from "./analyst.js";
|
|
2
|
+
import { createCoderSubagent } from "./coder.js";
|
|
3
|
+
|
|
4
|
+
export { createAnalystSubagent, createCoderSubagent, type AnalystSubagentOptions };
|
|
5
|
+
|
|
6
|
+
/** 默认专家团队,顺序即展示给主 Agent 的顺序。 */
|
|
7
|
+
export const createDefaultSubagents = ({ databaseUrl }: AnalystSubagentOptions = {}) => {
|
|
8
|
+
return [createCoderSubagent(), createAnalystSubagent({ databaseUrl })];
|
|
9
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
2
|
+
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
3
|
+
import type { BaseCheckpointSaver, BaseStore } from "@langchain/langgraph";
|
|
4
|
+
import type { AnyBackendProtocol, BackendFactory } from "deepagents";
|
|
5
|
+
|
|
6
|
+
import type { AppConfig } from "../config/index.js";
|
|
7
|
+
import type { Logger } from "../storage/logger/index.js";
|
|
8
|
+
import type { AgentOptions, CompiledAgent } from "../graph/index.js";
|
|
9
|
+
import {
|
|
10
|
+
createApprovalPolicy,
|
|
11
|
+
createContextMiddleware,
|
|
12
|
+
createLoggingMiddleware,
|
|
13
|
+
createSecurityMiddleware,
|
|
14
|
+
} from "../middleware/index.js";
|
|
15
|
+
import { createAgentFactory } from "./factory.js";
|
|
16
|
+
import { buildSupervisorPrompt } from "./prompts/index.js";
|
|
17
|
+
import { createDefaultSubagents } from "./subagents/index.js";
|
|
18
|
+
import { agentStateSchema } from "./state/index.js";
|
|
19
|
+
|
|
20
|
+
export interface SupervisorDependencies {
|
|
21
|
+
config: AppConfig;
|
|
22
|
+
model: BaseChatModel;
|
|
23
|
+
backend: AnyBackendProtocol | BackendFactory;
|
|
24
|
+
checkpointer: BaseCheckpointSaver;
|
|
25
|
+
store: BaseStore;
|
|
26
|
+
logger: Logger;
|
|
27
|
+
tools: StructuredToolInterface[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 装配主 Agent:共享运行时(模型、后端、checkpointer、store、中间件),
|
|
32
|
+
* 以及它的提示词、工具、子 Agent、记忆和技能。
|
|
33
|
+
*/
|
|
34
|
+
export const createSupervisorAgent = ({
|
|
35
|
+
config,
|
|
36
|
+
model,
|
|
37
|
+
backend,
|
|
38
|
+
checkpointer,
|
|
39
|
+
store,
|
|
40
|
+
logger,
|
|
41
|
+
tools,
|
|
42
|
+
}: SupervisorDependencies): CompiledAgent => {
|
|
43
|
+
const subagents = createDefaultSubagents({ databaseUrl: config.database.url });
|
|
44
|
+
|
|
45
|
+
// 依赖里用具体的工具类型,交给 Agent 时再收窄为它接受的联合类型。
|
|
46
|
+
const agentTools = tools as AgentOptions["tools"];
|
|
47
|
+
|
|
48
|
+
const middleware: AgentOptions["middleware"] = [
|
|
49
|
+
createLoggingMiddleware(logger),
|
|
50
|
+
createSecurityMiddleware(),
|
|
51
|
+
createContextMiddleware(),
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// 工厂允许返回 Promise,公开类型只声明了同步工厂,运行时由 deepagents 解析。
|
|
55
|
+
const agentBackend = backend as unknown as AgentOptions["backend"];
|
|
56
|
+
|
|
57
|
+
const createAgent = createAgentFactory({
|
|
58
|
+
model,
|
|
59
|
+
backend: agentBackend,
|
|
60
|
+
checkpointer,
|
|
61
|
+
store,
|
|
62
|
+
stateSchema: agentStateSchema,
|
|
63
|
+
middleware,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return createAgent({
|
|
67
|
+
name: config.agent.name,
|
|
68
|
+
systemPrompt: buildSupervisorPrompt({
|
|
69
|
+
name: config.agent.name,
|
|
70
|
+
subagents: subagents.map(({ name, description }) => ({
|
|
71
|
+
name,
|
|
72
|
+
description,
|
|
73
|
+
})),
|
|
74
|
+
approvalMode: config.agent.approvals,
|
|
75
|
+
}),
|
|
76
|
+
tools: agentTools,
|
|
77
|
+
subagents,
|
|
78
|
+
interruptOn: createApprovalPolicy(config.agent.approvals),
|
|
79
|
+
memory: config.agent.memoryFiles,
|
|
80
|
+
skills: config.agent.skillDirectories,
|
|
81
|
+
});
|
|
82
|
+
};
|