network-ai 4.0.16 → 4.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/README.md +152 -64
- package/dist/adapters/a2a-adapter.d.ts +152 -0
- package/dist/adapters/a2a-adapter.d.ts.map +1 -0
- package/dist/adapters/a2a-adapter.js +235 -0
- package/dist/adapters/a2a-adapter.js.map +1 -0
- package/dist/adapters/custom-streaming-adapter.d.ts +68 -0
- package/dist/adapters/custom-streaming-adapter.d.ts.map +1 -0
- package/dist/adapters/custom-streaming-adapter.js +181 -0
- package/dist/adapters/custom-streaming-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +12 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/langchain-streaming-adapter.d.ts +48 -0
- package/dist/adapters/langchain-streaming-adapter.d.ts.map +1 -0
- package/dist/adapters/langchain-streaming-adapter.js +161 -0
- package/dist/adapters/langchain-streaming-adapter.js.map +1 -0
- package/dist/adapters/streaming-base-adapter.d.ts +42 -0
- package/dist/adapters/streaming-base-adapter.d.ts.map +1 -0
- package/dist/adapters/streaming-base-adapter.js +68 -0
- package/dist/adapters/streaming-base-adapter.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/run.js +1 -0
- package/dist/run.js.map +1 -1
- package/package.json +6 -4
- package/types/streaming-adapter.d.ts +63 -0
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# Network-AI
|
|
2
2
|
|
|
3
3
|
**TypeScript/Node.js multi-agent orchestrator — shared state, guardrails, budgets, and cross-framework coordination**
|
|
4
4
|
|
|
5
5
|
[](https://github.com/jovanSAPFIONEER/Network-AI/actions/workflows/ci.yml)
|
|
6
6
|
[](https://github.com/jovanSAPFIONEER/Network-AI/actions/workflows/codeql.yml)
|
|
7
|
-
[](https://github.com/jovanSAPFIONEER/Network-AI/releases)
|
|
8
8
|
[](https://www.npmjs.com/package/network-ai)
|
|
9
|
-
[](#testing)
|
|
10
|
+
[](#adapter-system)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://socket.dev/npm/package/network-ai/overview)
|
|
13
13
|
[](https://nodejs.org)
|
|
@@ -19,7 +19,13 @@ Network-AI is a TypeScript/Node.js multi-agent orchestrator that adds coordinati
|
|
|
19
19
|
|
|
20
20
|
- **Shared blackboard with locking** — atomic `propose → validate → commit` prevents race conditions and split-brain failures across parallel agents
|
|
21
21
|
- **Guardrails and budgets** — FSM governance, per-agent token ceilings, HMAC audit trails, and permission gating
|
|
22
|
-
- **
|
|
22
|
+
- **13 adapters** — LangChain (+ streaming), AutoGen, CrewAI, OpenAI Assistants, LlamaIndex, Semantic Kernel, Haystack, DSPy, Agno, MCP, Custom (+ streaming), OpenClaw, and A2A — no glue code, no lock-in
|
|
23
|
+
|
|
24
|
+
> **The silent failure mode in multi-agent systems:** parallel agents writing to the same key
|
|
25
|
+
> use last-write-wins by default — one agent's result silently overwrites another's mid-flight.
|
|
26
|
+
> The outcome is split-brain state: double-spends, contradictory decisions, corrupted context,
|
|
27
|
+
> no error thrown. Network-AI's `propose → validate → commit` mutex prevents this at the
|
|
28
|
+
> coordination layer, before any write reaches shared state.
|
|
23
29
|
|
|
24
30
|
**Use Network-AI as:**
|
|
25
31
|
- A **TypeScript/Node.js library** — `import { createSwarmOrchestrator } from 'network-ai'`
|
|
@@ -28,6 +34,15 @@ Network-AI is a TypeScript/Node.js multi-agent orchestrator that adds coordinati
|
|
|
28
34
|
|
|
29
35
|
[**5-minute quickstart →**](QUICKSTART.md) | [**Architecture →**](ARCHITECTURE.md) | [**All adapters →**](#adapter-system) | [**Benchmarks →**](BENCHMARKS.md)
|
|
30
36
|
|
|
37
|
+
> **Try the control-plane stress test — no API key, ~3 seconds:**
|
|
38
|
+
> ```bash
|
|
39
|
+
> npx ts-node examples/08-control-plane-stress-demo.ts
|
|
40
|
+
> ```
|
|
41
|
+
> Runs priority preemption, AuthGuardian permission gating, FSM governance, and compliance
|
|
42
|
+
> monitoring against a live swarm. No external services required.
|
|
43
|
+
>
|
|
44
|
+
> If it saves you from a race condition, a ⭐ helps others find it.
|
|
45
|
+
|
|
31
46
|
---
|
|
32
47
|
|
|
33
48
|
## Why teams use Network-AI
|
|
@@ -37,38 +52,44 @@ Network-AI is a TypeScript/Node.js multi-agent orchestrator that adds coordinati
|
|
|
37
52
|
| Race conditions in parallel agents | Atomic blackboard: `propose → validate → commit` with file-system mutex |
|
|
38
53
|
| Agent overspend / runaway costs | `FederatedBudget` — hard per-agent token ceilings with live spend tracking |
|
|
39
54
|
| No visibility into what agents did | HMAC-signed audit log on every write, permission grant, and FSM transition |
|
|
40
|
-
| Locked into one AI framework |
|
|
55
|
+
| Locked into one AI framework | 13 adapters — mix LangChain + AutoGen + CrewAI + A2A + custom in one swarm |
|
|
41
56
|
| Agents escalating beyond their scope | `AuthGuardian` — scoped permission tokens required before sensitive operations |
|
|
42
57
|
|
|
43
58
|
---
|
|
44
59
|
|
|
45
60
|
## Architecture
|
|
46
61
|
|
|
62
|
+
```mermaid
|
|
63
|
+
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#1e293b', 'primaryTextColor': '#e2e8f0', 'primaryBorderColor': '#475569', 'lineColor': '#94a3b8', 'clusterBkg': '#0f172a', 'clusterBorder': '#334155', 'edgeLabelBackground': '#1e293b', 'edgeLabelColor': '#cbd5e1', 'titleColor': '#e2e8f0'}}}%%
|
|
64
|
+
flowchart TD
|
|
65
|
+
classDef app fill:#1e3a5f,stroke:#3b82f6,color:#bfdbfe,font-weight:bold
|
|
66
|
+
classDef security fill:#451a03,stroke:#d97706,color:#fde68a
|
|
67
|
+
classDef routing fill:#14532d,stroke:#16a34a,color:#bbf7d0
|
|
68
|
+
classDef quality fill:#3b0764,stroke:#9333ea,color:#e9d5ff
|
|
69
|
+
classDef blackboard fill:#0c4a6e,stroke:#0284c7,color:#bae6fd
|
|
70
|
+
classDef adapters fill:#064e3b,stroke:#059669,color:#a7f3d0
|
|
71
|
+
classDef audit fill:#1e293b,stroke:#475569,color:#94a3b8
|
|
72
|
+
|
|
73
|
+
App["Your Application"]:::app
|
|
74
|
+
App -->|"createSwarmOrchestrator()"| SO
|
|
75
|
+
|
|
76
|
+
subgraph SO["SwarmOrchestrator"]
|
|
77
|
+
AG["AuthGuardian\n(permission gating)"]:::security
|
|
78
|
+
AR["AdapterRegistry\n(route tasks to frameworks)"]:::routing
|
|
79
|
+
QG["QualityGateAgent\n(validate blackboard writes)"]:::quality
|
|
80
|
+
BB["SharedBlackboard\n(shared agent state)\npropose → validate → commit\nfilesystem mutex"]:::blackboard
|
|
81
|
+
AD["Adapters — plug any framework in, swap freely\nLangChain · AutoGen · CrewAI · MCP · LlamaIndex · …"]:::adapters
|
|
82
|
+
|
|
83
|
+
AG -->|"grant / deny"| AR
|
|
84
|
+
AR -->|"tasks dispatched"| AD
|
|
85
|
+
AD -->|"writes results"| BB
|
|
86
|
+
QG -->|"validates"| BB
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
SO --> AUDIT["data/audit_log.jsonl"]:::audit
|
|
47
90
|
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
└──────────────────────────┬──────────────────────────────────┘
|
|
51
|
-
│ createSwarmOrchestrator()
|
|
52
|
-
┌──────────────────────────▼──────────────────────────────────┐
|
|
53
|
-
│ SwarmOrchestrator │
|
|
54
|
-
│ ┌──────────────┐ ┌───────────────┐ ┌─────────────────┐ │
|
|
55
|
-
│ │ AdapterRegistry│ │ AuthGuardian │ │ FederatedBudget │ │
|
|
56
|
-
│ │ (route tasks) │ │ (permissions) │ │ (token ceilings)│ │
|
|
57
|
-
│ └──────┬───────┘ └───────────────┘ └─────────────────┘ │
|
|
58
|
-
│ │ │
|
|
59
|
-
│ ┌──────▼──────────────────────────────────────────────┐ │
|
|
60
|
-
│ │ LockedBlackboard (shared state) │ │
|
|
61
|
-
│ │ propose → validate → commit (file-system mutex) │ │
|
|
62
|
-
│ └──────────────────────────────────────────────────────┘ │
|
|
63
|
-
│ │ │
|
|
64
|
-
│ ┌──────▼───────────────────────────────────────────────┐ │
|
|
65
|
-
│ │ Adapters (plug any framework in, swap out freely) │ │
|
|
66
|
-
│ │ LangChain │ AutoGen │ CrewAI │ MCP │ LlamaIndex │… │ │
|
|
67
|
-
│ └──────────────────────────────────────────────────────┘ │
|
|
68
|
-
└─────────────────────────────────────────────────────────────┘
|
|
69
|
-
│
|
|
70
|
-
HMAC-signed audit log
|
|
71
|
-
```
|
|
91
|
+
|
|
92
|
+
> `FederatedBudget` is a standalone export — instantiate it separately and optionally wire it to a blackboard backend for cross-node token budget enforcement.
|
|
72
93
|
|
|
73
94
|
→ [Full architecture, FSM journey, and handoff protocol](ARCHITECTURE.md)
|
|
74
95
|
|
|
@@ -84,6 +105,64 @@ No native dependencies, no build step. Adapters are dependency-free (BYOC — br
|
|
|
84
105
|
|
|
85
106
|
---
|
|
86
107
|
|
|
108
|
+
## Use as MCP Server
|
|
109
|
+
|
|
110
|
+
Start the server (no config required, zero dependencies):
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npx network-ai-server --port 3001
|
|
114
|
+
# or from source:
|
|
115
|
+
npx ts-node bin/mcp-server.ts --port 3001
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Then wire any MCP-compatible client to it.
|
|
119
|
+
|
|
120
|
+
**Claude Desktop** — add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"mcpServers": {
|
|
125
|
+
"network-ai": {
|
|
126
|
+
"url": "http://localhost:3001/sse"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Cursor / Cline / any SSE-based MCP client** — point to the same URL:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"mcpServers": {
|
|
137
|
+
"network-ai": {
|
|
138
|
+
"url": "http://localhost:3001/sse"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Verify it's running:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
curl http://localhost:3001/health # { "status": "ok", "tools": <n>, "uptime": <ms> }
|
|
148
|
+
curl http://localhost:3001/tools # full tool list
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Tools exposed over MCP:**
|
|
152
|
+
- `blackboard_read` / `blackboard_write` / `blackboard_list` / `blackboard_delete` / `blackboard_exists`
|
|
153
|
+
- `budget_status` / `budget_spend` / `budget_reset` — federated token tracking
|
|
154
|
+
- `token_create` / `token_validate` / `token_revoke` — HMAC-signed permission tokens
|
|
155
|
+
- `audit_query` — query the append-only audit log
|
|
156
|
+
- `config_get` / `config_set` — live orchestrator configuration
|
|
157
|
+
- `agent_list` / `agent_spawn` / `agent_stop` — agent lifecycle
|
|
158
|
+
- `fsm_transition` — write FSM state transitions to the blackboard
|
|
159
|
+
|
|
160
|
+
Each tool takes an `agent_id` parameter — all writes are identity-verified and namespace-scoped, exactly as they are in the TypeScript API.
|
|
161
|
+
|
|
162
|
+
Options: `--no-budget`, `--no-token`, `--no-control`, `--ceiling <n>`, `--board <name>`, `--audit-log <path>`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
87
166
|
## Two agents, one shared state — without race conditions
|
|
88
167
|
|
|
89
168
|
The real differentiator is coordination. Here is what no single-framework solution handles: two agents writing to the same resource concurrently, atomically, without corrupting each other.
|
|
@@ -129,13 +208,15 @@ Add budgets, permissions, and cross-framework agents with the same pattern. →
|
|
|
129
208
|
|
|
130
209
|
## Demo — Control-Plane Stress Test *(no API key)*
|
|
131
210
|
|
|
132
|
-
Runs in ~
|
|
211
|
+
Runs in ~3 seconds. Proves the coordination primitives without any LLM calls.
|
|
133
212
|
|
|
134
213
|
```bash
|
|
135
214
|
npm run demo -- --08
|
|
136
215
|
```
|
|
137
216
|
|
|
138
|
-
What it shows: atomic blackboard locking, priority preemption (priority-3 wins over priority-0 on same key), FSM hard-stop at 700 ms, live compliance violation capture (TOOL_ABUSE, TURN_TAKING, RESPONSE_TIMEOUT, JOURNEY_TIMEOUT), and `FederatedBudget` tracking — all without a single API call.
|
|
217
|
+
What it shows: atomic blackboard locking, priority preemption (priority-3 wins over priority-0 on same key), **AuthGuardian permission gate** (blocked → justified → granted with token), FSM hard-stop at 700 ms, live compliance violation capture (TOOL_ABUSE, TURN_TAKING, RESPONSE_TIMEOUT, JOURNEY_TIMEOUT), and `FederatedBudget` tracking — all without a single API call.
|
|
218
|
+
|
|
219
|
+
[](https://www.youtube.com/watch?v=niVRZJu1MEo)
|
|
139
220
|
|
|
140
221
|
**8-agent AI pipeline** (requires `OPENAI_API_KEY` — builds a Payment Processing Service end-to-end):
|
|
141
222
|
|
|
@@ -149,12 +230,12 @@ npm run demo -- --07
|
|
|
149
230
|
|
|
150
231
|
## Adapter System
|
|
151
232
|
|
|
152
|
-
|
|
233
|
+
13 adapters, zero adapter dependencies. You bring your own SDK objects.
|
|
153
234
|
|
|
154
|
-
| Adapter | Framework | Register method |
|
|
235
|
+
| Adapter | Framework / Protocol | Register method |
|
|
155
236
|
|---|---|---|
|
|
156
237
|
| `CustomAdapter` | Any function or HTTP endpoint | `registerHandler(name, fn)` |
|
|
157
|
-
| `LangChainAdapter` | LangChain | `
|
|
238
|
+
| `LangChainAdapter` | LangChain | `registerAgent(name, runnable)` |
|
|
158
239
|
| `AutoGenAdapter` | AutoGen / AG2 | `registerAgent(name, agent)` |
|
|
159
240
|
| `CrewAIAdapter` | CrewAI | `registerAgent` or `registerCrew` |
|
|
160
241
|
| `MCPAdapter` | Model Context Protocol | `registerTool(name, handler)` |
|
|
@@ -165,8 +246,16 @@ npm run demo -- --07
|
|
|
165
246
|
| `DSPyAdapter` | Stanford DSPy | `registerModule()`, `registerProgram()` |
|
|
166
247
|
| `AgnoAdapter` | Agno (formerly Phidata) | `registerAgent()`, `registerTeam()` |
|
|
167
248
|
| `OpenClawAdapter` | OpenClaw | `registerSkill(name, skillRef)` |
|
|
249
|
+
| `A2AAdapter` | Google A2A Protocol | `registerRemoteAgent(name, url)` |
|
|
168
250
|
|
|
169
|
-
|
|
251
|
+
**Streaming variants** (drop-in replacements with `.stream()` support):
|
|
252
|
+
|
|
253
|
+
| Adapter | Extends | Streaming source |
|
|
254
|
+
|---|---|---|
|
|
255
|
+
| `LangChainStreamingAdapter` | `LangChainAdapter` | Calls `.stream()` on the Runnable if available; falls back to `.invoke()` |
|
|
256
|
+
| `CustomStreamingAdapter` | `CustomAdapter` | Pipes `AsyncIterable<string>` handlers; falls back to single-chunk for plain Promises |
|
|
257
|
+
|
|
258
|
+
Extend `BaseAdapter` (or `StreamingBaseAdapter` for streaming) to add your own in minutes. See [references/adapter-system.md](references/adapter-system.md).
|
|
170
259
|
|
|
171
260
|
---
|
|
172
261
|
|
|
@@ -176,12 +265,12 @@ Extend `BaseAdapter` to add your own in minutes. See [references/adapter-system.
|
|
|
176
265
|
|
|
177
266
|
| Capability | Network-AI | LangGraph | CrewAI | AutoGen |
|
|
178
267
|
|---|---|---|---|---|
|
|
179
|
-
| Cross-framework agents in one swarm | ✅
|
|
180
|
-
| Atomic shared state (conflict-safe) | ✅ `propose → validate → commit` | ⚠️
|
|
181
|
-
| Hard
|
|
182
|
-
| Permission gating before sensitive ops | ✅ `AuthGuardian` |
|
|
183
|
-
|
|
|
184
|
-
| Encryption at rest | ✅ AES-256-GCM |
|
|
268
|
+
| Cross-framework agents in one swarm | ✅ 13 built-in adapters | ⚠️ Nodes can call any code; no adapter abstraction | ⚠️ Extensible via tools; CrewAI-native agents only | ⚠️ Extensible via plugins; AutoGen-native agents only |
|
|
269
|
+
| Atomic shared state (conflict-safe) | ✅ `propose → validate → commit` mutex | ⚠️ State passed between nodes; last-write-wins | ⚠️ Shared memory available; no conflict resolution | ⚠️ Shared context available; no conflict resolution |
|
|
270
|
+
| Hard token ceiling per agent | ✅ `FederatedBudget` (first-class API) | ⚠️ Via callbacks / custom middleware | ⚠️ Via callbacks / custom middleware | ⚠️ Built-in token tracking in v0.4+; no swarm-level ceiling |
|
|
271
|
+
| Permission gating before sensitive ops | ✅ `AuthGuardian` (built-in) | ⚠️ Possible via custom node logic | ⚠️ Possible via custom tools | ⚠️ Possible via custom middleware |
|
|
272
|
+
| Append-only audit log | ✅ plain JSONL (`data/audit_log.jsonl`) | ⚠️ Not built-in | ⚠️ Not built-in | ⚠️ Not built-in |
|
|
273
|
+
| Encryption at rest | ✅ AES-256-GCM (TypeScript layer) | ⚠️ Not built-in | ⚠️ Not built-in | ⚠️ Not built-in |
|
|
185
274
|
| Language | TypeScript / Node.js | Python | Python | Python |
|
|
186
275
|
|
|
187
276
|
---
|
|
@@ -192,29 +281,31 @@ Extend `BaseAdapter` to add your own in minutes. See [references/adapter-system.
|
|
|
192
281
|
npm run test:all # All suites in sequence
|
|
193
282
|
npm test # Core orchestrator
|
|
194
283
|
npm run test:security # Security module
|
|
195
|
-
npm run test:adapters # All
|
|
284
|
+
npm run test:adapters # All 13 adapters
|
|
285
|
+
npm run test:streaming # Streaming adapters
|
|
286
|
+
npm run test:a2a # A2A protocol adapter
|
|
196
287
|
npm run test:priority # Priority & preemption
|
|
197
288
|
```
|
|
198
289
|
|
|
199
|
-
**1,
|
|
290
|
+
**1,283 passing assertions across 15 test suites** (`npm run test:all`):
|
|
200
291
|
|
|
201
292
|
| Suite | Assertions | Covers |
|
|
202
293
|
|---|---|---|
|
|
203
|
-
| `test-
|
|
204
|
-
| `test-
|
|
205
|
-
| `test-
|
|
206
|
-
| `test-
|
|
207
|
-
| `test-
|
|
208
|
-
| `test-
|
|
209
|
-
| `test-
|
|
210
|
-
| `test-
|
|
211
|
-
| `test-
|
|
212
|
-
| `test-
|
|
213
|
-
| `test-
|
|
214
|
-
| `test-
|
|
215
|
-
| `test-
|
|
216
|
-
| `test.ts` |
|
|
217
|
-
| `test-
|
|
294
|
+
| `test-phase4.ts` | 147 | FSM governance, compliance monitor, adapter integration |
|
|
295
|
+
| `test-phase5f.ts` | 127 | SSE transport, `McpCombinedBridge`, extended MCP tools |
|
|
296
|
+
| `test-phase5g.ts` | 121 | CRDT backend, vector clocks, bidirectional sync |
|
|
297
|
+
| `test-phase6.ts` | 121 | MCP server, control-plane tools, audit tools |
|
|
298
|
+
| `test-phase5d.ts` | 117 | Pluggable backend (Redis, CRDT, Memory) |
|
|
299
|
+
| `test-adapters.ts` | 139 | All 13 adapters, registry routing, integration, edge cases |
|
|
300
|
+
| `test-standalone.ts` | 88 | Blackboard, auth, integration, persistence, parallelisation, quality gate |
|
|
301
|
+
| `test-phase5e.ts` | 87 | Federated budget tracking |
|
|
302
|
+
| `test-phase5c.ts` | 73 | Named multi-blackboard, isolation, backend options |
|
|
303
|
+
| `test-priority.ts` | 64 | Priority preemption, conflict resolution, backward compat |
|
|
304
|
+
| `test-a2a.ts` | 34 | A2A protocol: register, execute, mock fetch, error paths |
|
|
305
|
+
| `test-streaming.ts` | 31 | Streaming adapters, chunk shapes, fallback, collectStream |
|
|
306
|
+
| `test-phase5b.ts` | 55 | Pluggable backend part 2, consistency levels |
|
|
307
|
+
| `test-phase5.ts` | 42 | Named multi-blackboard base |
|
|
308
|
+
| `test-security.ts` | 34 | Tokens, sanitization, rate limiting, encryption, audit |
|
|
218
309
|
|
|
219
310
|
---
|
|
220
311
|
|
|
@@ -240,17 +331,14 @@ npm run test:priority # Priority & preemption
|
|
|
240
331
|
|
|
241
332
|
1. Fork → feature branch → `npm run test:all` → pull request
|
|
242
333
|
2. Bugs and feature requests via [Issues](https://github.com/jovanSAPFIONEER/Network-AI/issues)
|
|
243
|
-
3. If Network-AI saves you time, a ⭐ helps others find it
|
|
244
|
-
|
|
245
|
-
[](https://github.com/jovanSAPFIONEER/Network-AI)
|
|
246
334
|
|
|
247
335
|
---
|
|
248
336
|
|
|
249
337
|
MIT License — [LICENSE](LICENSE) · [CHANGELOG](CHANGELOG.md) · [CONTRIBUTING](CONTRIBUTING.md) · [](https://github.com/jovanSAPFIONEER/Network-AI/releases.atom)
|
|
250
338
|
|
|
251
339
|
<details>
|
|
252
|
-
<summary>Keywords
|
|
340
|
+
<summary>Keywords</summary>
|
|
253
341
|
|
|
254
|
-
|
|
342
|
+
multi-agent · agent orchestration · AI agents · agentic AI · agentic workflow · TypeScript · Node.js · LangGraph · CrewAI · AutoGen · MCP · model-context-protocol · LlamaIndex · Semantic Kernel · OpenAI Assistants · Haystack · DSPy · Agno · OpenClaw · ClawHub · shared state · blackboard pattern · atomic commits · guardrails · token budgets · permission gating · audit trail · agent coordination · agent handoffs · governance · cost-awareness
|
|
255
343
|
|
|
256
344
|
</details>
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2AAdapter — Agent-to-Agent (A2A) protocol adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements the Google A2A (Agent-to-Agent) open protocol that lets
|
|
5
|
+
* independently hosted agents discover each other through a standard
|
|
6
|
+
* Agent Card (/.well-known/agent.json) and exchange tasks via a
|
|
7
|
+
* JSON-RPC envelope posted to the agent's task endpoint.
|
|
8
|
+
*
|
|
9
|
+
* References:
|
|
10
|
+
* https://google.github.io/A2A/
|
|
11
|
+
* https://github.com/google/A2A
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* const adapter = new A2AAdapter();
|
|
16
|
+
* await adapter.initialize({});
|
|
17
|
+
*
|
|
18
|
+
* // Register a remote agent by its Agent Card URL
|
|
19
|
+
* await adapter.registerRemoteAgent('remote-analyst', 'https://agent.example.com');
|
|
20
|
+
*
|
|
21
|
+
* // Or register a local agent that serves an A2A-compliant card
|
|
22
|
+
* adapter.registerLocalA2AAgent('local-writer', {
|
|
23
|
+
* name: 'Writing Agent',
|
|
24
|
+
* description: 'Draft documents given a topic',
|
|
25
|
+
* version: '1.0',
|
|
26
|
+
* capabilities: { streaming: false },
|
|
27
|
+
* taskEndpoint: 'https://writer.internal/tasks',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* await registry.addAdapter(adapter);
|
|
31
|
+
*
|
|
32
|
+
* // In the orchestrator:
|
|
33
|
+
* delegateTask({ targetAgent: 'a2a:remote-analyst', ... })
|
|
34
|
+
*
|
|
35
|
+
* @module A2AAdapter
|
|
36
|
+
* @version 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
import { BaseAdapter } from './base-adapter';
|
|
39
|
+
import type { AdapterConfig, AdapterCapabilities, AgentPayload, AgentContext, AgentResult } from '../types/agent-adapter';
|
|
40
|
+
/** Agent Card served at /.well-known/agent.json (A2A spec §3.1) */
|
|
41
|
+
export interface A2AAgentCard {
|
|
42
|
+
/** Human-readable agent name */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Purpose / capabilities in plain English */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** SemVer */
|
|
47
|
+
version?: string;
|
|
48
|
+
/** Protocol capabilities declared by the agent */
|
|
49
|
+
capabilities?: {
|
|
50
|
+
streaming?: boolean;
|
|
51
|
+
pushNotifications?: boolean;
|
|
52
|
+
stateTransitionHistory?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/** URL that accepts A2A task envelopes (defaults to <baseUrl>/tasks) */
|
|
55
|
+
taskEndpoint?: string;
|
|
56
|
+
/** Agent homepage or further docs */
|
|
57
|
+
url?: string;
|
|
58
|
+
}
|
|
59
|
+
/** JSON-RPC 2.0 task request envelope sent to the task endpoint (A2A spec §4) */
|
|
60
|
+
export interface A2ATask {
|
|
61
|
+
jsonrpc: '2.0';
|
|
62
|
+
id: string;
|
|
63
|
+
method: 'tasks/send';
|
|
64
|
+
params: {
|
|
65
|
+
id: string;
|
|
66
|
+
message: {
|
|
67
|
+
role: 'user';
|
|
68
|
+
parts: Array<{
|
|
69
|
+
type: 'text';
|
|
70
|
+
text: string;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** State of a running A2A task */
|
|
77
|
+
export type A2ATaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'canceled' | 'failed' | 'unknown';
|
|
78
|
+
/** Artifact produced by the agent (A2A spec §4.3) */
|
|
79
|
+
export interface A2AArtifact {
|
|
80
|
+
name?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
parts: Array<{
|
|
83
|
+
type: string;
|
|
84
|
+
text?: string;
|
|
85
|
+
data?: unknown;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
/** JSON-RPC 2.0 task response (A2A spec §4) */
|
|
89
|
+
export interface A2ATaskResponse {
|
|
90
|
+
jsonrpc: '2.0';
|
|
91
|
+
id: string;
|
|
92
|
+
result?: {
|
|
93
|
+
id: string;
|
|
94
|
+
status: {
|
|
95
|
+
state: A2ATaskState;
|
|
96
|
+
message?: string;
|
|
97
|
+
};
|
|
98
|
+
artifacts?: A2AArtifact[];
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
};
|
|
101
|
+
error?: {
|
|
102
|
+
code: number;
|
|
103
|
+
message: string;
|
|
104
|
+
data?: unknown;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Adapter configuration specific to A2A */
|
|
108
|
+
export interface A2AAdapterConfig extends AdapterConfig {
|
|
109
|
+
/** Default bearer token applied to all agents unless overridden at agent level */
|
|
110
|
+
defaultBearerToken?: string;
|
|
111
|
+
/** Default timeout for all agents in ms (default: 30 000) */
|
|
112
|
+
defaultTimeoutMs?: number;
|
|
113
|
+
/** Custom fetch implementation (for testing / node compat) */
|
|
114
|
+
fetchImpl?: typeof fetch;
|
|
115
|
+
}
|
|
116
|
+
export declare class A2AAdapter extends BaseAdapter {
|
|
117
|
+
readonly name = "a2a";
|
|
118
|
+
readonly version = "1.0.0";
|
|
119
|
+
private a2aAgents;
|
|
120
|
+
private defaultBearerToken?;
|
|
121
|
+
private defaultTimeoutMs;
|
|
122
|
+
private fetchImpl;
|
|
123
|
+
get capabilities(): AdapterCapabilities;
|
|
124
|
+
initialize(config: A2AAdapterConfig): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Fetch the Agent Card from `<baseUrl>/.well-known/agent.json` and register
|
|
127
|
+
* the remote agent for use in the orchestrator.
|
|
128
|
+
*
|
|
129
|
+
* @param agentId - Local identifier (used in `delegate_task` calls)
|
|
130
|
+
* @param baseUrl - Root URL of the remote A2A-compliant agent server
|
|
131
|
+
* @param options - Optional bearer token / timeout override
|
|
132
|
+
*/
|
|
133
|
+
registerRemoteAgent(agentId: string, baseUrl: string, options?: {
|
|
134
|
+
bearerToken?: string;
|
|
135
|
+
timeoutMs?: number;
|
|
136
|
+
}): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Register a local A2A agent whose card you already have (no network fetch).
|
|
139
|
+
* Useful when the card is embedded in config or returned from another service.
|
|
140
|
+
*/
|
|
141
|
+
registerLocalA2AAgent(agentId: string, card: A2AAgentCard & {
|
|
142
|
+
taskEndpoint: string;
|
|
143
|
+
}, options?: {
|
|
144
|
+
bearerToken?: string;
|
|
145
|
+
timeoutMs?: number;
|
|
146
|
+
}): void;
|
|
147
|
+
executeAgent(agentId: string, payload: AgentPayload, context: AgentContext): Promise<AgentResult>;
|
|
148
|
+
private fetchAgentCard;
|
|
149
|
+
private sendTask;
|
|
150
|
+
private extractOutput;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=a2a-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a-adapter.d.ts","sourceRoot":"","sources":["../../adapters/a2a-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;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