opc-agent 0.1.0 → 0.3.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/CONTRIBUTING.md +75 -0
  3. package/README.md +105 -116
  4. package/README.zh-CN.md +58 -96
  5. package/dist/analytics/index.d.ts +31 -0
  6. package/dist/analytics/index.js +52 -0
  7. package/dist/channels/telegram.d.ts +21 -0
  8. package/dist/channels/telegram.js +120 -0
  9. package/dist/channels/websocket.d.ts +15 -0
  10. package/dist/channels/websocket.js +81 -0
  11. package/dist/cli.js +261 -27
  12. package/dist/core/agent.d.ts +2 -0
  13. package/dist/core/agent.js +3 -1
  14. package/dist/core/logger.d.ts +19 -0
  15. package/dist/core/logger.js +50 -0
  16. package/dist/core/room.d.ts +24 -0
  17. package/dist/core/room.js +97 -0
  18. package/dist/core/runtime.d.ts +11 -0
  19. package/dist/core/runtime.js +76 -0
  20. package/dist/core/sandbox.d.ts +28 -0
  21. package/dist/core/sandbox.js +118 -0
  22. package/dist/i18n/index.d.ts +13 -0
  23. package/dist/i18n/index.js +73 -0
  24. package/dist/index.d.ts +17 -1
  25. package/dist/index.js +28 -1
  26. package/dist/memory/deepbrain.d.ts +40 -0
  27. package/dist/memory/deepbrain.js +135 -0
  28. package/dist/plugins/index.d.ts +47 -0
  29. package/dist/plugins/index.js +59 -0
  30. package/dist/schema/oad.d.ts +294 -36
  31. package/dist/schema/oad.js +22 -3
  32. package/dist/templates/code-reviewer.d.ts +41 -0
  33. package/dist/templates/code-reviewer.js +38 -0
  34. package/dist/templates/content-writer.d.ts +36 -0
  35. package/dist/templates/content-writer.js +52 -0
  36. package/dist/templates/hr-recruiter.d.ts +36 -0
  37. package/dist/templates/hr-recruiter.js +52 -0
  38. package/dist/templates/knowledge-base.d.ts +44 -0
  39. package/dist/templates/knowledge-base.js +35 -0
  40. package/dist/templates/project-manager.d.ts +36 -0
  41. package/dist/templates/project-manager.js +52 -0
  42. package/dist/templates/sales-assistant.d.ts +56 -0
  43. package/dist/templates/sales-assistant.js +79 -0
  44. package/dist/tools/mcp.d.ts +32 -0
  45. package/dist/tools/mcp.js +49 -0
  46. package/package.json +11 -2
  47. package/src/analytics/index.ts +66 -0
  48. package/src/channels/telegram.ts +90 -0
  49. package/src/channels/websocket.ts +87 -0
  50. package/src/cli.ts +286 -33
  51. package/src/core/agent.ts +4 -1
  52. package/src/core/logger.ts +57 -0
  53. package/src/core/room.ts +109 -0
  54. package/src/core/runtime.ts +79 -1
  55. package/src/core/sandbox.ts +101 -0
  56. package/src/i18n/index.ts +79 -0
  57. package/src/index.ts +19 -1
  58. package/src/memory/deepbrain.ts +108 -0
  59. package/src/plugins/index.ts +87 -0
  60. package/src/schema/oad.ts +24 -2
  61. package/src/templates/code-reviewer.ts +34 -0
  62. package/src/templates/content-writer.ts +58 -0
  63. package/src/templates/hr-recruiter.ts +58 -0
  64. package/src/templates/knowledge-base.ts +31 -0
  65. package/src/templates/project-manager.ts +58 -0
  66. package/src/templates/sales-assistant.ts +79 -0
  67. package/src/tools/mcp.ts +76 -0
  68. package/templates/code-reviewer/README.md +27 -0
  69. package/templates/code-reviewer/oad.yaml +41 -0
  70. package/templates/knowledge-base/README.md +28 -0
  71. package/templates/knowledge-base/oad.yaml +38 -0
  72. package/templates/sales-assistant/README.md +26 -0
  73. package/templates/sales-assistant/oad.yaml +43 -0
  74. package/tests/analytics.test.ts +50 -0
  75. package/tests/i18n.test.ts +41 -0
  76. package/tests/mcp.test.ts +54 -0
  77. package/tests/plugin.test.ts +74 -0
  78. package/tests/room.test.ts +106 -0
  79. package/tests/sandbox.test.ts +46 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to OPC Agent will be documented in this file.
