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.
- package/CHANGELOG.md +44 -0
- package/CONTRIBUTING.md +75 -0
- package/README.md +105 -116
- package/README.zh-CN.md +58 -96
- package/dist/analytics/index.d.ts +31 -0
- package/dist/analytics/index.js +52 -0
- package/dist/channels/telegram.d.ts +21 -0
- package/dist/channels/telegram.js +120 -0
- package/dist/channels/websocket.d.ts +15 -0
- package/dist/channels/websocket.js +81 -0
- package/dist/cli.js +261 -27
- package/dist/core/agent.d.ts +2 -0
- package/dist/core/agent.js +3 -1
- package/dist/core/logger.d.ts +19 -0
- package/dist/core/logger.js +50 -0
- package/dist/core/room.d.ts +24 -0
- package/dist/core/room.js +97 -0
- package/dist/core/runtime.d.ts +11 -0
- package/dist/core/runtime.js +76 -0
- package/dist/core/sandbox.d.ts +28 -0
- package/dist/core/sandbox.js +118 -0
- package/dist/i18n/index.d.ts +13 -0
- package/dist/i18n/index.js +73 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +28 -1
- package/dist/memory/deepbrain.d.ts +40 -0
- package/dist/memory/deepbrain.js +135 -0
- package/dist/plugins/index.d.ts +47 -0
- package/dist/plugins/index.js +59 -0
- package/dist/schema/oad.d.ts +294 -36
- package/dist/schema/oad.js +22 -3
- package/dist/templates/code-reviewer.d.ts +41 -0
- package/dist/templates/code-reviewer.js +38 -0
- package/dist/templates/content-writer.d.ts +36 -0
- package/dist/templates/content-writer.js +52 -0
- package/dist/templates/hr-recruiter.d.ts +36 -0
- package/dist/templates/hr-recruiter.js +52 -0
- package/dist/templates/knowledge-base.d.ts +44 -0
- package/dist/templates/knowledge-base.js +35 -0
- package/dist/templates/project-manager.d.ts +36 -0
- package/dist/templates/project-manager.js +52 -0
- package/dist/templates/sales-assistant.d.ts +56 -0
- package/dist/templates/sales-assistant.js +79 -0
- package/dist/tools/mcp.d.ts +32 -0
- package/dist/tools/mcp.js +49 -0
- package/package.json +11 -2
- package/src/analytics/index.ts +66 -0
- package/src/channels/telegram.ts +90 -0
- package/src/channels/websocket.ts +87 -0
- package/src/cli.ts +286 -33
- package/src/core/agent.ts +4 -1
- package/src/core/logger.ts +57 -0
- package/src/core/room.ts +109 -0
- package/src/core/runtime.ts +79 -1
- package/src/core/sandbox.ts +101 -0
- package/src/i18n/index.ts +79 -0
- package/src/index.ts +19 -1
- package/src/memory/deepbrain.ts +108 -0
- package/src/plugins/index.ts +87 -0
- package/src/schema/oad.ts +24 -2
- package/src/templates/code-reviewer.ts +34 -0
- package/src/templates/content-writer.ts +58 -0
- package/src/templates/hr-recruiter.ts +58 -0
- package/src/templates/knowledge-base.ts +31 -0
- package/src/templates/project-manager.ts +58 -0
- package/src/templates/sales-assistant.ts +79 -0
- package/src/tools/mcp.ts +76 -0
- package/templates/code-reviewer/README.md +27 -0
- package/templates/code-reviewer/oad.yaml +41 -0
- package/templates/knowledge-base/README.md +28 -0
- package/templates/knowledge-base/oad.yaml +38 -0
- package/templates/sales-assistant/README.md +26 -0
- package/templates/sales-assistant/oad.yaml +43 -0
- package/tests/analytics.test.ts +50 -0
- package/tests/i18n.test.ts +41 -0
- package/tests/mcp.test.ts +54 -0
- package/tests/plugin.test.ts +74 -0
- package/tests/room.test.ts +106 -0
- 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
|
package/CONTRIBUTING.md
ADDED
|
@@ -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
|
-
[](https://www.npmjs.com/package/opc-agent)
|
|
6
|
+
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## Features
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
-
#
|
|
51
|
-
opc
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
|
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: "
|
|
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:
|
|
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
|
|
100
|
+
metrics: [response_time]
|
|
88
101
|
```
|
|
89
102
|
|
|
90
|
-
##
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
108
|
+
### DeepBrain (optional)
|
|
109
|
+
Semantic search over past conversations and knowledge. Install `deepbrain` package:
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
```bash
|
|
112
|
+
npm install deepbrain
|
|
114
113
|
```
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
123
|
+
Falls back to in-memory if deepbrain is not installed.
|
|
129
124
|
|
|
130
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
133
|
+
```typescript
|
|
134
|
+
import { BaseAgent, AgentRuntime } from 'opc-agent';
|
|
143
135
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
3
|
+
**开放 Agent 框架** — 构建、测试和运行企业级 AI Agent。
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/opc-agent)
|
|
6
|
+
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## 特性
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
#
|
|
42
|
-
opc init my-agent
|
|
43
|
-
|
|
44
|
-
# 进入项目目录
|
|
45
|
-
cd my-agent
|
|
46
|
-
|
|
47
|
-
# 验证 Agent 定义
|
|
48
|
-
opc build
|
|
25
|
+
# 创建新 Agent 项目(交互式)
|
|
26
|
+
opc init my-agent
|
|
49
27
|
|
|
50
|
-
#
|
|
51
|
-
opc
|
|
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
|
-
##
|
|
58
|
-
|
|
59
|
-
Agent 使用声明式 YAML 格式定义:
|
|
36
|
+
## 模板
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
98
|
-
|
|
|
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
|
-
##
|
|
59
|
+
## 记忆提供者
|
|
101
60
|
|
|
102
|
-
|
|
61
|
+
### 内存(默认)
|
|
62
|
+
简单键值存储,重启后数据丢失。
|
|
103
63
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
- `sandbox`(沙箱)→ `verified`(已验证)→ `certified`(已认证)→ `listed`(已上架)
|
|
107
|
-
- **价值**:ROI 指标追踪(响应时间、满意度、解决率)
|
|
64
|
+
### DeepBrain(可选)
|
|
65
|
+
语义搜索历史对话和知识。安装 `deepbrain` 包后配置:
|
|
108
66
|
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|