opc-agent 1.0.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.
@@ -49,6 +49,7 @@ export default defineConfig({
49
49
  zh: {
50
50
  label: '中文',
51
51
  lang: 'zh-CN',
52
+ description: '开放智能体框架 — 构建、测试、运行企业级 AI 智能体',
52
53
  themeConfig: {
53
54
  nav: [
54
55
  { text: '指南', link: '/zh/guide/getting-started' },
@@ -58,7 +59,7 @@ export default defineConfig({
58
59
  sidebar: {
59
60
  '/zh/guide/': [
60
61
  {
61
- text: '介绍',
62
+ text: '入门',
62
63
  items: [
63
64
  { text: '快速开始', link: '/zh/guide/getting-started' },
64
65
  { text: '核心概念', link: '/zh/guide/concepts' },
@@ -74,6 +75,16 @@ export default defineConfig({
74
75
  ],
75
76
  },
76
77
  ],
78
+ '/zh/api/': [
79
+ {
80
+ text: '参考',
81
+ items: [
82
+ { text: 'OAD Schema', link: '/zh/api/oad-schema' },
83
+ { text: 'CLI 命令', link: '/zh/api/cli' },
84
+ { text: 'SDK', link: '/zh/api/sdk' },
85
+ ],
86
+ },
87
+ ],
77
88
  },
78
89
  },
79
90
  },
@@ -86,7 +97,7 @@ export default defineConfig({
86
97
  ],
87
98
  footer: {
88
99
  message: 'Released under the Apache-2.0 License.',
89
- copyright: 'Copyright © 2025 Deepleaper',
100
+ copyright: 'Copyright © 2025 Deepleaper 跃盟科技',
90
101
  },
91
102
  },
92
103
  });
@@ -0,0 +1,54 @@
1
+ # CLI 命令参考
2
+
3
+ ## 完整命令列表
4
+
5
+ | 命令 | 说明 |
6
+ |------|------|
7
+ | `opc init [name]` | 创建新智能体项目(交互式) |
8
+ | `opc create <name>` | 从模板快速创建 |
9
+ | `opc run` | 启动智能体(Web 服务) |
10
+ | `opc chat` | 命令行交互对话 |
11
+ | `opc test` | 运行测试用例 |
12
+ | `opc analytics` | 查看使用分析 |
13
+ | `opc info` | 查看智能体信息 |
14
+ | `opc build` | 校验 OAD 配置 |
15
+ | `opc dev` | 热重载开发模式 |
16
+ | `opc deploy` | 部署智能体 |
17
+ | `opc publish` | 发布到市场 |
18
+ | `opc install <source>` | 从包安装智能体 |
19
+ | `opc search <query>` | 搜索 OPC 市场 |
20
+ | `opc stats` | 查看运行时统计 |
21
+ | `opc kb add <file>` | 添加知识库文件 |
22
+ | `opc kb search <query>` | 搜索知识库 |
23
+ | `opc tool list` | 列出 MCP 工具 |
24
+ | `opc workflow run <name>` | 运行工作流 |
25
+ | `opc version-mgmt list` | 列出保存的版本 |
26
+
27
+ ## 通用选项
28
+
29
+ - `-f, --file <file>` — OAD 文件路径(默认:`oad.yaml`)
30
+ - `-t, --template <name>` — 模板名称
31
+ - `-p, --port <port>` — 端口覆盖
32
+ - `--json` — JSON 格式输出(用于 test/analytics)
33
+
34
+ ## 常用示例
35
+
36
+ ```bash
37
+ # 用模板创建项目
38
+ opc init my-bot -t teacher
39
+
40
+ # 运行测试,输出 JSON
41
+ opc test --json
42
+
43
+ # 查看分析数据
44
+ opc analytics
45
+
46
+ # 部署到 OpenClaw
47
+ opc deploy --target openclaw --install
48
+
49
+ # 添加文件到知识库
50
+ opc kb add ./docs/product-manual.pdf
51
+
52
+ # 搜索知识库
53
+ opc kb search "退货政策"
54
+ ```
@@ -1,3 +1,87 @@
1
- # OAD Schema
1
+ # OAD Schema v1 规范
2
2
 
3
- 详细说明请参考 [英文版](/api/oad-schema)
3
+ **OAD**(Open Agent Definition)是智能体的声明式定义格式,支持 YAML 和 JSON
4
+
5
+ ## 完整 Schema
6
+
7
+ ```yaml
8
+ apiVersion: opc/v1 # 必填。API 版本,目前固定为 "opc/v1"
9
+ kind: Agent # 必填。资源类型,目前固定为 "Agent"
10
+
11
+ metadata:
12
+ name: string # 必填。智能体标识名
13
+ version: string # 语义版本号,默认 "1.0.0"
14
+ description: string # 可选。人类可读的描述
15
+ author: string # 可选。作者
16
+ license: string # 默认 "Apache-2.0"
17
+ marketplace: # 可选。市场配置
18
+ certified: boolean # 默认 false
19
+ category: string # 如 "customer-service"
20
+
21
+ spec:
22
+ provider: # 大语言模型供应商
23
+ default: string # 默认供应商,默认 "deepseek"
24
+ allowed: string[] # 允许的供应商列表,默认 ["openai", "deepseek", "qwen"]
25
+ model: string # 模型名称,默认 "deepseek-chat"
26
+ systemPrompt: string # 系统提示词
27
+
28
+ skills: # 技能列表
29
+ - name: string # 技能标识
30
+ description: string # 技能说明
31
+ config: object # 可选。技能配置
32
+
33
+ channels: # 通信渠道
34
+ - type: web|websocket|telegram|slack|wechat|feishu|email|voice|webhook
35
+ port: number # Web 渠道的端口
36
+ config: object # 可选。渠道配置
37
+
38
+ memory:
39
+ shortTerm: boolean # 开启对话记忆,默认 true
40
+ longTerm: boolean # 开启持久化记忆,默认 false
41
+ provider: string # 记忆后端(可选)
42
+
43
+ testing:
44
+ cases: # 测试用例
45
+ - name: string
46
+ input: string
47
+ expect:
48
+ contains: string[]
49
+ notContains: string[]
50
+ toolCalled: string[]
51
+ maxLatencyMs: number
52
+
53
+ rateLimits:
54
+ perUser:
55
+ maxRequests: number
56
+ windowMs: number
57
+ perProvider:
58
+ maxRequests: number
59
+ windowMs: number
60
+
61
+ cache:
62
+ enabled: boolean
63
+ ttlMs: number
64
+ maxEntries: number
65
+
66
+ dtv:
67
+ trust:
68
+ level: sandbox|verified|certified|listed # 默认 "sandbox"
69
+ value:
70
+ metrics: string[] # 要追踪的指标,默认 []
71
+ ```
72
+
73
+ ## 校验
74
+
75
+ OAD 文件使用 Zod schema 校验。用 CLI 校验:
76
+
77
+ ```bash
78
+ opc build -f oad.yaml
79
+ ```
80
+
81
+ 或在代码中校验:
82
+
83
+ ```typescript
84
+ import { validateOAD } from 'opc-agent';
85
+
86
+ const config = validateOAD(yamlData);
87
+ ```
@@ -0,0 +1,102 @@
1
+ # SDK 参考
2
+
3
+ ## 核心类
4
+
5
+ ### AgentRuntime — 智能体运行时
6
+
7
+ ```typescript
8
+ import { AgentRuntime } from 'opc-agent';
9
+
10
+ const runtime = new AgentRuntime();
11
+ await runtime.loadConfig('oad.yaml'); // 加载 OAD 配置
12
+ const agent = await runtime.initialize(); // 初始化智能体
13
+ await runtime.start(); // 启动服务
14
+ ```
15
+
16
+ ### AnalyticsEngine — 分析引擎
17
+
18
+ ```typescript
19
+ import { AnalyticsEngine } from 'opc-agent';
20
+
21
+ const engine = new AnalyticsEngine('.');
22
+ engine.trackMessage('user-1', 250, 100, 50); // 追踪消息
23
+ engine.trackToolUse('search', true, 120); // 追踪工具调用
24
+ const stats = engine.getStats(); // 获取统计数据
25
+ ```
26
+
27
+ ### RateLimiter — 限流器
28
+
29
+ ```typescript
30
+ import { RateLimiter } from 'opc-agent';
31
+
32
+ const limiter = new RateLimiter({
33
+ userLimit: { maxRequests: 60, windowMs: 60000 },
34
+ providerLimit: { maxRequests: 100, windowMs: 60000 },
35
+ });
36
+
37
+ await limiter.acquire('user-1', 'openai'); // 获取令牌,超限时抛出异常
38
+ ```
39
+
40
+ ### LLMCache — LLM 响应缓存
41
+
42
+ ```typescript
43
+ import { LLMCache } from 'opc-agent';
44
+
45
+ const cache = new LLMCache({ ttlMs: 3600000 }); // 1 小时过期
46
+ const key = LLMCache.makeKey(messages, systemPrompt);
47
+ const cached = cache.get(key);
48
+ if (!cached) {
49
+ const response = await callLLM(messages);
50
+ cache.set(key, response);
51
+ }
52
+ ```
53
+
54
+ ### KnowledgeBase — 知识库
55
+
56
+ ```typescript
57
+ import { KnowledgeBase } from 'opc-agent';
58
+
59
+ const kb = new KnowledgeBase('./docs');
60
+ await kb.addFile('产品手册.pdf'); // 添加文件
61
+ await kb.addFile('FAQ.md');
62
+ const results = await kb.search('退货政策'); // 语义搜索
63
+ ```
64
+
65
+ ### Orchestrator — 多智能体编排
66
+
67
+ ```typescript
68
+ import { Orchestrator } from 'opc-agent';
69
+
70
+ const orchestrator = new Orchestrator({
71
+ agents: [triageAgent, salesAgent, supportAgent],
72
+ strategy: 'route-by-intent', // 按意图路由
73
+ });
74
+
75
+ const response = await orchestrator.handle(message);
76
+ ```
77
+
78
+ ### Testing — 测试工具
79
+
80
+ ```typescript
81
+ import { runTests, formatReport } from 'opc-agent';
82
+
83
+ const report = await runTests('oad.yaml');
84
+ console.log(formatReport(report));
85
+ ```
86
+
87
+ ## 模板列表
88
+
89
+ | 模板 | 说明 |
90
+ |------|------|
91
+ | `customer-service` | 客服:FAQ + 人工转接 |
92
+ | `sales-assistant` | 销售:产品问答 + 线索捕获 |
93
+ | `knowledge-base` | 知识库:RAG 语义检索 |
94
+ | `code-reviewer` | 代码审查:Bug 检测 + 风格检查 |
95
+ | `hr-recruiter` | HR:简历筛选 + 面试 |
96
+ | `project-manager` | 项目管理:任务 + 会议纪要 |
97
+ | `content-writer` | 内容创作:博客 + 社媒 + SEO |
98
+ | `legal-assistant` | 法务:合同审查 + 合规 |
99
+ | `financial-advisor` | 财务:预算 + 支出 |
100
+ | `executive-assistant` | 行政:日程 + 邮件 + 会议 |
101
+ | `data-analyst` | 数据分析:查询 + 可视化 |
102
+ | `teacher` | 教学:课程 + 出题 |
@@ -1,28 +1,104 @@
1
1
  # 核心概念
2
2
 
3
- ## OAD(Open Agent Definition)
3
+ ## 智能体 (Agent)
4
4
 
5
- OAD 是智能体的声明式定义文件,使用 YAML 格式。包含:
5
+ 智能体是一个有完整生命周期的 AI 实体:
6
6
 
7
- - **metadata** — 名称、版本、描述
8
- - **spec** 模型、系统提示词、技能、渠道、记忆、DTV
7
+ ```
8
+ 初始化 (init) 就绪 (ready) → 运行中 (running) → 已停止 (stopped)
9
+ ```
9
10
 
10
- ## 技能(Skills)
11
+ 每个智能体有以下属性:
12
+ - **名称** — 唯一标识符
13
+ - **系统提示词** — 定义智能体的角色和行为
14
+ - **技能** — 智能体能做的事(如 FAQ 查询、转人工)
15
+ - **渠道** — 用户和智能体交互的方式(如 Web、Telegram)
16
+ - **记忆** — 对话历史和长期知识
11
17
 
12
- 技能是智能体的能力模块,每个技能处理特定类型的用户请求。
18
+ ## OAD (Open Agent Definition)
13
19
 
14
- ## 渠道(Channels)
20
+ OAD 是智能体的声明式定义格式,用 YAML 编写。一个 OAD 文件就是一个完整的智能体定义。
15
21
 
16
- 渠道定义智能体与用户交互的方式:Web、Telegram、Slack、微信等。
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
+ ```
17
36
 
18
- ## DTV(Data-Trust-Value)
37
+ 这个设计理念参考了 Kubernetes 的资源定义:声明你想要的状态,框架帮你实现。
19
38
 
20
- DTV 框架确保智能体的数据安全、信任级别和价值追踪。
39
+ ## 技能 (Skill)
21
40
 
22
- ## 测试
41
+ 技能是智能体的模块化能力。每个技能:
42
+ - 有 `name` 和 `description`
43
+ - 接收对话上下文和当前消息
44
+ - 返回是否处理了这条消息,以及置信度
23
45
 
24
- 在 OAD 中定义测试用例,使用 `opc test` 运行自动化测试。
46
+ 内置技能包括:
47
+ - **FAQ 查询** — 从预设问答库匹配答案
48
+ - **人工转接** — 置信度低时转给人工客服
49
+ - **知识库检索** — 从文档中语义搜索相关内容
25
50
 
26
- ## 缓存与限流
51
+ 你也可以继承 `BaseSkill` 实现自定义技能。
27
52
 
28
- 内置 LLM 响应缓存和多级限流,降低 API 成本,保护服务稳定性。
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,11 +1,36 @@
1
- # 配置
1
+ # 配置详解
2
2
 
3
- 详细配置说明请参考 [英文版](/guide/configuration)。
3
+ ## OAD 文件结构
4
4
 
5
- ## 限流配置
5
+ `oad.yaml` 是智能体的核心配置文件,所有配置都在这里:
6
6
 
7
7
  ```yaml
8
+ apiVersion: opc/v1
9
+ kind: Agent
10
+ metadata:
11
+ name: my-agent
12
+ version: 1.0.0
13
+ description: 我的智能体
8
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
9
34
  rateLimits:
10
35
  perUser:
11
36
  maxRequests: 60
@@ -13,27 +38,98 @@ spec:
13
38
  perProvider:
14
39
  maxRequests: 100
15
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
16
79
  ```
17
80
 
18
81
  ## 缓存配置
19
82
 
83
+ 开启 LLM 响应缓存,降低 API 调用成本:
84
+
20
85
  ```yaml
21
86
  spec:
22
87
  cache:
23
88
  enabled: true
24
- ttlMs: 3600000
25
- maxEntries: 1000
89
+ ttlMs: 3600000 # 缓存有效期 1 小时
90
+ maxEntries: 1000 # 最大缓存条数
26
91
  ```
27
92
 
28
- ## 测试配置
93
+ ## 渠道配置
29
94
 
30
95
  ```yaml
31
96
  spec:
32
- testing:
33
- cases:
34
- - name: 问候测试
35
- input: "你好"
36
- expect:
37
- contains: ["你好", "帮"]
38
- maxLatencyMs: 5000
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]
39
135
  ```
@@ -1,3 +1,81 @@
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
1
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
+ ## 上线检查清单
2
73
 
3
- 详细说明请参考 [英文版](/guide/deployment)。
74
+ - [ ] 在 `.env` 中配置正确的 API Key
75
+ - [ ] 在 `oad.yaml` 中配置限流策略
76
+ - [ ] 开启缓存以降低 API 成本
77
+ - [ ] 配置监控和告警
78
+ - [ ] 运行 `opc test` 确保测试通过
79
+ - [ ] 检查 DTV 信任等级设置
80
+ - [ ] 配置 CORS 和安全头
81
+ - [ ] 准备回滚方案