4
+
5
+ ## [0.2.0] - 2026-04-15
6
+
7
+ ### Added
8
+ - **DeepBrain Integration**: Optional long-term memory backend with semantic search. Config via `memory.longTerm.provider: deepbrain`. Falls back to in-memory if not installed.
9
+ - **Telegram Channel**: Basic webhook handler for Telegram Bot API (`src/channels/telegram.ts`).
10
+ - **WebSocket Channel**: Real-time bidirectional communication with broadcast (`src/channels/websocket.ts`).
11
+ - **Sales Assistant Template**: Product Q&A, lead capture, appointment booking.
12
+ - **Knowledge Base Template**: RAG with DeepBrain for answering from company docs.
13
+ - **Code Reviewer Template**: Bug detection, style checking, severity ratings.
14
+ - **Skill Marketplace Stub**: `opc publish` validates OAD and generates manifest. `opc search` placeholder.
15
+ - **OAD Marketplace Fields**: `pricing` (free/freemium/paid/enterprise) and `tags` in marketplace config.
16
+ - **Context Size Guard**: Auto-truncate tool outputs exceeding 5000 characters.
17
+ - **Conversation History Limit**: Configurable limit (default 50 messages).
18
+ - **Graceful Shutdown**: Handles SIGINT/SIGTERM with cleanup.
19
+ - **Structured Logging**: Logger with debug/info/warn/error levels.
20
+ - **Interactive CLI Init**: `opc init` with prompts and template selection.
21
+ - **Dev Mode**: `opc dev` watches files and hot-reloads agent on changes.
22
+ - **Agent Info Command**: `opc info` displays agent details from OAD.
23
+ - **Colorful CLI Output**: Status indicators and colored text throughout CLI.
24
+ - **CONTRIBUTING.md**: Contribution guidelines.
25
+ - **CHANGELOG.md**: This file.
26
+
27
+ ### Changed
28
+ - OAD `memory.longTerm` now accepts boolean or object with provider config.
29
+ - OAD `channels.type` now includes `telegram`.
30
+ - CLI version bumped to 0.2.0.
31
+
32
+ ## [0.1.0] - 2026-04-14
33
+
34
+ ### Added
35
+ - Initial release
36
+ - BaseAgent with lifecycle management
37
+ - AgentRuntime for config-driven setup
38
+ - OAD Schema v1 with Zod validation
39
+ - Web channel (Express)
40
+ - InMemoryStore
41
+ - Skill system (BaseSkill, SkillRegistry)
42
+ - DTV framework (Trust, Value, Data)
43
+ - Customer Service template
44
+ - CLI: init, create, build, test, run, publish
@@ -0,0 +1,75 @@
1
+ # Contributing to OPC Agent
2
+
3
+ Thank you for your interest in contributing to OPC Agent! 🎉
4
+
5
+ ## Getting Started
6
+
7
+ 1. Fork the repository
8
+ 2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/opc-agent.git`
9
+ 3. Install dependencies: `npm install`
10
+ 4. Create a branch: `git checkout -b feature/my-feature`
11
+
12
+ ## Development
13
+
14
+ ```bash
15
+ # Build
16
+ npm run build
17
+
18
+ # Run tests
19
+ npm test
20
+
21
+ # Type check
22
+ npm run lint
23
+
24
+ # Watch mode
25
+ npm run dev
26
+ ```
27
+
28
+ ## Project Structure
29
+
30
+ ```
31
+ src/
32
+ ├── core/ # Agent, Runtime, Config, Logger, Types
33
+ ├── channels/ # Web, WebSocket, Telegram channels
34
+ ├── memory/ # InMemoryStore, DeepBrainMemoryStore
35
+ ├── providers/ # LLM provider abstraction
36
+ ├── schema/ # OAD schema (Zod)
37
+ ├── skills/ # BaseSkill, SkillRegistry
38
+ ├── templates/ # Agent templates
39
+ ├── dtv/ # Data, Trust, Value framework
40
+ ├── cli.ts # CLI entry point
41
+ └── index.ts # Public API exports
42
+ ```
43
+
44
+ ## Guidelines
45
+
46
+ - **TypeScript**: All code must be TypeScript with strict mode
47
+ - **Tests**: Add tests for new features in `tests/`
48
+ - **Commits**: Use conventional commits (`feat:`, `fix:`, `docs:`, etc.)
49
+ - **OAD Compatibility**: Changes to OAD schema must be backward-compatible
50
+ - **No Breaking Changes** without major version bump
51
+
52
+ ## Adding a Template
53
+
54
+ 1. Create `src/templates/my-template.ts` with config factory function
55
+ 2. Create `templates/my-template/oad.yaml` and `README.md`
56
+ 3. Register in `src/cli.ts` TEMPLATES map
57
+ 4. Add tests
58
+
59
+ ## Adding a Channel
60
+
61
+ 1. Create `src/channels/my-channel.ts` extending `BaseChannel`
62
+ 2. Add channel type to OAD schema in `src/schema/oad.ts`
63
+ 3. Wire up in `src/core/runtime.ts`
64
+ 4. Export from `src/index.ts`
65
+
66
+ ## Pull Requests
67
+
68
+ 1. Ensure all tests pass: `npm test`
69
+ 2. Ensure types check: `npm run lint`
70
+ 3. Write a clear PR description
71
+ 4. Reference any related issues
72
+
73
+ ## License
74
+
75
+ By contributing, you agree that your contributions will be licensed under Apache-2.0.
package/README.md CHANGED
@@ -1,62 +1,64 @@
1
1
  # OPC Agent
2
2
 
3
- **Open Agent Framework — Build, test, and run AI Agents for business workstations.**
3
+ **Open Agent Framework** — Build, test, and run AI Agents for business workstations.
4
4
 
5
- [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.5-blue.svg)](https://www.typescriptlang.org/)
5
+ [![npm version](https://img.shields.io/npm/v/opc-agent.svg)](https://www.npmjs.com/package/opc-agent)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
7
7
 
8
- OPC Agent is an open-source framework for building production-ready AI agents. It provides a declarative agent definition format (OAD), pluggable skills, multi-channel support, and a progressive trust model for safe deployment.
8
+ ## Features
9
9
 
10
- ## Architecture
11
-
12
- ```
13
- ┌─────────────────────────────────────────────────┐
14
- │ OPC Agent │
15
- ├─────────────┬──────────┬────────────────────────┤
16
- │ Channels │ Skills │ Memory │
17
- │ ┌────────┐ ┌──────┐ │ ┌──────────────────┐ │
18
- │ │ Web │ │ │ FAQ │ │ │ Short-term │ │
19
- │ │ WS │ │ │Custom│ │ │ Long-term │ │
20
- │ │ CLI │ │ │ ... │ │ └──────────────────┘ │
21
- │ └────────┘ │ └──────┘ │ │
22
- ├─────────────┴──────────┴────────────────────────┤
23
- │ Agent Runtime │
24
- │ ┌──────────┐ ┌────────┐ ┌────────────────────┐ │
25
- │ │ Lifecycle│ │ Router │ │ LLM Providers │ │
26
- │ │ Manager │ │ │ │ OpenAI/DeepSeek/ │ │
27
- │ │ │ │ │ │ Qwen via agentkits │ │
28
- │ └──────────┘ └────────┘ └────────────────────┘ │
29
- ├─────────────────────────────────────────────────┤
30
- │ DTV Framework │
31
- │ Data (read-only) │ Trust (sandbox→listed) │ Value│
32
- └─────────────────────────────────────────────────┘
33
- ```
10
+ - 🤖 **Agent Framework** — BaseAgent with lifecycle management, skills, and LLM integration
11
+ - 📋 **OAD Schema** — Declarative agent definition (YAML/JSON) with validation
12
+ - 🧠 **Memory System** — Short-term + long-term memory with DeepBrain integration
13
+ - 🔌 **Multi-Channel** — Web, WebSocket, and Telegram channels
14
+ - 🛡️ **DTV Framework** — Data, Trust, and Value tracking for agents
15
+ - 🎯 **Skill System** — Pluggable skills with registry and priority execution
16
+ - 📦 **Templates** — Customer service, sales assistant, knowledge base, code reviewer
17
+ - 🚀 **CLI** — Interactive project creation, dev mode, build, test, run
34
18
 
35
19
  ## Quick Start
36
20
 
37
21
  ```bash
