opc-agent 1.1.0 → 1.1.1
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 +232 -88
- package/README.zh-CN.md +334 -56
- package/dist/cli.js +1 -32
- package/dist/i18n/index.js +60 -9
- package/docs/.vitepress/config.ts +13 -2
- package/docs/zh/api/cli.md +54 -0
- package/docs/zh/api/oad-schema.md +86 -2
- package/docs/zh/api/sdk.md +102 -0
- package/docs/zh/guide/concepts.md +90 -14
- package/docs/zh/guide/configuration.md +109 -13
- package/docs/zh/guide/deployment.md +79 -1
- package/docs/zh/guide/getting-started.md +41 -17
- package/docs/zh/guide/templates.md +79 -17
- package/docs/zh/guide/testing.md +75 -5
- package/docs/zh/index.md +13 -13
- package/package.json +1 -1
- package/src/cli.ts +1 -35
- package/src/i18n/index.ts +60 -9
- package/tests/i18n.test.ts +1 -1
|
@@ -1,22 +1,84 @@
|
|
|
1
1
|
# 模板
|
|
2
2
|
|
|
3
|
-
OPC Agent
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
|
8
|
-
|
|
9
|
-
| `
|
|
10
|
-
| `
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
13
|
-
| `
|
|
14
|
-
| `
|
|
15
|
-
| `
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
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
|
+
## 使用模板
|
|
19
23
|
|
|
20
24
|
```bash
|
|
21
|
-
|
|
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
|
+
}
|
|
22
84
|
```
|
package/docs/zh/guide/testing.md
CHANGED
|
@@ -1,18 +1,88 @@
|
|
|
1
1
|
# 测试
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 概览
|
|
4
|
+
|
|
5
|
+
OPC Agent 内置了测试框架。你可以在 `oad.yaml` 或单独的 `tests.yaml` 中定义测试用例,用 `opc test` 一键运行。
|
|
6
|
+
|
|
7
|
+
## 在 OAD 中定义测试
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
spec:
|
|
11
|
+
testing:
|
|
12
|
+
cases:
|
|
13
|
+
- name: 问候测试
|
|
14
|
+
input: "你好!"
|
|
15
|
+
expect:
|
|
16
|
+
contains: ["你好", "帮"]
|
|
17
|
+
maxLatencyMs: 5000
|
|
18
|
+
|
|
19
|
+
- name: 产品咨询
|
|
20
|
+
input: "你们怎么收费?"
|
|
21
|
+
expect:
|
|
22
|
+
contains: ["价格", "套餐"]
|
|
23
|
+
notContains: ["error"]
|
|
24
|
+
|
|
25
|
+
- name: 空输入
|
|
26
|
+
input: ""
|
|
27
|
+
expect:
|
|
28
|
+
maxLatencyMs: 2000
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 独立测试文件
|
|
32
|
+
|
|
33
|
+
在 `oad.yaml` 同目录创建 `tests.yaml`:
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
cases:
|
|
37
|
+
- name: 冒烟测试
|
|
38
|
+
input: "你好"
|
|
39
|
+
expect:
|
|
40
|
+
maxLatencyMs: 10000
|
|
41
|
+
|
|
42
|
+
- name: FAQ 验证
|
|
43
|
+
input: "退货政策是什么?"
|
|
44
|
+
expect:
|
|
45
|
+
contains: ["退货", "退款"]
|
|
46
|
+
```
|
|
4
47
|
|
|
5
48
|
## 运行测试
|
|
6
49
|
|
|
7
50
|
```bash
|
|
51
|
+
# 运行测试
|
|
8
52
|
opc test
|
|
53
|
+
|
|
54
|
+
# JSON 格式输出
|
|
9
55
|
opc test --json
|
|
56
|
+
|
|
57
|
+
# 指定 OAD 文件
|
|
10
58
|
opc test -f my-agent.yaml
|
|
59
|
+
|
|
60
|
+
# 监听模式(改了代码自动重跑)
|
|
61
|
+
opc test --watch
|
|
11
62
|
```
|
|
12
63
|
|
|
13
|
-
##
|
|
64
|
+
## 测试报告
|
|
14
65
|
|
|
15
|
-
```bash
|
|
16
|
-
opc deploy --target openclaw
|
|
17
|
-
opc deploy --target hermes
|
|
18
66
|
```
|
|
67
|
+
═══════════════════════════════════════════
|
|
68
|
+
OPC Agent 测试报告
|
|
69
|
+
═══════════════════════════════════════════
|
|
70
|
+
|
|
71
|
+
✔ [通过] 问候测试 (245ms)
|
|
72
|
+
✔ [通过] 产品咨询 (312ms)
|
|
73
|
+
✘ [失败] 空输入 (5120ms)
|
|
74
|
+
→ 延迟 5120ms 超过上限 2000ms
|
|
75
|
+
|
|
76
|
+
───────────────────────────────────────────
|
|
77
|
+
总计: 3 通过: 2 失败: 1 耗时: 5677ms
|
|
78
|
+
───────────────────────────────────────────
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 断言类型
|
|
82
|
+
|
|
83
|
+
| 断言 | 说明 |
|
|
84
|
+
|------|------|
|
|
85
|
+
| `contains` | 回复必须包含这些字符串(不区分大小写) |
|
|
86
|
+
| `notContains` | 回复不能包含这些字符串 |
|
|
87
|
+
| `toolCalled` | 指定的工具必须被调用 |
|
|
88
|
+
| `maxLatencyMs` | 响应必须在指定时间内完成 |
|
package/docs/zh/index.md
CHANGED
|
@@ -3,7 +3,7 @@ layout: home
|
|
|
3
3
|
hero:
|
|
4
4
|
name: OPC Agent
|
|
5
5
|
text: 开放智能体框架
|
|
6
|
-
tagline:
|
|
6
|
+
tagline: 构建、测试、运行企业级 AI 智能体
|
|
7
7
|
actions:
|
|
8
8
|
- theme: brand
|
|
9
9
|
text: 快速开始
|
|
@@ -12,16 +12,16 @@ hero:
|
|
|
12
12
|
text: GitHub
|
|
13
13
|
link: https://github.com/Deepleaper/opc-agent
|
|
14
14
|
features:
|
|
15
|
-
- title:
|
|
16
|
-
details:
|
|
17
|
-
- title:
|
|
18
|
-
details:
|
|
19
|
-
- title:
|
|
20
|
-
details: Web、Telegram、Slack
|
|
21
|
-
- title: 🧪
|
|
22
|
-
details: 在 OAD
|
|
23
|
-
- title:
|
|
24
|
-
details:
|
|
25
|
-
- title:
|
|
26
|
-
details:
|
|
15
|
+
- title: ⚡ 30 秒上手
|
|
16
|
+
details: 两条命令创建智能体,开箱即用,支持 12 个场景模板
|
|
17
|
+
- title: 📋 OAD 声明式定义
|
|
18
|
+
details: 用 YAML 文件定义智能体的一切:模型、技能、渠道、安全策略
|
|
19
|
+
- title: 📡 多渠道部署
|
|
20
|
+
details: Web、Telegram、Slack、微信公众号、飞书、WebSocket,一套代码到处运行
|
|
21
|
+
- title: 🧪 内置测试框架
|
|
22
|
+
details: 在 OAD 文件中定义测试用例,opc test 一键验证智能体行为
|
|
23
|
+
- title: 🔌 多模型支持
|
|
24
|
+
details: DeepSeek、通义千问、OpenAI、Anthropic、Ollama,不绑定任何一家
|
|
25
|
+
- title: 🧠 知识库 RAG
|
|
26
|
+
details: 添加文档自动构建知识库,智能体回答时语义检索增强
|
|
27
27
|
---
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -520,41 +520,7 @@ program
|
|
|
520
520
|
});
|
|
521
521
|
});
|
|
522
522
|
|
|
523
|
-
//
|
|
524
|
-
|
|
525
|
-
program
|
|
526
|
-
.command('publish')
|
|
527
|
-
.description('Validate and package for OPC Registry')
|
|
528
|
-
.option('-f, --file <file>', 'OAD file', 'oad.yaml')
|
|
529
|
-
.action(async (opts: { file: string }) => {
|
|
530
|
-
try {
|
|
531
|
-
const runtime = new AgentRuntime();
|
|
532
|
-
const config = await runtime.loadConfig(opts.file);
|
|
533
|
-
const trust = config.spec.dtv?.trust?.level ?? 'sandbox';
|
|
534
|
-
|
|
535
|
-
console.log(`\n${icon.package} Publishing: ${color.bold(config.metadata.name)} v${config.metadata.version}`);
|
|
536
|
-
console.log(` ${icon.success} OAD validation passed`);
|
|
537
|
-
|
|
538
|
-
const manifest = {
|
|
539
|
-
name: config.metadata.name,
|
|
540
|
-
version: config.metadata.version,
|
|
541
|
-
description: config.metadata.description,
|
|
542
|
-
author: config.metadata.author,
|
|
543
|
-
license: config.metadata.license,
|
|
544
|
-
trust,
|
|
545
|
-
channels: config.spec.channels.map((c: any) => c.type),
|
|
546
|
-
skills: config.spec.skills.map((s: any) => s.name),
|
|
547
|
-
publishedAt: new Date().toISOString(),
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
fs.writeFileSync('opc-manifest.json', JSON.stringify(manifest, null, 2));
|
|
551
|
-
console.log(` ${icon.file} Generated opc-manifest.json`);
|
|
552
|
-
console.log(`\n🚧 OPC Registry is coming soon. Manifest saved locally.\n`);
|
|
553
|
-
} catch (err) {
|
|
554
|
-
console.error(`${icon.error} Publish failed:`, err instanceof Error ? err.message : err);
|
|
555
|
-
process.exit(1);
|
|
556
|
-
}
|
|
557
|
-
});
|
|
523
|
+
// (publish command moved to marketplace section below)
|
|
558
524
|
|
|
559
525
|
// ── Deploy command ───────────────────────────────────────────
|
|
560
526
|
|
package/src/i18n/index.ts
CHANGED
|
@@ -18,16 +18,33 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
18
18
|
'agent.notUnderstood': 'I\'m not sure I understand. Could you rephrase?',
|
|
19
19
|
'agent.handoff': 'Let me connect you with a human agent.',
|
|
20
20
|
'cli.init.success': 'Created agent project: {name}',
|
|
21
|
+
'cli.init.prompt.name': 'Agent name:',
|
|
22
|
+
'cli.init.prompt.template': 'Choose a template:',
|
|
23
|
+
'cli.init.prompt.provider': 'Choose an LLM provider:',
|
|
21
24
|
'cli.build.success': 'Build successful: {name} v{version}',
|
|
22
25
|
'cli.test.pass': 'All tests passed',
|
|
23
26
|
'cli.test.fail': '{count} test(s) failed',
|
|
27
|
+
'cli.run.starting': 'Starting agent "{name}"...',
|
|
28
|
+
'cli.run.listening': 'Agent "{name}" is running at http://localhost:{port}',
|
|
29
|
+
'cli.deploy.success': 'Deployed "{name}" to {target}',
|
|
30
|
+
'cli.deploy.error': 'Deploy failed: {error}',
|
|
31
|
+
'cli.validate.success': 'OAD validation passed',
|
|
32
|
+
'cli.validate.error': 'OAD validation failed: {error}',
|
|
33
|
+
'cli.analytics.title': 'Agent Analytics',
|
|
34
|
+
'cli.analytics.noData': 'No analytics data yet',
|
|
24
35
|
'cli.stats.title': 'Agent Analytics',
|
|
25
36
|
'cli.stats.messages': 'Messages Processed',
|
|
26
37
|
'cli.stats.avgTime': 'Avg Response Time',
|
|
27
38
|
'cli.stats.errors': 'Errors',
|
|
28
39
|
'cli.stats.uptime': 'Uptime',
|
|
40
|
+
'cli.chat.welcome': 'Chat with your agent. Type "exit" to quit.',
|
|
41
|
+
'cli.dev.watching': 'Watching for changes...',
|
|
42
|
+
'cli.publish.success': 'Published "{name}" v{version}',
|
|
29
43
|
'plugin.loaded': 'Plugin "{name}" loaded',
|
|
30
44
|
'plugin.error': 'Plugin "{name}" failed: {error}',
|
|
45
|
+
'kb.added': 'Added "{file}" to knowledge base',
|
|
46
|
+
'kb.searchResults': '{count} results found',
|
|
47
|
+
'kb.noResults': 'No results found',
|
|
31
48
|
'web.title': 'OPC Agent',
|
|
32
49
|
'web.chat.placeholder': 'Type a message...',
|
|
33
50
|
'web.chat.send': 'Send',
|
|
@@ -50,22 +67,39 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
50
67
|
'zh-CN': {
|
|
51
68
|
'agent.started': '智能体 "{name}" 启动成功',
|
|
52
69
|
'agent.stopped': '智能体 "{name}" 已停止',
|
|
53
|
-
'agent.error': '
|
|
54
|
-
'agent.greeting': '
|
|
55
|
-
'agent.farewell': '
|
|
56
|
-
'agent.notUnderstood': '
|
|
57
|
-
'agent.handoff': '
|
|
58
|
-
'cli.init.success': '
|
|
59
|
-
'cli.
|
|
70
|
+
'agent.error': '发生错误:{error}',
|
|
71
|
+
'agent.greeting': '你好!有什么可以帮你的?',
|
|
72
|
+
'agent.farewell': '再见!祝你愉快。',
|
|
73
|
+
'agent.notUnderstood': '抱歉,我没太理解你的意思。能换个方式描述一下吗?',
|
|
74
|
+
'agent.handoff': '我来帮你转接人工客服。',
|
|
75
|
+
'cli.init.success': '已创建智能体项目:{name}',
|
|
76
|
+
'cli.init.prompt.name': '智能体名称:',
|
|
77
|
+
'cli.init.prompt.template': '选择一个模板:',
|
|
78
|
+
'cli.init.prompt.provider': '选择大语言模型供应商:',
|
|
79
|
+
'cli.build.success': '构建成功:{name} v{version}',
|
|
60
80
|
'cli.test.pass': '所有测试通过',
|
|
61
81
|
'cli.test.fail': '{count} 个测试失败',
|
|
62
|
-
'cli.
|
|
82
|
+
'cli.run.starting': '正在启动智能体 "{name}"...',
|
|
83
|
+
'cli.run.listening': '智能体 "{name}" 已在 http://localhost:{port} 上运行',
|
|
84
|
+
'cli.deploy.success': '已将 "{name}" 部署到 {target}',
|
|
85
|
+
'cli.deploy.error': '部署失败:{error}',
|
|
86
|
+
'cli.validate.success': 'OAD 配置校验通过',
|
|
87
|
+
'cli.validate.error': 'OAD 配置校验失败:{error}',
|
|
88
|
+
'cli.analytics.title': '智能体数据分析',
|
|
89
|
+
'cli.analytics.noData': '暂无分析数据',
|
|
90
|
+
'cli.stats.title': '智能体数据分析',
|
|
63
91
|
'cli.stats.messages': '已处理消息',
|
|
64
92
|
'cli.stats.avgTime': '平均响应时间',
|
|
65
93
|
'cli.stats.errors': '错误数',
|
|
66
94
|
'cli.stats.uptime': '运行时间',
|
|
95
|
+
'cli.chat.welcome': '开始和智能体对话吧。输入 "exit" 退出。',
|
|
96
|
+
'cli.dev.watching': '正在监听文件变更...',
|
|
97
|
+
'cli.publish.success': '已发布 "{name}" v{version}',
|
|
67
98
|
'plugin.loaded': '插件 "{name}" 已加载',
|
|
68
|
-
'plugin.error': '插件 "{name}"
|
|
99
|
+
'plugin.error': '插件 "{name}" 出错:{error}',
|
|
100
|
+
'kb.added': '已将 "{file}" 添加到知识库',
|
|
101
|
+
'kb.searchResults': '找到 {count} 条结果',
|
|
102
|
+
'kb.noResults': '未找到相关结果',
|
|
69
103
|
'web.title': 'OPC 智能体',
|
|
70
104
|
'web.chat.placeholder': '输入消息...',
|
|
71
105
|
'web.chat.send': '发送',
|
|
@@ -94,16 +128,33 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
94
128
|
'agent.notUnderstood': '申し訳ございません、理解できませんでした。別の言い方でお願いできますか?',
|
|
95
129
|
'agent.handoff': 'オペレーターにおつなぎします。',
|
|
96
130
|
'cli.init.success': 'エージェントプロジェクトを作成しました: {name}',
|
|
131
|
+
'cli.init.prompt.name': 'エージェント名:',
|
|
132
|
+
'cli.init.prompt.template': 'テンプレートを選択:',
|
|
133
|
+
'cli.init.prompt.provider': 'LLMプロバイダーを選択:',
|
|
97
134
|
'cli.build.success': 'ビルド成功: {name} v{version}',
|
|
98
135
|
'cli.test.pass': '全テスト合格',
|
|
99
136
|
'cli.test.fail': '{count} 件のテストが失敗しました',
|
|
137
|
+
'cli.run.starting': 'エージェント「{name}」を起動中...',
|
|
138
|
+
'cli.run.listening': 'エージェント「{name}」が http://localhost:{port} で稼働中',
|
|
139
|
+
'cli.deploy.success': '「{name}」を {target} にデプロイしました',
|
|
140
|
+
'cli.deploy.error': 'デプロイ失敗: {error}',
|
|
141
|
+
'cli.validate.success': 'OADバリデーション成功',
|
|
142
|
+
'cli.validate.error': 'OADバリデーション失敗: {error}',
|
|
143
|
+
'cli.analytics.title': 'エージェント分析',
|
|
144
|
+
'cli.analytics.noData': '分析データがありません',
|
|
100
145
|
'cli.stats.title': 'エージェント分析',
|
|
101
146
|
'cli.stats.messages': '処理済みメッセージ',
|
|
102
147
|
'cli.stats.avgTime': '平均応答時間',
|
|
103
148
|
'cli.stats.errors': 'エラー数',
|
|
104
149
|
'cli.stats.uptime': '稼働時間',
|
|
150
|
+
'cli.chat.welcome': 'エージェントとチャットしましょう。"exit"で終了。',
|
|
151
|
+
'cli.dev.watching': 'ファイル変更を監視中...',
|
|
152
|
+
'cli.publish.success': '「{name}」v{version} を公開しました',
|
|
105
153
|
'plugin.loaded': 'プラグイン「{name}」を読み込みました',
|
|
106
154
|
'plugin.error': 'プラグイン「{name}」でエラー: {error}',
|
|
155
|
+
'kb.added': '「{file}」をナレッジベースに追加しました',
|
|
156
|
+
'kb.searchResults': '{count} 件の結果が見つかりました',
|
|
157
|
+
'kb.noResults': '結果が見つかりませんでした',
|
|
107
158
|
'web.title': 'OPC エージェント',
|
|
108
159
|
'web.chat.placeholder': 'メッセージを入力...',
|
|
109
160
|
'web.chat.send': '送信',
|
package/tests/i18n.test.ts
CHANGED