opc-agent 0.1.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/LICENSE +201 -0
- package/README.md +179 -0
- package/README.zh-CN.md +126 -0
- package/dist/channels/index.d.ts +10 -0
- package/dist/channels/index.js +11 -0
- package/dist/channels/web.d.ts +12 -0
- package/dist/channels/web.js +81 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +146 -0
- package/dist/core/agent.d.ts +28 -0
- package/dist/core/agent.js +100 -0
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.js +50 -0
- package/dist/core/runtime.d.ts +14 -0
- package/dist/core/runtime.js +54 -0
- package/dist/core/types.d.ts +58 -0
- package/dist/core/types.js +3 -0
- package/dist/dtv/data.d.ts +18 -0
- package/dist/dtv/data.js +25 -0
- package/dist/dtv/trust.d.ts +19 -0
- package/dist/dtv/trust.js +40 -0
- package/dist/dtv/value.d.ts +23 -0
- package/dist/dtv/value.js +38 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +33 -0
- package/dist/memory/index.d.ts +11 -0
- package/dist/memory/index.js +33 -0
- package/dist/providers/index.d.ts +12 -0
- package/dist/providers/index.js +68 -0
- package/dist/schema/oad.d.ts +553 -0
- package/dist/schema/oad.js +61 -0
- package/dist/skills/base.d.ts +9 -0
- package/dist/skills/base.js +13 -0
- package/dist/skills/index.d.ts +10 -0
- package/dist/skills/index.js +25 -0
- package/dist/templates/customer-service.d.ts +56 -0
- package/dist/templates/customer-service.js +75 -0
- package/docs/api/oad-schema.md +64 -0
- package/docs/guide/concepts.md +51 -0
- package/docs/guide/getting-started.md +44 -0
- package/docs/guide/templates.md +28 -0
- package/package.json +37 -0
- package/src/channels/index.ts +15 -0
- package/src/channels/web.ts +85 -0
- package/src/cli.ts +131 -0
- package/src/core/agent.ts +116 -0
- package/src/core/config.ts +14 -0
- package/src/core/runtime.ts +57 -0
- package/src/core/types.ts +68 -0
- package/src/dtv/data.ts +29 -0
- package/src/dtv/trust.ts +43 -0
- package/src/dtv/value.ts +47 -0
- package/src/index.ts +16 -0
- package/src/memory/index.ts +34 -0
- package/src/providers/index.ts +44 -0
- package/src/schema/oad.ts +76 -0
- package/src/skills/base.ts +16 -0
- package/src/skills/index.ts +27 -0
- package/src/templates/customer-service.ts +80 -0
- package/templates/customer-service/README.md +22 -0
- package/templates/customer-service/oad.yaml +36 -0
- package/tests/agent.test.ts +72 -0
- package/tests/channel.test.ts +39 -0
- package/tests/oad.test.ts +68 -0
- package/tests/runtime.test.ts +42 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# OPC Agent
|
|
2
|
+
|
|
3
|
+
**Open Agent Framework — Build, test, and run AI Agents for business workstations.**
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
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.
|
|
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
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Install
|
|
39
|
+
npm install -g opc-agent
|
|
40
|
+
|
|
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
|
|
49
|
+
|
|
50
|
+
# Test in sandbox
|
|
51
|
+
opc test
|
|
52
|
+
|
|
53
|
+
# Run the agent
|
|
54
|
+
opc run
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## OAD — Open Agent Definition
|
|
58
|
+
|
|
59
|
+
Agents are defined using a declarative YAML format:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
apiVersion: opc/v1
|
|
63
|
+
kind: Agent
|
|
64
|
+
metadata:
|
|
65
|
+
name: my-agent
|
|
66
|
+
version: 1.0.0
|
|
67
|
+
description: "My first agent"
|
|
68
|
+
spec:
|
|
69
|
+
provider:
|
|
70
|
+
default: deepseek
|
|
71
|
+
allowed: [openai, deepseek, qwen]
|
|
72
|
+
model: deepseek-chat
|
|
73
|
+
systemPrompt: "You are a helpful assistant."
|
|
74
|
+
skills:
|
|
75
|
+
- name: faq-lookup
|
|
76
|
+
description: "Look up FAQ answers"
|
|
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
|
+
```
|
|
89
|
+
|
|
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();
|
|
100
|
+
|
|
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
|
+
});
|
|
108
|
+
|
|
109
|
+
agent.registerSkill(myCustomSkill);
|
|
110
|
+
agent.bindChannel(new WebChannel(3000));
|
|
111
|
+
|
|
112
|
+
await agent.init();
|
|
113
|
+
await agent.start();
|
|
114
|
+
```
|
|
115
|
+
|
|
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
|
|
127
|
+
|
|
128
|
+
**D**ata — **T**rust — **V**alue: A governance framework for agent operations.
|
|
129
|
+
|
|
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)
|
|
134
|
+
|
|
135
|
+
## Templates
|
|
136
|
+
|
|
137
|
+
| Template | Description |
|
|
138
|
+
|----------|-------------|
|
|
139
|
+
| `customer-service` | FAQ + human handoff, web channel |
|
|
140
|
+
| More coming soon... | Sales, IT help desk, content moderation |
|
|
141
|
+
|
|
142
|
+
## CLI Commands
|
|
143
|
+
|
|
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) |
|
|
152
|
+
|
|
153
|
+
## Comparison
|
|
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 |
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
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
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
[Apache-2.0](LICENSE)
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
Built by [Deepleaper](https://github.com/Deepleaper) 🚀
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# OPC Agent
|
|
2
|
+
|
|
3
|
+
**开放 Agent 框架 — 构建、测试和运行面向企业工作站的 AI Agent。**
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
OPC Agent 是一个开源框架,用于构建生产级 AI Agent。提供声明式 Agent 定义格式(OAD)、可插拔技能、多通道支持,以及渐进式信任模型确保安全部署。
|
|
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
|
+
```
|
|
34
|
+
|
|
35
|
+
## 快速开始
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# 安装
|
|
39
|
+
npm install -g opc-agent
|
|
40
|
+
|
|
41
|
+
# 创建新的 Agent 项目
|
|
42
|
+
opc init my-agent --template customer-service
|
|
43
|
+
|
|
44
|
+
# 进入项目目录
|
|
45
|
+
cd my-agent
|
|
46
|
+
|
|
47
|
+
# 验证 Agent 定义
|
|
48
|
+
opc build
|
|
49
|
+
|
|
50
|
+
# 沙箱测试
|
|
51
|
+
opc test
|
|
52
|
+
|
|
53
|
+
# 运行 Agent
|
|
54
|
+
opc run
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## OAD — 开放 Agent 定义
|
|
58
|
+
|
|
59
|
+
Agent 使用声明式 YAML 格式定义:
|
|
60
|
+
|
|
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
|
+
```
|
|
89
|
+
|
|
90
|
+
## 核心概念
|
|
91
|
+
|
|
92
|
+
| 概念 | 说明 |
|
|
93
|
+
|------|------|
|
|
94
|
+
| **Agent** | 自治 AI 实体,具有生命周期(init → ready → running → stopped) |
|
|
95
|
+
| **Skill(技能)** | 模块化能力(FAQ、工单创建等) |
|
|
96
|
+
| **Channel(通道)** | 用户接口(Web HTTP、WebSocket、CLI) |
|
|
97
|
+
| **Memory(记忆)** | 短期(会话内)和长期(持久化) |
|
|
98
|
+
| **OAD** | 声明式 YAML Agent 定义格式 |
|
|
99
|
+
|
|
100
|
+
## DTV 框架
|
|
101
|
+
|
|
102
|
+
**D**ata(数据)— **T**rust(信任)— **V**alue(价值):Agent 运营治理框架。
|
|
103
|
+
|
|
104
|
+
- **数据**:通过 MRGConfig 只读访问业务数据
|
|
105
|
+
- **信任**:渐进式级别控制 Agent 能力
|
|
106
|
+
- `sandbox`(沙箱)→ `verified`(已验证)→ `certified`(已认证)→ `listed`(已上架)
|
|
107
|
+
- **价值**:ROI 指标追踪(响应时间、满意度、解决率)
|
|
108
|
+
|
|
109
|
+
## CLI 命令
|
|
110
|
+
|
|
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` | 打包到注册中心(即将推出) |
|
|
119
|
+
|
|
120
|
+
## 许可证
|
|
121
|
+
|
|
122
|
+
[Apache-2.0](LICENSE)
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
由 [Deepleaper](https://github.com/Deepleaper) 构建 🚀
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IChannel, Message } from '../core/types';
|
|
2
|
+
export type { IChannel } from '../core/types';
|
|
3
|
+
export declare abstract class BaseChannel implements IChannel {
|
|
4
|
+
abstract type: string;
|
|
5
|
+
protected handler: ((message: Message) => Promise<Message>) | null;
|
|
6
|
+
onMessage(handler: (message: Message) => Promise<Message>): void;
|
|
7
|
+
abstract start(): Promise<void>;
|
|
8
|
+
abstract stop(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseChannel = void 0;
|
|
4
|
+
class BaseChannel {
|
|
5
|
+
handler = null;
|
|
6
|
+
onMessage(handler) {
|
|
7
|
+
this.handler = handler;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.BaseChannel = BaseChannel;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
export declare class WebChannel extends BaseChannel {
|
|
3
|
+
readonly type = "web";
|
|
4
|
+
private app;
|
|
5
|
+
private server;
|
|
6
|
+
private port;
|
|
7
|
+
constructor(port?: number);
|
|
8
|
+
private setupRoutes;
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebChannel = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
class WebChannel extends index_1.BaseChannel {
|
|
10
|
+
type = 'web';
|
|
11
|
+
app;
|
|
12
|
+
server = null;
|
|
13
|
+
port;
|
|
14
|
+
constructor(port = 3000) {
|
|
15
|
+
super();
|
|
16
|
+
this.port = port;
|
|
17
|
+
this.app = (0, express_1.default)();
|
|
18
|
+
this.app.use(express_1.default.json());
|
|
19
|
+
this.setupRoutes();
|
|
20
|
+
}
|
|
21
|
+
setupRoutes() {
|
|
22
|
+
this.app.get('/health', (_req, res) => {
|
|
23
|
+
res.json({ status: 'ok', timestamp: Date.now() });
|
|
24
|
+
});
|
|
25
|
+
this.app.post('/chat', async (req, res) => {
|
|
26
|
+
if (!this.handler) {
|
|
27
|
+
res.status(503).json({ error: 'Agent not ready' });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const { message, sessionId } = req.body;
|
|
31
|
+
if (!message) {
|
|
32
|
+
res.status(400).json({ error: 'message is required' });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const msg = {
|
|
36
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
37
|
+
role: 'user',
|
|
38
|
+
content: message,
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
metadata: { sessionId: sessionId ?? 'default' },
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
const response = await this.handler(msg);
|
|
44
|
+
res.json({ response: response.content, id: response.id });
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
res.status(500).json({ error: 'Internal error' });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// SSE streaming endpoint
|
|
51
|
+
this.app.get('/stream', (req, res) => {
|
|
52
|
+
res.writeHead(200, {
|
|
53
|
+
'Content-Type': 'text/event-stream',
|
|
54
|
+
'Cache-Control': 'no-cache',
|
|
55
|
+
'Connection': 'keep-alive',
|
|
56
|
+
});
|
|
57
|
+
res.write('data: {"type":"connected"}\n\n');
|
|
58
|
+
const interval = setInterval(() => {
|
|
59
|
+
res.write('data: {"type":"heartbeat"}\n\n');
|
|
60
|
+
}, 30000);
|
|
61
|
+
req.on('close', () => clearInterval(interval));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async start() {
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
this.server = this.app.listen(this.port, () => {
|
|
67
|
+
console.log(`[WebChannel] Listening on port ${this.port}`);
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async stop() {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
if (!this.server)
|
|
75
|
+
return resolve();
|
|
76
|
+
this.server.close((err) => (err ? reject(err) : resolve()));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.WebChannel = WebChannel;
|
|
81
|
+
//# sourceMappingURL=web.js.map
|
package/dist/cli.d.ts
ADDED