38
- # Install
22
+ # Install globally
39
23
  npm install -g opc-agent
40
24
 
41
- # Create a new agent project
42
- opc init my-agent --template customer-service
43
-
44
- # Enter the project
45
- cd my-agent
46
-
47
- # Validate the agent definition
48
- opc build
25
+ # Create a new agent project (interactive)
26
+ opc init my-agent
49
27
 
50
- # Test in sandbox
51
- opc test
28
+ # Or with a specific template
29
+ opc init my-bot --template sales-assistant
52
30
 
53
31
  # Run the agent
32
+ cd my-agent
54
33
  opc run
55
34
  ```
56
35
 
57
- ## OAD — Open Agent Definition
36
+ ## Templates
37
+
38
+ | Template | Description |
39
+ |----------|-------------|
40
+ | `customer-service` | FAQ lookup + human handoff |
41
+ | `sales-assistant` | Product Q&A + lead capture + appointment booking |
42
+ | `knowledge-base` | RAG with DeepBrain semantic search |
43
+ | `code-reviewer` | Bug detection + style checking |
44
+
45
+ ## CLI Commands
46
+
47
+ | Command | Description |
48
+ |---------|-------------|
49
+ | `opc init [name]` | Create new project (interactive) |
50
+ | `opc create <name>` | Create agent from template |
51
+ | `opc info` | Show agent info from OAD |
52
+ | `opc build` | Validate OAD |
53
+ | `opc test` | Run in sandbox mode |
54
+ | `opc run` | Start agent with channels |
55
+ | `opc dev` | Hot-reload development mode |
56
+ | `opc publish` | Validate and generate manifest |
57
+ | `opc search <query>` | Search OPC Registry (coming soon) |
58
+
59
+ ## OAD Schema
58
60
 
59
- Agents are defined using a declarative YAML format:
61
+ OAD (Open Agent Definition) is a declarative schema for defining agents:
60
62
 
61
63
  ```yaml
