opc-agent 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -51
- package/CONTRIBUTING.md +75 -75
- package/README.md +341 -101
- package/README.zh-CN.md +382 -55
- package/dist/channels/web.js +256 -256
- package/dist/cli.js +1 -32
- package/dist/deploy/hermes.js +22 -22
- package/dist/deploy/openclaw.js +31 -31
- package/dist/i18n/index.js +60 -9
- package/dist/templates/code-reviewer.js +5 -5
- package/dist/templates/customer-service.js +2 -2
- package/dist/templates/data-analyst.js +5 -5
- package/dist/templates/knowledge-base.js +2 -2
- package/dist/templates/sales-assistant.js +4 -4
- package/dist/templates/teacher.js +6 -6
- package/docs/.vitepress/config.ts +103 -92
- package/docs/api/cli.md +48 -48
- package/docs/api/oad-schema.md +64 -64
- package/docs/api/sdk.md +80 -80
- package/docs/guide/concepts.md +51 -51
- package/docs/guide/configuration.md +79 -79
- package/docs/guide/deployment.md +42 -42
- package/docs/guide/getting-started.md +44 -44
- package/docs/guide/templates.md +28 -28
- package/docs/guide/testing.md +84 -84
- package/docs/index.md +27 -27
- package/docs/zh/api/cli.md +54 -0
- package/docs/zh/api/oad-schema.md +87 -3
- package/docs/zh/api/sdk.md +102 -0
- package/docs/zh/guide/concepts.md +104 -28
- package/docs/zh/guide/configuration.md +135 -39
- package/docs/zh/guide/deployment.md +81 -3
- package/docs/zh/guide/getting-started.md +82 -58
- package/docs/zh/guide/templates.md +84 -22
- package/docs/zh/guide/testing.md +88 -18
- package/docs/zh/index.md +27 -27
- package/examples/customer-service-demo/README.md +90 -90
- package/examples/customer-service-demo/oad.yaml +107 -107
- package/package.json +1 -1
- package/src/analytics/index.ts +66 -66
- package/src/channels/discord.ts +192 -192
- package/src/channels/email.ts +177 -177
- package/src/channels/feishu.ts +236 -236
- package/src/channels/index.ts +15 -15
- package/src/channels/slack.ts +160 -160
- package/src/channels/telegram.ts +90 -90
- package/src/channels/voice.ts +106 -106
- package/src/channels/web.ts +596 -596
- package/src/channels/webhook.ts +199 -199
- package/src/channels/websocket.ts +87 -87
- package/src/channels/wechat.ts +149 -149
- package/src/cli.ts +1 -35
- package/src/core/a2a.ts +143 -143
- package/src/core/agent.ts +152 -152
- package/src/core/analytics-engine.ts +186 -186
- package/src/core/auth.ts +57 -57
- package/src/core/cache.ts +141 -141
- package/src/core/compose.ts +77 -77
- package/src/core/config.ts +14 -14
- package/src/core/errors.ts +148 -148
- package/src/core/hitl.ts +138 -138
- package/src/core/knowledge.ts +210 -210
- package/src/core/logger.ts +57 -57
- package/src/core/orchestrator.ts +215 -215
- package/src/core/performance.ts +187 -187
- package/src/core/rate-limiter.ts +128 -128
- package/src/core/room.ts +109 -109
- package/src/core/runtime.ts +152 -152
- package/src/core/sandbox.ts +101 -101
- package/src/core/security.ts +171 -171
- package/src/core/types.ts +68 -68
- package/src/core/versioning.ts +106 -106
- package/src/core/watch.ts +178 -178
- package/src/core/workflow.ts +235 -235
- package/src/deploy/hermes.ts +156 -156
- package/src/deploy/openclaw.ts +200 -200
- package/src/dtv/data.ts +29 -29
- package/src/dtv/trust.ts +43 -43
- package/src/dtv/value.ts +47 -47
- package/src/i18n/index.ts +216 -165
- package/src/index.ts +110 -110
- package/src/marketplace/index.ts +223 -223
- package/src/memory/deepbrain.ts +108 -108
- package/src/memory/index.ts +34 -34
- package/src/plugins/index.ts +208 -208
- package/src/providers/index.ts +183 -183
- package/src/schema/oad.ts +155 -155
- package/src/skills/base.ts +16 -16
- package/src/skills/document.ts +100 -100
- package/src/skills/http.ts +35 -35
- package/src/skills/index.ts +27 -27
- package/src/skills/scheduler.ts +80 -80
- package/src/skills/webhook-trigger.ts +59 -59
- package/src/templates/code-reviewer.ts +34 -34
- package/src/templates/customer-service.ts +80 -80
- package/src/templates/data-analyst.ts +70 -70
- package/src/templates/executive-assistant.ts +71 -71
- package/src/templates/financial-advisor.ts +60 -60
- package/src/templates/knowledge-base.ts +31 -31
- package/src/templates/legal-assistant.ts +71 -71
- package/src/templates/sales-assistant.ts +79 -79
- package/src/templates/teacher.ts +79 -79
- package/src/testing/index.ts +181 -181
- package/src/tools/calculator.ts +73 -73
- package/src/tools/datetime.ts +149 -149
- package/src/tools/json-transform.ts +187 -187
- package/src/tools/mcp.ts +76 -76
- package/src/tools/text-analysis.ts +116 -116
- package/templates/Dockerfile +15 -15
- package/templates/code-reviewer/README.md +27 -27
- package/templates/code-reviewer/oad.yaml +41 -41
- package/templates/customer-service/README.md +22 -22
- package/templates/customer-service/oad.yaml +36 -36
- package/templates/docker-compose.yml +21 -21
- package/templates/knowledge-base/README.md +28 -28
- package/templates/knowledge-base/oad.yaml +38 -38
- package/templates/sales-assistant/README.md +26 -26
- package/templates/sales-assistant/oad.yaml +43 -43
- package/tests/a2a.test.ts +66 -66
- package/tests/agent.test.ts +72 -72
- package/tests/analytics.test.ts +50 -50
- package/tests/channel.test.ts +39 -39
- package/tests/e2e.test.ts +134 -134
- package/tests/errors.test.ts +83 -83
- package/tests/hitl.test.ts +71 -71
- package/tests/i18n.test.ts +41 -41
- package/tests/mcp.test.ts +54 -54
- package/tests/oad.test.ts +68 -68
- package/tests/performance.test.ts +115 -115
- package/tests/plugin.test.ts +74 -74
- package/tests/room.test.ts +106 -106
- package/tests/runtime.test.ts +42 -42
- package/tests/sandbox.test.ts +46 -46
- package/tests/security.test.ts +60 -60
- package/tests/templates.test.ts +77 -77
- package/tests/v070.test.ts +76 -76
- package/tests/versioning.test.ts +75 -75
- package/tests/voice.test.ts +61 -61
- package/tests/webhook.test.ts +29 -29
- package/tests/workflow.test.ts +143 -143
- package/tsconfig.json +19 -19
- package/vitest.config.ts +9 -9
|
@@ -1,28 +1,104 @@
|
|
|
1
|
-
# 核心概念
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
# 核心概念
|
|
2
|
+
|
|
3
|
+
## 智能体 (Agent)
|
|
4
|
+
|
|
5
|
+
智能体是一个有完整生命周期的 AI 实体:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
初始化 (init) → 就绪 (ready) → 运行中 (running) → 已停止 (stopped)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
每个智能体有以下属性:
|
|
12
|
+
- **名称** — 唯一标识符
|
|
13
|
+
- **系统提示词** — 定义智能体的角色和行为
|
|
14
|
+
- **技能** — 智能体能做的事(如 FAQ 查询、转人工)
|
|
15
|
+
- **渠道** — 用户和智能体交互的方式(如 Web、Telegram)
|
|
16
|
+
- **记忆** — 对话历史和长期知识
|
|
17
|
+
|
|
18
|
+
## OAD (Open Agent Definition)
|
|
19
|
+
|
|
20
|
+
OAD 是智能体的声明式定义格式,用 YAML 编写。一个 OAD 文件就是一个完整的智能体定义。
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
apiVersion: opc/v1
|
|
24
|
+
kind: Agent
|
|
25
|
+
metadata:
|
|
26
|
+
name: my-agent
|
|
27
|
+
version: 1.0.0
|
|
28
|
+
spec:
|
|
29
|
+
provider:
|
|
30
|
+
default: deepseek
|
|
31
|
+
model: deepseek-chat
|
|
32
|
+
systemPrompt: "你是一个专业的客服助手。"
|
|
33
|
+
skills: [...]
|
|
34
|
+
channels: [...]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
这个设计理念参考了 Kubernetes 的资源定义:声明你想要的状态,框架帮你实现。
|
|
38
|
+
|
|
39
|
+
## 技能 (Skill)
|
|
40
|
+
|
|
41
|
+
技能是智能体的模块化能力。每个技能:
|
|
42
|
+
- 有 `name` 和 `description`
|
|
43
|
+
- 接收对话上下文和当前消息
|
|
44
|
+
- 返回是否处理了这条消息,以及置信度
|
|
45
|
+
|
|
46
|
+
内置技能包括:
|
|
47
|
+
- **FAQ 查询** — 从预设问答库匹配答案
|
|
48
|
+
- **人工转接** — 置信度低时转给人工客服
|
|
49
|
+
- **知识库检索** — 从文档中语义搜索相关内容
|
|
50
|
+
|
|
51
|
+
你也可以继承 `BaseSkill` 实现自定义技能。
|
|
52
|
+
|
|
53
|
+
## 渠道 (Channel)
|
|
54
|
+
|
|
55
|
+
渠道是用户和智能体交互的接口:
|
|
56
|
+
|
|
57
|
+
| 渠道 | 说明 |
|
|
58
|
+
|------|------|
|
|
59
|
+
| **Web** | HTTP API + SSE 流式响应,自带对话 UI |
|
|
60
|
+
| **WebSocket** | 实时双向通信 + 广播 |
|
|
61
|
+
| **Telegram** | Telegram Bot API Webhook |
|
|
62
|
+
| **Slack** | Slack 应用集成 |
|
|
63
|
+
| **微信** | 微信公众号消息处理 |
|
|
64
|
+
| **飞书** | 飞书机器人 |
|
|
65
|
+
| **邮件** | 邮件收发 |
|
|
66
|
+
| **语音** | 语音识别(STT)+ 语音合成(TTS) |
|
|
67
|
+
| **Webhook** | 接收外部系统回调 |
|
|
68
|
+
|
|
69
|
+
## 记忆 (Memory)
|
|
70
|
+
|
|
71
|
+
智能体有两种记忆:
|
|
72
|
+
|
|
73
|
+
- **短期记忆** — 单次会话内的对话历史,会话结束即清除
|
|
74
|
+
- **长期记忆** — 跨会话的持久化知识,支持 DeepBrain 语义搜索
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
spec:
|
|
78
|
+
memory:
|
|
79
|
+
shortTerm: true # 开启对话上下文
|
|
80
|
+
longTerm: true # 开启长期记忆
|
|
81
|
+
provider: deepbrain # 长期记忆后端
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## DTV 框架 (Data / Trust / Value)
|
|
85
|
+
|
|
86
|
+
DTV 框架管理智能体的数据访问、信任等级和价值度量:
|
|
87
|
+
|
|
88
|
+
### 数据 (Data)
|
|
89
|
+
智能体对业务数据的只读访问。可以读取配置,但不能修改源系统。
|
|
90
|
+
|
|
91
|
+
### 信任 (Trust)
|
|
92
|
+
渐进式信任等级控制智能体的能力范围:
|
|
93
|
+
|
|
94
|
+
| 等级 | 说明 |
|
|
95
|
+
|------|------|
|
|
96
|
+
| `sandbox` | 沙箱模式,无网络访问,能力受限 |
|
|
97
|
+
| `verified` | 身份已验证,基础能力 |
|
|
98
|
+
| `certified` | 通过安全审计,完整能力 |
|
|
99
|
+
| `listed` | 已发布到 OPC 市场 |
|
|
100
|
+
|
|
101
|
+
### 价值 (Value)
|
|
102
|
+
性能和 ROI 指标追踪:
|
|
103
|
+
- 响应时间、满意度评分、解决率
|
|
104
|
+
- 自动化报表和仪表盘
|
|
@@ -1,39 +1,135 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```yaml
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
# 配置详解
|
|
2
|
+
|
|
3
|
+
## OAD 文件结构
|
|
4
|
+
|
|
5
|
+
`oad.yaml` 是智能体的核心配置文件,所有配置都在这里:
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
apiVersion: opc/v1
|
|
9
|
+
kind: Agent
|
|
10
|
+
metadata:
|
|
11
|
+
name: my-agent
|
|
12
|
+
version: 1.0.0
|
|
13
|
+
description: 我的智能体
|
|
14
|
+
spec:
|
|
15
|
+
provider:
|
|
16
|
+
default: deepseek
|
|
17
|
+
allowed: [openai, deepseek, qwen]
|
|
18
|
+
model: deepseek-chat
|
|
19
|
+
systemPrompt: "你是一个专业的助手。"
|
|
20
|
+
skills: []
|
|
21
|
+
channels:
|
|
22
|
+
- type: web
|
|
23
|
+
port: 3000
|
|
24
|
+
memory:
|
|
25
|
+
shortTerm: true
|
|
26
|
+
longTerm: false
|
|
27
|
+
testing:
|
|
28
|
+
cases:
|
|
29
|
+
- name: 问候测试
|
|
30
|
+
input: "你好"
|
|
31
|
+
expect:
|
|
32
|
+
contains: ["你好", "帮"]
|
|
33
|
+
maxLatencyMs: 5000
|
|
34
|
+
rateLimits:
|
|
35
|
+
perUser:
|
|
36
|
+
maxRequests: 60
|
|
37
|
+
windowMs: 60000
|
|
38
|
+
perProvider:
|
|
39
|
+
maxRequests: 100
|
|
40
|
+
windowMs: 60000
|
|
41
|
+
cache:
|
|
42
|
+
enabled: true
|
|
43
|
+
ttlMs: 3600000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 环境变量
|
|
47
|
+
|
|
48
|
+
| 变量 | 说明 | 默认值 |
|
|
49
|
+
|------|------|--------|
|
|
50
|
+
| `OPC_LLM_API_KEY` | 大语言模型 API Key | — |
|
|
51
|
+
| `OPC_LLM_BASE_URL` | API 地址 | `https://api.openai.com/v1` |
|
|
52
|
+
| `OPC_LLM_MODEL` | 模型名称 | `gpt-4o-mini` |
|
|
53
|
+
|
|
54
|
+
## 模型供应商配置
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
spec:
|
|
58
|
+
provider:
|
|
59
|
+
default: deepseek # 默认供应商
|
|
60
|
+
allowed: [deepseek, qwen, openai] # 允许的供应商列表
|
|
61
|
+
model: deepseek-chat # 具体模型
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
运行时通过环境变量 `OPC_LLM_API_KEY` 和 `OPC_LLM_BASE_URL` 传入凭证。
|
|
65
|
+
|
|
66
|
+
## 限流配置
|
|
67
|
+
|
|
68
|
+
保护你的 API 配额和后端服务:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
spec:
|
|
72
|
+
rateLimits:
|
|
73
|
+
perUser:
|
|
74
|
+
maxRequests: 60 # 每个用户每分钟最多 60 次请求
|
|
75
|
+
windowMs: 60000
|
|
76
|
+
perProvider:
|
|
77
|
+
maxRequests: 100 # 每个供应商每分钟最多 100 次请求
|
|
78
|
+
windowMs: 60000
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 缓存配置
|
|
82
|
+
|
|
83
|
+
开启 LLM 响应缓存,降低 API 调用成本:
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
spec:
|
|
87
|
+
cache:
|
|
88
|
+
enabled: true
|
|
89
|
+
ttlMs: 3600000 # 缓存有效期 1 小时
|
|
90
|
+
maxEntries: 1000 # 最大缓存条数
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 渠道配置
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
spec:
|
|
97
|
+
channels:
|
|
98
|
+
- type: web
|
|
99
|
+
port: 3000
|
|
100
|
+
config:
|
|
101
|
+
cors: true
|
|
102
|
+
sse: true # 启用 SSE 流式响应
|
|
103
|
+
|
|
104
|
+
- type: telegram
|
|
105
|
+
config:
|
|
106
|
+
token: ${TELEGRAM_BOT_TOKEN}
|
|
107
|
+
|
|
108
|
+
- type: wechat
|
|
109
|
+
config:
|
|
110
|
+
appId: ${WECHAT_APP_ID}
|
|
111
|
+
appSecret: ${WECHAT_APP_SECRET}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 记忆配置
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
spec:
|
|
118
|
+
memory:
|
|
119
|
+
shortTerm: true # 对话上下文记忆
|
|
120
|
+
longTerm: true # 跨会话长期记忆
|
|
121
|
+
provider: deepbrain # 长期记忆后端
|
|
122
|
+
config:
|
|
123
|
+
collection: my-kb # 知识库集合名称
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## DTV 信任配置
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
spec:
|
|
130
|
+
dtv:
|
|
131
|
+
trust:
|
|
132
|
+
level: sandbox # sandbox | verified | certified | listed
|
|
133
|
+
value:
|
|
134
|
+
metrics: [response_time, satisfaction_score]
|
|
135
|
+
```
|
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# 部署指南
|
|
2
|
+
|
|
3
|
+
## 本地开发
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# 热重载开发模式
|
|
7
|
+
opc dev
|
|
8
|
+
|
|
9
|
+
# 普通启动
|
|
10
|
+
opc run
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Docker 部署
|
|
14
|
+
|
|
15
|
+
每个 `opc init` 创建的项目都自带 `Dockerfile` 和 `docker-compose.yml`:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
docker compose up -d
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 自定义 Docker 配置
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
# docker-compose.yml
|
|
25
|
+
services:
|
|
26
|
+
agent:
|
|
27
|
+
build: .
|
|
28
|
+
ports:
|
|
29
|
+
- "3000:3000"
|
|
30
|
+
env_file: .env
|
|
31
|
+
restart: unless-stopped
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 部署到 OpenClaw
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 部署
|
|
38
|
+
opc deploy --target openclaw
|
|
39
|
+
|
|
40
|
+
# 部署并注册到配置
|
|
41
|
+
opc deploy --target openclaw --install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 部署到 Hermes 云
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 直接部署
|
|
48
|
+
opc deploy --target hermes
|
|
49
|
+
|
|
50
|
+
# 生成部署文件到指定目录
|
|
51
|
+
opc deploy --target hermes --output ./my-deploy
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 环境变量
|
|
55
|
+
|
|
56
|
+
在 `.env` 文件中配置:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# 大语言模型配置
|
|
60
|
+
OPC_LLM_API_KEY=sk-xxx
|
|
61
|
+
OPC_LLM_BASE_URL=https://api.deepseek.com/v1
|
|
62
|
+
OPC_LLM_MODEL=deepseek-chat
|
|
63
|
+
|
|
64
|
+
# Telegram 机器人(可选)
|
|
65
|
+
TELEGRAM_BOT_TOKEN=xxx
|
|
66
|
+
|
|
67
|
+
# 微信公众号(可选)
|
|
68
|
+
WECHAT_APP_ID=xxx
|
|
69
|
+
WECHAT_APP_SECRET=xxx
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 上线检查清单
|
|
73
|
+
|
|
74
|
+
- [ ] 在 `.env` 中配置正确的 API Key
|
|
75
|
+
- [ ] 在 `oad.yaml` 中配置限流策略
|
|
76
|
+
- [ ] 开启缓存以降低 API 成本
|
|
77
|
+
- [ ] 配置监控和告警
|
|
78
|
+
- [ ] 运行 `opc test` 确保测试通过
|
|
79
|
+
- [ ] 检查 DTV 信任等级设置
|
|
80
|
+
- [ ] 配置 CORS 和安全头
|
|
81
|
+
- [ ] 准备回滚方案
|
|
@@ -1,58 +1,82 @@
|
|
|
1
|
-
# 快速开始
|
|
2
|
-
|
|
3
|
-
## 安装
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
npm install -g opc-agent
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
opc
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
# 快速开始
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install -g opc-agent
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 创建第一个智能体
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 交互式创建(会让你选模板和配置)
|
|
13
|
+
opc init my-agent
|
|
14
|
+
cd my-agent
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
或者直接用模板:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
opc init my-bot --template customer-service
|
|
21
|
+
opc init my-bot --template sales-assistant
|
|
22
|
+
opc init my-bot --template knowledge-base
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 配置
|
|
26
|
+
|
|
27
|
+
编辑 `.env` 文件,填入你的大语言模型 API Key:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
OPC_LLM_API_KEY=your-api-key
|
|
31
|
+
OPC_LLM_BASE_URL=https://api.deepseek.com/v1 # DeepSeek
|
|
32
|
+
OPC_LLM_MODEL=deepseek-chat
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
支持的供应商和对应的 Base URL:
|
|
36
|
+
|
|
37
|
+
| 供应商 | Base URL | 推荐模型 |
|
|
38
|
+
|--------|----------|---------|
|
|
39
|
+
| DeepSeek | `https://api.deepseek.com/v1` | `deepseek-chat` |
|
|
40
|
+
| 通义千问 | `https://dashscope.aliyuncs.com/compatible-mode/v1` | `qwen-plus` |
|
|
41
|
+
| OpenAI | `https://api.openai.com/v1` | `gpt-4o-mini` |
|
|
42
|
+
| Ollama (本地) | `http://localhost:11434/v1` | `llama3` |
|
|
43
|
+
|
|
44
|
+
## 启动
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 启动 Web 对话服务
|
|
48
|
+
opc run
|
|
49
|
+
|
|
50
|
+
# 或者用命令行对话
|
|
51
|
+
opc chat
|
|
52
|
+
|
|
53
|
+
# 开发模式(改代码自动重启)
|
|
54
|
+
opc dev
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
访问 `http://localhost:3000` 即可看到对话界面。
|
|
58
|
+
|
|
59
|
+
## 校验配置
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
opc build
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 运行测试
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
opc test
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 查看数据分析
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
opc analytics
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 下一步
|
|
78
|
+
|
|
79
|
+
- [核心概念](/zh/guide/concepts) — 理解 OAD、技能、渠道等概念
|
|
80
|
+
- [模板列表](/zh/guide/templates) — 查看全部 12 个场景模板
|
|
81
|
+
- [配置详解](/zh/guide/configuration) — OAD 文件的完整配置项
|
|
82
|
+
- [部署指南](/zh/guide/deployment) — Docker、OpenClaw、Hermes 部署
|
|
@@ -1,22 +1,84 @@
|
|
|
1
|
-
# 模板
|
|
2
|
-
|
|
3
|
-
OPC Agent
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
|
8
|
-
|
|
9
|
-
| `
|
|
10
|
-
| `
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
13
|
-
| `
|
|
14
|
-
| `
|
|
15
|
-
| `
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
# 模板
|
|
2
|
+
|
|
3
|
+
OPC Agent 提供 12 个开箱即用的场景模板,覆盖常见的企业智能体需求。
|
|
4
|
+
|
|
5
|
+
## 模板列表
|
|
6
|
+
|
|
7
|
+
| 模板 | 说明 | 适用场景 |
|
|
8
|
+
|------|------|---------|
|
|
9
|
+
| `customer-service` | 客服智能体 | FAQ 自动回答 + 转人工 |
|
|
10
|
+
| `sales-assistant` | 销售助手 | 产品问答 + 线索捕获 + 预约 |
|
|
11
|
+
| `knowledge-base` | 知识库问答 | 基于文档的 RAG 语义检索 |
|
|
12
|
+
| `code-reviewer` | 代码审查 | Bug 检测 + 代码风格检查 |
|
|
13
|
+
| `hr-recruiter` | HR 招聘助手 | 简历筛选 + 面试安排 |
|
|
14
|
+
| `project-manager` | 项目管理 | 任务跟踪 + 会议纪要 |
|
|
15
|
+
| `content-writer` | 内容创作 | 博客写作 + 社媒运营 + SEO |
|
|
16
|
+
| `legal-assistant` | 法务助手 | 合同审查 + 合规检查 |
|
|
17
|
+
| `financial-advisor` | 财务顾问 | 预算管理 + 支出分析 |
|
|
18
|
+
| `executive-assistant` | 行政助理 | 日程管理 + 邮件处理 |
|
|
19
|
+
| `data-analyst` | 数据分析师 | SQL 查询 + 数据可视化 |
|
|
20
|
+
| `teacher` | 教学助手 | 课程设计 + 出题 + 互动 |
|
|
21
|
+
|
|
22
|
+
## 使用模板
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 创建时指定模板
|
|
26
|
+
opc init my-agent --template customer-service
|
|
27
|
+
|
|
28
|
+
# 或者用简写
|
|
29
|
+
opc init my-agent -t sales-assistant
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 客服智能体详解
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
# customer-service/oad.yaml
|
|
36
|
+
apiVersion: opc/v1
|
|
37
|
+
kind: Agent
|
|
38
|
+
metadata:
|
|
39
|
+
name: customer-service
|
|
40
|
+
version: 1.0.0
|
|
41
|
+
description: "客服智能体:FAQ 查询 + 人工转接"
|
|
42
|
+
spec:
|
|
43
|
+
provider:
|
|
44
|
+
default: deepseek
|
|
45
|
+
model: deepseek-chat
|
|
46
|
+
systemPrompt: |
|
|
47
|
+
你是一个友好、专业的客服助手。
|
|
48
|
+
帮助客户解答产品、订单、物流、退换货等问题。
|
|
49
|
+
回答要简洁、有帮助、有同理心。
|
|
50
|
+
skills:
|
|
51
|
+
- name: faq-lookup
|
|
52
|
+
description: "FAQ 知识库查询"
|
|
53
|
+
- name: human-handoff
|
|
54
|
+
description: "转接人工客服"
|
|
55
|
+
channels:
|
|
56
|
+
- type: web
|
|
57
|
+
port: 3000
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 自定义模板
|
|
61
|
+
|
|
62
|
+
你可以基于现有模板修改,也可以从头创建:
|
|
63
|
+
|
|
64
|
+
1. 编写 `oad.yaml` 定义智能体
|
|
65
|
+
2. 继承 `BaseSkill` 实现自定义技能
|
|
66
|
+
3. 将 `oad.yaml` + `README.md` 打包成一个目录
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { BaseSkill } from 'opc-agent';
|
|
70
|
+
import type { AgentContext, Message, SkillResult } from 'opc-agent';
|
|
71
|
+
|
|
72
|
+
export class MySkill extends BaseSkill {
|
|
73
|
+
name = 'my-skill';
|
|
74
|
+
description = '我的自定义技能';
|
|
75
|
+
|
|
76
|
+
async execute(context: AgentContext, message: Message): Promise<SkillResult> {
|
|
77
|
+
// 你的技能逻辑
|
|
78
|
+
if (message.content.includes('关键词')) {
|
|
79
|
+
return this.match('这是我的回答', 0.9);
|
|
80
|
+
}
|
|
81
|
+
return this.noMatch();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|