va-agent-protocol 0.1.0 → 0.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/README.zh.md +559 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -64,7 +64,7 @@ va-agent-protocol solves this with a **JSON Schema-based contract** — comply w
64
64
 
65
65
  ## Why Frontier Models Need This
66
66
 
67
- 2026 frontier models (Claude Opus 4, GPT-5, Gemini 2.5 Pro) bring extraordinary capabilities: autonomous multi-step reasoning, million-token context windows, and native tool calling. va-agent-protocol is designed to **amplify these strengths** and **guard against remaining weaknesses**.
67
+ 2026 frontier models (Claude Opus 4.6, GPT-5.3-codex, or equivalent) bring extraordinary capabilities: autonomous multi-step reasoning, million-token context windows, and native tool calling. va-agent-protocol is designed to **amplify these strengths** and **guard against remaining weaknesses**.
68
68
 
69
69
  ### Amplifying strengths
70
70
 
package/README.zh.md ADDED
@@ -0,0 +1,559 @@
1
+ # va-agent-protocol
2
+
3
+ [English README](./README.md)
4
+
5
+ [![CI](https://github.com/Vadaski/va-agent-protocol/actions/workflows/ci.yml/badge.svg)](https://github.com/Vadaski/va-agent-protocol/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/va-agent-protocol.svg)](https://www.npmjs.com/package/va-agent-protocol)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ **AI 智能体的 USB 接口 — 调度、验证、编排。**
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────┐
13
+ │ Orchestrator │
14
+ │ (dispatch, schedule, monitor, retry) │
15
+ └──────────────────┬──────────────────────┘
16
+ │ ← va-agent-protocol
17
+ ┌──────────────────┴──────────────────────┐
18
+ │ ┌───────────┐ ┌──────────┐ ┌─────────┐│
19
+ │ │ Claude │ │ Codex │ │ Your ││
20
+ │ │ Code │ │ │ │ Agent ││
21
+ │ └───────────┘ └──────────┘ └─────────┘│
22
+ │ Any CLI agent │
23
+ └──────────────────────────────────────────┘
24
+ ```
25
+
26
+ ### 立即体验
27
+
28
+ ```bash
29
+ npx va-orchestrate agents --project-root .
30
+ ```
31
+
32
+ ---
33
+
34
+ ## 协议对比
35
+
36
+ va-agent-protocol 与 MCP 和 A2A 的关系如何?它们是**互补**的,而非竞争关系:
37
+
38
+ | 维度 | MCP (Anthropic) | A2A (Google) | va-agent-protocol |
39
+ |------|----------------|-------------|-------------------|
40
+ | **关注点** | 工具级上下文 | 智能体发现 + 协调 | 长任务执行 + 证据验证 |
41
+ | **任务类型** | 短同步工具调用 | 发现 + 路由 | 长任务 + 自动拓扑 + 调度器 |
42
+ | **时间模型** | 同步 | 异步(推送) | 异步(轮询;v0.2 推送) |
43
+ | **验证** | 返回值 = 结果 | 弱验证 | CLI 关卡 + 模型评估 + 陷阱机制 |
44
+ | **编排** | 无 | 基本路由 | 拓扑排序 + 能力匹配 + 并发控制 |
45
+ | **失败学习** | 无 | 无 | 陷阱积累 |
46
+ | **互操作** | — | 兼容 MCP | 与 MCP 和 A2A 互补 |
47
+
48
+ > **一句话总结** — MCP 将模型连接到工具。A2A 将智能体连接到智能体。va-agent-protocol 确保工作真正被正确完成。
49
+
50
+ ---
51
+
52
+ ## 为什么需要它
53
+
54
+ AI 智能体可以自主编写代码、审查代码和测试代码。但每个智能体都有自己的接口。目前没有标准方法来:
55
+
56
+ - **调度**任务给智能体,附带目标和约束条件
57
+ - **监控**智能体工作时的实时进度
58
+ - **收集证据**证明任务确实完成了(而不仅仅是自我认证)
59
+ - **重试**并附带先前失败的上下文
60
+ - **组合**具有不同能力的多个智能体
61
+
62
+ va-agent-protocol 通过**基于 JSON Schema 的契约**解决了这个问题 — 遵循规范,你的智能体就能接入任何编排器。
63
+
64
+ ---
65
+
66
+ ## 前沿模型为何需要它
67
+
68
+ 2026 年的前沿模型(Claude Opus 4.6、GPT-5.3-codex 或同等模型)带来了非凡的能力:自主多步推理、百万 token 上下文窗口和原生工具调用。va-agent-protocol 旨在**放大这些优势**并**防范遗留的弱点**。
69
+
70
+ ### 放大优势
71
+
72
+ - **目标驱动的委派** — 任务定义要实现什么(WHAT),而不是如何实现(HOW)。模型的推理能力得到充分释放。
73
+ - **并行任务调度** — 编排器并发调度独立任务,充分利用前沿模型原生的并行工具编排能力。
74
+ - **长上下文感知** — 任务契约、陷阱指南和证据载荷专为能够在上下文中容纳整个项目的模型而设计。
75
+
76
+ ### 防范弱点
77
+
78
+ - **证据关卡防止幻觉** — 智能体无法自我认证完成。CLI 命令和模型评估关卡产生客观的通过/失败信号。"我认为完成了"不等于"确实完成了"。
79
+ - **陷阱积累防止重复犯错** — 来自过去尝试的结构化失败元数据被作为硬约束注入重试。系统随时间推移变得越来越难以欺骗。
80
+ - **模型评估关卡** — 对于主观质量(代码风格、内容语调),AI 评审者使用分数阈值和三级决策(通过 / 阻塞待人工审核 / 失败+重试)。
81
+
82
+ > **一句话:** 信任模型的推理能力;使用确定性机制捕捉其盲点。
83
+
84
+ ---
85
+
86
+ ## 设计原则
87
+
88
+ 继承自 [va-auto-pilot](https://github.com/Vadaski/va-auto-pilot):
89
+
90
+ 1. **目标驱动,而非步骤驱动** — 任务定义要实现什么(WHAT),而不是如何实现(HOW)
91
+ 2. **CLI 优先** — 智能体通过子进程调用,而非库导入
92
+ 3. **基于证据的完成** — 用关卡结果和产出物"证明完成",而非"相信我"
93
+ 4. **约定优于配置** — 遵循 JSON Schema,即可兼容
94
+ 5. **失败知识积累** — 每次重试都会收到先前失败的陷阱信息
95
+
96
+ ---
97
+
98
+ ## 快速开始
99
+
100
+ ```bash
101
+ npm install va-agent-protocol
102
+ ```
103
+
104
+ ### 1. 定义任务
105
+
106
+ ```typescript
107
+ import type { TaskUnit } from "va-agent-protocol";
108
+
109
+ const task: TaskUnit = {
110
+ id: "TASK-001",
111
+ objective: "Implement user authentication with JWT",
112
+ constraints: [
113
+ "Use bcrypt for password hashing",
114
+ "Tokens expire in 24 hours",
115
+ ],
116
+ acceptanceCriteria: [
117
+ "npm run typecheck passes",
118
+ "npm test passes with all auth tests",
119
+ "No CRITICAL findings in code review",
120
+ ],
121
+ priority: "P1",
122
+ };
123
+ ```
124
+
125
+ ### 2. 实现适配器(或使用内置适配器)
126
+
127
+ 适配器是"USB 插头" — 它在协议和你的智能体 CLI 之间进行转换:
128
+
129
+ ```typescript
130
+ import type {
131
+ AgentAdapter,
132
+ AgentCapability,
133
+ DispatchResult,
134
+ PollResult,
135
+ TaskUnit,
136
+ } from "va-agent-protocol";
137
+ import { generateCorrelationId } from "va-agent-protocol";
138
+
139
+ class MyAgentAdapter implements AgentAdapter {
140
+ readonly id = "my-agent";
141
+
142
+ capabilities(): AgentCapability {
143
+ return {
144
+ agentId: this.id,
145
+ name: "My Custom Agent",
146
+ version: "1.0.0",
147
+ capabilities: ["code-generation", "testing"],
148
+ modelRequirement: "frontier",
149
+ interface: {
150
+ type: "cli",
151
+ command: "my-agent-cli",
152
+ },
153
+ constraints: {
154
+ maxConcurrent: 2,
155
+ maxRetries: 3,
156
+ },
157
+ };
158
+ }
159
+
160
+ async dispatch(task: TaskUnit): Promise<DispatchResult> {
161
+ const correlationId = generateCorrelationId();
162
+ // Spawn your agent process here
163
+ return { correlationId, accepted: true };
164
+ }
165
+
166
+ async poll(correlationId: string): Promise<PollResult> {
167
+ // Check your agent's state
168
+ return {
169
+ correlationId,
170
+ state: "running",
171
+ progress: {
172
+ taskId: "TASK-001",
173
+ phase: "implementing",
174
+ summary: "Writing authentication middleware...",
175
+ completionEstimate: 0.4,
176
+ logs: [{
177
+ timestamp: new Date().toISOString(),
178
+ level: "info",
179
+ message: "Created src/auth/middleware.ts",
180
+ }],
181
+ data: { linesWritten: 87 },
182
+ },
183
+ };
184
+ }
185
+
186
+ async cancel(correlationId: string): Promise<void> {
187
+ // Kill the agent process
188
+ }
189
+ }
190
+ ```
191
+
192
+ ### 3. 编排
193
+
194
+ ```typescript
195
+ import {
196
+ AgentRegistry,
197
+ Orchestrator,
198
+ } from "va-agent-protocol";
199
+
200
+ const registry = new AgentRegistry();
201
+ registry.register(new MyAgentAdapter());
202
+
203
+ const orchestrator = new Orchestrator(registry, {
204
+ pollIntervalMs: 3000,
205
+ maxRetries: 3,
206
+
207
+ onProgress: (taskId, progress) => {
208
+ console.log(`${taskId}: ${progress.phase} (${Math.round((progress.completionEstimate ?? 0) * 100)}%)`);
209
+ },
210
+
211
+ onCompleted: (taskId, evidence) => {
212
+ console.log(`${taskId} completed!`);
213
+ for (const gate of evidence.gateResults ?? []) {
214
+ console.log(` ${gate.passed ? "✓" : "✗"} ${gate.gate}`);
215
+ }
216
+ },
217
+
218
+ onFailed: (taskId, evidence) => {
219
+ console.error(`${taskId} failed: ${evidence.failureDetail?.hypothesis}`);
220
+ },
221
+
222
+ onBlocked: (taskId, reason) => {
223
+ console.log(`${taskId} needs human input: ${reason}`);
224
+ },
225
+ });
226
+
227
+ orchestrator.enqueue(task);
228
+ orchestrator.start();
229
+ ```
230
+
231
+ ---
232
+
233
+ ## 协议 Schema
234
+
235
+ 协议由 `schemas/` 目录中的 5 个 JSON Schema 定义:
236
+
237
+ | Schema | 用途 |
238
+ |--------|------|
239
+ | [`task-unit.schema.json`](schemas/task-unit.schema.json) | 通用任务契约(目标 + 约束 + 验收标准) |
240
+ | [`agent-capability.schema.json`](schemas/agent-capability.schema.json) | 智能体自描述(能力、接口、约束) |
241
+ | [`lifecycle.schema.json`](schemas/lifecycle.schema.json) | 任务状态机和有效转换 |
242
+ | [`evidence.schema.json`](schemas/evidence.schema.json) | 完成证明(关卡结果、产出物、失败详情) |
243
+ | [`message.schema.json`](schemas/message.schema.json) | 编排器与智能体之间的通信信封 |
244
+
245
+ ### 任务生命周期
246
+
247
+ ```
248
+ pending → running → completed
249
+
250
+ blocked → running (after human input)
251
+
252
+ failed → running (retry with pitfall context)
253
+ ```
254
+
255
+ ### 基于证据的完成
256
+
257
+ 任务不能自我认证完成。它们必须提供**证据**:
258
+
259
+ ```json
260
+ {
261
+ "taskId": "TASK-001",
262
+ "status": "completed",
263
+ "gateResults": [
264
+ {
265
+ "gate": "typecheck",
266
+ "command": "npm run typecheck",
267
+ "exitCode": 0,
268
+ "passed": true,
269
+ "durationMs": 1200
270
+ },
271
+ {
272
+ "gate": "unit-tests",
273
+ "command": "npm test",
274
+ "exitCode": 0,
275
+ "passed": true,
276
+ "output": "42 tests passed, 0 failed"
277
+ }
278
+ ],
279
+ "artifacts": [
280
+ { "type": "commit", "path": "a1b2c3d", "description": "Implement JWT auth" }
281
+ ],
282
+ "verification": "All 3 quality gates passed."
283
+ }
284
+ ```
285
+
286
+ ### 模型评估关卡
287
+
288
+ 并非所有质量关卡都是 CLI 命令。对于主观或 AI 评判的评估(风格一致性、代码质量评分、内容审查),关卡支持 `model-evaluation` 类型:
289
+
290
+ ```json
291
+ {
292
+ "gate": "style-consistency",
293
+ "type": "model-evaluation",
294
+ "evaluator": "style-similarity-agent",
295
+ "score": 0.85,
296
+ "threshold": 0.8,
297
+ "softThreshold": 0.65,
298
+ "passed": true,
299
+ "rationale": "Sentence rhythm and vocabulary match. Tone slightly more formal."
300
+ }
301
+ ```
302
+
303
+ 当 `passed: false` 时,`severity` 字段控制响应:
304
+ - `"error"` — 硬失败(编排器重试)
305
+ - `"warning"` — 软失败(编排器可能路由到 `blocked` 状态以供人工审核)
306
+
307
+ `softThreshold` 启用三级决策:低于软阈值 = 失败+重试,介于软阈值和硬阈值之间 = 阻塞待人工审核,高于硬阈值 = 通过。
308
+
309
+ ### 任务输入/输出
310
+
311
+ 任务可以声明类型化的输入和输出。编排器自动解析依赖任务之间的数据引用:
312
+
313
+ ```typescript
314
+ const extractSchema: TaskUnit = {
315
+ id: "SCHEMA-001",
316
+ objective: "Extract API schema definitions",
317
+ outputContract: { keys: ["apiSchema"] }, // Declares what this task produces
318
+ // ...
319
+ };
320
+
321
+ const generateClient: TaskUnit = {
322
+ id: "CLIENT-001",
323
+ dependsOn: ["SCHEMA-001"],
324
+ inputs: {
325
+ schema: { fromTask: "SCHEMA-001", outputKey: "apiSchema" }, // Resolved by orchestrator
326
+ language: "typescript", // Static input
327
+ },
328
+ // ...
329
+ };
330
+ ```
331
+
332
+ ### 失败 → 陷阱 → 重试
333
+
334
+ 当任务失败时,编排器捕获结构化的失败元数据,并将其作为 `pitfalls` 注入重试上下文:
335
+
336
+ ```
337
+ Attempt 1: Agent implements feature → tests fail on edge case
338
+ ↓ failureDetail captured
339
+ Attempt 2: Agent receives pitfall context →
340
+ "Previous attempt failed: missing null check for empty array input"
341
+ → Agent handles edge case → tests pass
342
+ ```
343
+
344
+ ---
345
+
346
+ ## 进度报告
347
+
348
+ 智能体通过 `ProgressPayload` 报告进度:
349
+
350
+ ```typescript
351
+ {
352
+ taskId: "TASK-001",
353
+ phase: "implementing", // Current execution phase
354
+ summary: "Writing auth module", // Human-readable status
355
+ completionEstimate: 0.4, // 0.0 → 1.0
356
+ logs: [{ // Structured log entries
357
+ timestamp: "2026-02-24T...",
358
+ level: "info",
359
+ message: "Created src/auth/middleware.ts"
360
+ }],
361
+ data: { // Arbitrary structured data
362
+ linesWritten: 87,
363
+ currentFile: "src/auth/middleware.ts"
364
+ }
365
+ }
366
+ ```
367
+
368
+ ---
369
+
370
+ ## 多智能体调度
371
+
372
+ 注册具有不同能力的智能体。调度器将任务匹配到最合适的智能体:
373
+
374
+ ```typescript
375
+ registry.register(codeAgent); // capabilities: ["code-generation", "testing"]
376
+ registry.register(reviewAgent); // capabilities: ["code-review", "security-audit"]
377
+
378
+ // Scheduler auto-routes:
379
+ // "Implement feature X" → codeAgent (matched "code-generation")
380
+ // "Audit API security" → reviewAgent (matched "security-audit")
381
+ ```
382
+
383
+ 并发限制会被遵守。如果智能体达到最大容量,任务会排队等待空位。
384
+
385
+ ---
386
+
387
+ ## 任务依赖
388
+
389
+ 任务可以声明依赖关系。编排器按拓扑顺序调度它们:
390
+
391
+ ```typescript
392
+ const tasks = [
393
+ { id: "TASK-001", objective: "Build core module", ... },
394
+ { id: "TASK-002", objective: "Add tests", dependsOn: ["TASK-001"], ... },
395
+ { id: "TASK-003", objective: "Write docs", ... }, // No deps, runs in parallel
396
+ ];
397
+
398
+ orchestrator.enqueue(...tasks);
399
+ // TASK-001 and TASK-003 dispatch immediately (parallel)
400
+ // TASK-002 waits for TASK-001 to complete
401
+ ```
402
+
403
+ ---
404
+
405
+ ## 内置适配器:va-auto-pilot
406
+
407
+ 第一个适配器封装了 [va-auto-pilot](https://github.com/Vadaski/va-auto-pilot) 的 sprint-board CLI:
408
+
409
+ ```typescript
410
+ import { VaAutoPilotAdapter, AgentRegistry, Orchestrator } from "va-agent-protocol";
411
+
412
+ const adapter = new VaAutoPilotAdapter({
413
+ projectRoot: "/path/to/your/project",
414
+ });
415
+
416
+ const registry = new AgentRegistry();
417
+ registry.register(adapter);
418
+ ```
419
+
420
+ ---
421
+
422
+ ## CLI
423
+
424
+ ```bash
425
+ # List registered agents
426
+ npx va-orchestrate agents --project-root ./my-project
427
+
428
+ # Dispatch a task from JSON file
429
+ npx va-orchestrate dispatch --task task.json --project-root ./my-project
430
+ ```
431
+
432
+ ---
433
+
434
+ ## 运行示例
435
+
436
+ ```bash
437
+ npm run example
438
+ ```
439
+
440
+ 这将展示多智能体注册、能力匹配、任务依赖排序、实时进度、质量关卡证据、失败 → 陷阱 → 重试、阻塞状态上报以及实时终端仪表板。
441
+
442
+ ---
443
+
444
+ ## 实现你自己的适配器
445
+
446
+ 适配器是"USB 插头" — 是你为使智能体兼容协议而编写的唯一代码。实现 `AgentAdapter` 接口:
447
+
448
+ ```typescript
449
+ import type {
450
+ AgentAdapter,
451
+ AgentCapability,
452
+ DispatchResult,
453
+ PollResult,
454
+ TaskUnit,
455
+ } from "va-agent-protocol";
456
+ import { generateCorrelationId } from "va-agent-protocol";
457
+
458
+ class MyAgentAdapter implements AgentAdapter {
459
+ readonly id = "my-agent";
460
+
461
+ capabilities(): AgentCapability {
462
+ return {
463
+ agentId: this.id,
464
+ name: "My Agent",
465
+ version: "1.0.0",
466
+ capabilities: ["code-generation"],
467
+ interface: { type: "cli", command: "my-agent-cli" },
468
+ constraints: { maxConcurrent: 2 },
469
+ };
470
+ }
471
+
472
+ async dispatch(task: TaskUnit): Promise<DispatchResult> {
473
+ const correlationId = generateCorrelationId();
474
+ return { correlationId, accepted: true };
475
+ }
476
+
477
+ async poll(correlationId: string): Promise<PollResult> {
478
+ return { correlationId, state: "running" };
479
+ }
480
+
481
+ async cancel(correlationId: string): Promise<void> {}
482
+ }
483
+ ```
484
+
485
+ 完整的实际示例请参见 `src/adapter/codex-adapter.ts`。
486
+
487
+ ---
488
+
489
+ ## 架构
490
+
491
+ ```
492
+ va-agent-protocol/
493
+ ├── schemas/ # JSON Schema definitions (THE SPEC)
494
+ │ ├── task-unit.schema.json
495
+ │ ├── agent-capability.schema.json
496
+ │ ├── lifecycle.schema.json
497
+ │ ├── evidence.schema.json
498
+ │ └── message.schema.json
499
+ ├── src/
500
+ │ ├── types/ # TypeScript types (mirror schemas)
501
+ │ ├── adapter/ # Agent adapter interface + implementations
502
+ │ │ ├── agent-adapter.ts # The "USB plug shape"
503
+ │ │ ├── codex-adapter.ts # OpenAI Codex CLI adapter
504
+ │ │ └── va-auto-pilot-adapter.ts
505
+ │ ├── orchestrator/ # Dispatch loop + scheduling
506
+ │ │ ├── registry.ts # Agent discovery
507
+ │ │ ├── scheduler.ts # Task → agent matching
508
+ │ │ └── orchestrator.ts # Core loop
509
+ │ └── utils/
510
+ │ └── logger.ts # Configurable logger interface
511
+ ├── examples/
512
+ │ └── full-lifecycle.ts # Comprehensive demo
513
+ └── bin/
514
+ └── va-orchestrate.mjs # CLI entry point
515
+ ```
516
+
517
+ ---
518
+
519
+ ## 路线图
520
+
521
+ ### v0.2
522
+
523
+ - **MCP 服务器适配器** — 将 va-agent-protocol 作为 MCP 工具服务器暴露
524
+ - **持久化** — 基于 SQLite 的编排器状态,支持崩溃恢复
525
+ - **推送式进度** — 智能体通过 stdio/WebSocket 主动推送进度,替代轮询
526
+ - **子编排** — 智能体可以生成子任务,反馈回编排器
527
+ - **Web 仪表板** — 实时任务可视化和监控
528
+ - **扩展点** — 更多 Schema 对象上的 `metadata` 字段,放宽 `additionalProperties`
529
+
530
+ ### v0.3
531
+
532
+ - **REST / gRPC 适配器**,用于非 CLI 集成
533
+ - **治理** — 成本护栏 + 权限范围控制
534
+ - **A2A 桥接** — 与 Google A2A 的双向智能体发现和任务委派
535
+
536
+ ### 未来
537
+
538
+ - **多语言 SDK** — Python、Go 协议实现
539
+ - **分布式编排** — 多个编排器实例共享状态
540
+ - **适配器生态系统** — Claude Code、Cursor、Aider 及其他 CLI 智能体适配器
541
+ - **Agentic AI Foundation** 贡献
542
+
543
+ ---
544
+
545
+ ## v0.1 已知限制
546
+
547
+ 这些是 v0.1 的有意范围约束,不是 bug:
548
+
549
+ - **仅内存状态** — 持久化/恢复计划在 v0.2 实现
550
+ - **基于轮询的进度** — 智能体主动推送计划在 v0.2+ 实现
551
+ - **严格 Schema** — `additionalProperties: false`;v0.2 将引入扩展点
552
+ - **无子编排** — v0.2+ 功能
553
+ - **单一调度启发式** — 能力匹配使用关键词推断;生产部署应提供显式能力标签
554
+
555
+ ---
556
+
557
+ ## 许可证
558
+
559
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "va-agent-protocol",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Universal agent task protocol — the USB interface for CLI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "yaml": "^2.8.2"
36
36
  },
37
37
  "optionalDependencies": {
38
- "va-auto-pilot": "file:../auto-pilot"
38
+ "va-auto-pilot": "^0.1.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^22.0.0",