62
64
  apiVersion: opc/v1
@@ -64,7 +66,11 @@ kind: Agent
64
66
  metadata:
65
67
  name: my-agent
66
68
  version: 1.0.0
67
- description: "My first agent"
69
+ description: "My AI agent"
70
+ marketplace:
71
+ category: support
72
+ pricing: free
73
+ tags: [ai, support]
68
74
  spec:
69
75
  provider:
70
76
  default: deepseek
@@ -73,107 +79,90 @@ spec:
73
79
  systemPrompt: "You are a helpful assistant."
74
80
  skills:
75
81
  - name: faq-lookup
76
- description: "Look up FAQ answers"
82
+ description: "Answer FAQs"
77
83
  channels:
78
84
  - type: web
79
85
  port: 3000
86
+ - type: telegram
87
+ config:
88
+ token: "BOT_TOKEN"
89
+ - type: websocket
90
+ port: 3002
80
91
  memory:
81
92
  shortTerm: true
82
- longTerm: false
93
+ longTerm:
94
+ provider: deepbrain
95
+ collection: my-knowledge
83
96
  dtv:
84
97
  trust:
85
98
  level: sandbox
86
99
  value:
87
- metrics: [response_time, satisfaction_score]
100
+ metrics: [response_time]
88
101
  ```
89
102
 
90
- ## Programmatic Usage
91
-
92
- ```typescript
93
- import { BaseAgent, AgentRuntime, WebChannel } from 'opc-agent';
94
-
95
- // Option 1: Use runtime with OAD file
96
- const runtime = new AgentRuntime();
97
- await runtime.loadConfig('oad.yaml');
98
- await runtime.initialize();
99
- await runtime.start();
103
+ ## Memory Providers
100
104
 
101
- // Option 2: Build programmatically
102
- const agent = new BaseAgent({
103
- name: 'my-agent',
104
- systemPrompt: 'You are helpful.',
105
- provider: 'deepseek',
106
- model: 'deepseek-chat',
107
- });
105
+ ### In-Memory (default)
106
+ Simple key-value store. Data lost on restart.
108
107
 
109
- agent.registerSkill(myCustomSkill);
110
- agent.bindChannel(new WebChannel(3000));
108
+ ### DeepBrain (optional)
109
+ Semantic search over past conversations and knowledge. Install `deepbrain` package:
111
110
 
112
- await agent.init();
113
- await agent.start();
111
+ ```bash
112
+ npm install deepbrain
114
113
  ```
115
114
 
116
- ## Core Concepts
117
-
118
- | Concept | Description |
119
- |---------|-------------|
120
- | **Agent** | Autonomous AI entity with lifecycle (init → ready → running → stopped) |
121
- | **Skill** | Modular capability (FAQ, ticket creation, etc.) |
122
- | **Channel** | User interface (Web HTTP, WebSocket, CLI) |
123
- | **Memory** | Short-term (session) and long-term (persistent) |
124
- | **OAD** | Declarative YAML agent definition format |
125
-
126
- ## DTV Framework
115
+ Configure in OAD:
116
+ ```yaml
117
+ memory:
118
+ longTerm:
119
+ provider: deepbrain
120
+ collection: my-collection
121
+ ```
127
122
 
128
- **D**ata **T**rust **V**alue: A governance framework for agent operations.
123
+ Falls back to in-memory if deepbrain is not installed.
129
124
 
130
- - **Data**: Read-only access to business data via MRGConfig reader
131
- - **Trust**: Progressive levels control capabilities
132
- - `sandbox` → `verified` → `certified` → `listed`
133
- - **Value**: Metrics tracking for ROI (response time, satisfaction, resolution rate)
125
+ ## Channels
134
126
 
135
- ## Templates
127
+ - **Web** — Express HTTP server with `/chat` endpoint and SSE streaming
128
+ - **WebSocket** — Real-time bidirectional communication with broadcast
129
+ - **Telegram** — Webhook handler for Telegram Bot API
136
130
 
137
- | Template | Description |
138
- |----------|-------------|
139
- | `customer-service` | FAQ + human handoff, web channel |
140
- | More coming soon... | Sales, IT help desk, content moderation |
131
+ ## Programmatic Usage
141
132
 
142
- ## CLI Commands
133
+ ```typescript
134
+ import { BaseAgent, AgentRuntime } from 'opc-agent';
143
135
 
144
- | Command | Description |
145
- |---------|-------------|
146
- | `opc init [name]` | Initialize a new agent project |
147
- | `opc create <name>` | Create agent from template |
148
- | `opc build` | Validate OAD definition |
149
- | `opc test` | Run in sandbox mode |
150
- | `opc run` | Start agent with channels |
151
- | `opc publish` | Package for registry (coming soon) |
136
+ // Quick start
137
+ const agent = new BaseAgent({
138
+ name: 'my-agent',
139
+ systemPrompt: 'You are helpful.',
140
+ });
141
+ await agent.init();
152
142
 
153
- ## Comparison
143
+ // With skills
144
+ agent.registerSkill({
145
+ name: 'greeter',
146
+ description: 'Greet users',
147
+ execute: async (ctx, msg) => {
148
+ if (msg.content.includes('hello')) {
149
+ return { handled: true, response: 'Hi!', confidence: 1.0 };
150
+ }
151
+ return { handled: false, confidence: 0 };
152
+ },
153
+ });
154
154
 
155
- | Feature | OPC Agent | LangChain | AutoGen |
156
- |---------|-----------|-----------|---------|
157
- | Declarative config | ✅ OAD YAML | ❌ | ❌ |
158
- | Trust levels | ✅ 4-tier | ❌ | ❌ |
159
- | Built-in channels | ✅ Web, WS | ❌ | ❌ |
160
- | Business-focused | ✅ | ❌ General | ❌ Research |
161
- | Value tracking | ✅ ROI metrics | ❌ | ❌ |
162
- | TypeScript-first | ✅ | Python | Python |
163
- | Lightweight | ✅ ~5 deps | ❌ Heavy | ❌ Heavy |
155
+ // From OAD config
156
+ const runtime = new AgentRuntime();
157
+ await runtime.loadConfig('oad.yaml');
158
+ await runtime.initialize();
159
+ await runtime.start();
160
+ ```
164
161
 
165
162
  ## Contributing
166
163
 
167
- 1. Fork the repository
168
- 2. Create a feature branch: `git checkout -b feature/my-feature`
169
- 3. Commit your changes: `git commit -am 'Add my feature'`
170
- 4. Push: `git push origin feature/my-feature`
171
- 5. Open a Pull Request
164
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
172
165
 
173
166
  ## License
174
167
 
175
- [Apache-2.0](LICENSE)
176
-
177
- ---
178
-
179
- Built by [Deepleaper](https://github.com/Deepleaper) 🚀
168
+ Apache-2.0 — see [LICENSE](LICENSE).
package/README.zh-CN.md CHANGED
@@ -1,126 +1,88 @@
1
1
  # OPC Agent
2
2
 
3
- **开放 Agent 框架构建、测试和运行面向企业工作站的 AI Agent。**
3
+ **开放 Agent 框架**构建、测试和运行企业级 AI Agent
4
4
 
5
- [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.5-blue.svg)](https://www.typescriptlang.org/)
5
+ [![npm version](https://img.shields.io/npm/v/opc-agent.svg)](https://www.npmjs.com/package/opc-agent)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
7
7
 
8
- OPC Agent 是一个开源框架,用于构建生产级 AI Agent。提供声明式 Agent 定义格式(OAD)、可插拔技能、多通道支持,以及渐进式信任模型确保安全部署。
8
+ ## 特性
9
9
 
10
- ## 架构
11
-
12
- ```
13
- ┌─────────────────────────────────────────────────┐
14
- │ OPC Agent │
15
- ├─────────────┬──────────┬────────────────────────┤
16
- │ 通道 │ 技能 │ 记忆 │
17
- │ ┌────────┐ ┌──────┐ │ ┌──────────────────┐ │
18
- │ │ Web │ │ │ FAQ │ │ │ 短期记忆 │ │
19
- │ │ WS │ │ │ 自定义│ │ │ 长期记忆 │ │
20
- │ │ CLI │ │ │ ... │ │ └──────────────────┘ │
21
- │ └────────┘ │ └──────┘ │ │
22
- ├─────────────┴──────────┴────────────────────────┤
23
- │ Agent 运行时 │
24
- │ ┌──────────┐ ┌────────┐ ┌────────────────────┐ │
25
- │ │ 生命周期 │ │ 路由器 │ │ LLM 提供商 │ │
26
- │ │ 管理器 │ │ │ │ OpenAI/DeepSeek/ │ │
27
- │ │ │ │ │ │ Qwen (agentkits) │ │
28
- │ └──────────┘ └────────┘ └────────────────────┘ │
29
- ├─────────────────────────────────────────────────┤
30
- │ DTV 框架 │
31
- │ 数据(只读)│ 信任(沙箱→上架)│ 价值(指标追踪)│
32
- └─────────────────────────────────────────────────┘
33
- ```
10
+ - 🤖 **Agent 框架** — 带生命周期管理、技能和 LLM 集成的 BaseAgent
11
+ - 📋 **OAD Schema** — 声明式 Agent 定义(YAML/JSON),内置校验
12
+ - 🧠 **记忆系统** — 短期 + 长期记忆,支持 DeepBrain 集成
13
+ - 🔌 **多通道** — Web、WebSocket、Telegram 通道
14
+ - 🛡️ **DTV 框架** — 数据、信任、价值追踪
15
+ - 🎯 **技能系统** — 可插拔技能 + 注册表 + 优先级执行
16
+ - 📦 **模板** — 客服、销售助手、知识库、代码审查
17
+ - 🚀 **CLI** — 交互式创建、开发模式、构建、测试、运行
34
18
 
35
19
  ## 快速开始
36
20
 
37
21
  ```bash
38
- # 安装
22
+ # 全局安装
39
23
  npm install -g opc-agent
40
24
 
41
- # 创建新的 Agent 项目
42
- opc init my-agent --template customer-service
43
-
44
- # 进入项目目录
45
- cd my-agent
46
-
47
- # 验证 Agent 定义
48
- opc build
25
+ # 创建新 Agent 项目(交互式)
26
+ opc init my-agent
49
27
 
50
- # 沙箱测试
51
- opc test
28
+ # 使用指定模板
29
+ opc init my-bot --template sales-assistant
52
30
 
53
31
  # 运行 Agent
32
+ cd my-agent
54
33
  opc run
55
34
  ```
56
35
 
57
- ## OAD — 开放 Agent 定义
58
-
59
- Agent 使用声明式 YAML 格式定义:
36
+ ## 模板
60
37
 
61
- ```yaml
62
- apiVersion: opc/v1
63
- kind: Agent
64
- metadata:
65
- name: my-agent
66
- version: 1.0.0
67
- description: "我的第一个 Agent"
68
- spec:
69
- provider:
70
- default: deepseek
71
- allowed: [openai, deepseek, qwen]
72
- model: deepseek-chat
73
- systemPrompt: "你是一个有用的助手。"
74
- skills:
75
- - name: faq-lookup
76
- description: "查询常见问题"
77
- channels:
78
- - type: web
79
- port: 3000
80
- memory:
81
- shortTerm: true
82
- longTerm: false
83
- dtv:
84
- trust:
85
- level: sandbox
86
- value:
87
- metrics: [response_time, satisfaction_score]
88
- ```
38
+ | 模板 | 描述 |
39
+ |------|------|
40
+ | `customer-service` | FAQ 查询 + 人工转接 |
41
+ | `sales-assistant` | 产品问答 + 线索捕获 + 预约 |
42
+ | `knowledge-base` | 基于 DeepBrain 的 RAG 语义检索 |
43
+ | `code-reviewer` | Bug 检测 + 代码风格检查 |
89
44
 
90
- ## 核心概念
45
+ ## CLI 命令
91
46
 
92
- | 概念 | 说明 |
47
+ | 命令 | 描述 |
93
48
  |------|------|
94
- | **Agent** | 自治 AI 实体,具有生命周期(init ready running → stopped) |
95
- | **Skill(技能)** | 模块化能力(FAQ、工单创建等) |
96
- | **Channel(通道)** | 用户接口(Web HTTP、WebSocket、CLI) |
97
- | **Memory(记忆)** | 短期(会话内)和长期(持久化) |
98
- | **OAD** | 声明式 YAML Agent 定义格式 |
49
+ | `opc init [name]` | 创建新项目(交互式) |
50
+ | `opc create <name>` | 从模板创建 Agent |
51
+ | `opc info` | 显示 Agent 信息 |
52
+ | `opc build` | 校验 OAD |
53
+ | `opc test` | 沙箱模式运行 |
54
+ | `opc run` | 启动 Agent |
55
+ | `opc dev` | 热重载开发模式 |
56
+ | `opc publish` | 校验并生成清单 |
57
+ | `opc search <query>` | 搜索 OPC 市场(即将推出) |
99
58
 
100
- ## DTV 框架
59
+ ## 记忆提供者
101
60
 
102
- **D**ata(数据)— **T**rust(信任)— **V**alue(价值):Agent 运营治理框架。
61
+ ### 内存(默认)
62
+ 简单键值存储,重启后数据丢失。
103
63
 
104
- - **数据**:通过 MRGConfig 只读访问业务数据
105
- - **信任**:渐进式级别控制 Agent 能力
106
- - `sandbox`(沙箱)→ `verified`(已验证)→ `certified`(已认证)→ `listed`(已上架)
107
- - **价值**:ROI 指标追踪(响应时间、满意度、解决率)
64
+ ### DeepBrain(可选)
65
+ 语义搜索历史对话和知识。安装 `deepbrain` 包后配置:
108
66
 
109
- ## CLI 命令
67
+ ```yaml
68
+ memory:
69
+ longTerm:
70
+ provider: deepbrain
71
+ collection: my-collection
72
+ ```
110
73
 
111
- | 命令 | 说明 |
112
- |------|------|
113
- | `opc init [name]` | 初始化新的 Agent 项目 |
114
- | `opc create <name>` | 从模板创建 Agent |
115
- | `opc build` | 验证 OAD 定义 |
116
- | `opc test` | 沙箱模式测试 |
117
- | `opc run` | 启动 Agent |
118
- | `opc publish` | 打包到注册中心(即将推出) |
74
+ 未安装 deepbrain 时自动降级为内存存储。
119
75
 
120
- ## 许可证
76
+ ## 通道
121
77
 
122
- [Apache-2.0](LICENSE)
78
+ - **Web** — Express HTTP 服务,`/chat` 接口 + SSE 流式
79
+ - **WebSocket** — 实时双向通信 + 广播
80
+ - **Telegram** — Telegram Bot API Webhook 处理
123
81
 
124
- ---
82
+ ## 贡献
83
+
84
+ 参见 [CONTRIBUTING.md](CONTRIBUTING.md)。
85
+
86
+ ## 许可证
125
87
 
126
- [Deepleaper](https://github.com/Deepleaper) 构建 🚀
88
+ Apache-2.0 — 见 [LICENSE](LICENSE)
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Agent Analytics — track messages, response times, skill usage, errors, tokens.
3
+ */
4
+ export interface AnalyticsSnapshot {
5
+ messagesProcessed: number;
6
+ avgResponseTimeMs: number;
7
+ skillUsage: Record<string, number>;
8
+ errorCount: number;
9
+ tokenUsage: {
10
+ input: number;
11
+ output: number;
12
+ total: number;
13
+ };
14
+ uptime: number;
15
+ startedAt: number;
16
+ }
17
+ export declare class Analytics {
18
+ private messagesProcessed;
19
+ private totalResponseTimeMs;
20
+ private skillUsage;
21
+ private errorCount;
22
+ private tokenUsage;
23
+ private startedAt;
24
+ recordMessage(responseTimeMs: number): void;
25
+ recordSkillUsage(skillName: string): void;
26
+ recordError(): void;
27
+ recordTokens(input: number, output: number): void;
28
+ getSnapshot(): AnalyticsSnapshot;
29
+ reset(): void;
30
+ }
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Analytics = void 0;
4
+ class Analytics {
5
+ messagesProcessed = 0;
6
+ totalResponseTimeMs = 0;
7
+ skillUsage = {};
8
+ errorCount = 0;
9
+ tokenUsage = { input: 0, output: 0 };
10
+ startedAt = Date.now();
11
+ recordMessage(responseTimeMs) {
12
+ this.messagesProcessed++;
13
+ this.totalResponseTimeMs += responseTimeMs;
14
+ }
15
+ recordSkillUsage(skillName) {
16
+ this.skillUsage[skillName] = (this.skillUsage[skillName] ?? 0) + 1;
17
+ }
18
+ recordError() {
19
+ this.errorCount++;
20
+ }
21
+ recordTokens(input, output) {
22
+ this.tokenUsage.input += input;
23
+ this.tokenUsage.output += output;
24
+ }
25
+ getSnapshot() {
26
+ return {
27
+ messagesProcessed: this.messagesProcessed,
28
+ avgResponseTimeMs: this.messagesProcessed > 0
29
+ ? Math.round(this.totalResponseTimeMs / this.messagesProcessed)
30
+ : 0,
31
+ skillUsage: { ...this.skillUsage },
32
+ errorCount: this.errorCount,
33
+ tokenUsage: {
34
+ input: this.tokenUsage.input,
35
+ output: this.tokenUsage.output,
36
+ total: this.tokenUsage.input + this.tokenUsage.output,
37
+ },
38
+ uptime: Date.now() - this.startedAt,
39
+ startedAt: this.startedAt,
40
+ };
41
+ }
42
+ reset() {
43
+ this.messagesProcessed = 0;
44
+ this.totalResponseTimeMs = 0;
45
+ this.skillUsage = {};
46
+ this.errorCount = 0;
47
+ this.tokenUsage = { input: 0, output: 0 };
48
+ this.startedAt = Date.now();
49
+ }
50
+ }
51
+ exports.Analytics = Analytics;
52
+ //# sourceMappingURL=index.js.map