va-agent-protocol 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 +21 -0
- package/README.md +558 -0
- package/bin/va-orchestrate.mjs +153 -0
- package/dist/adapter/agent-adapter.d.ts +79 -0
- package/dist/adapter/agent-adapter.d.ts.map +1 -0
- package/dist/adapter/agent-adapter.js +36 -0
- package/dist/adapter/agent-adapter.js.map +1 -0
- package/dist/adapter/codex-adapter.d.ts +54 -0
- package/dist/adapter/codex-adapter.d.ts.map +1 -0
- package/dist/adapter/codex-adapter.js +409 -0
- package/dist/adapter/codex-adapter.js.map +1 -0
- package/dist/adapter/va-auto-pilot-adapter.d.ts +51 -0
- package/dist/adapter/va-auto-pilot-adapter.d.ts.map +1 -0
- package/dist/adapter/va-auto-pilot-adapter.js +275 -0
- package/dist/adapter/va-auto-pilot-adapter.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +101 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +452 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator/registry.d.ts +39 -0
- package/dist/orchestrator/registry.d.ts.map +1 -0
- package/dist/orchestrator/registry.js +62 -0
- package/dist/orchestrator/registry.js.map +1 -0
- package/dist/orchestrator/scheduler.d.ts +66 -0
- package/dist/orchestrator/scheduler.d.ts.map +1 -0
- package/dist/orchestrator/scheduler.js +155 -0
- package/dist/orchestrator/scheduler.js.map +1 -0
- package/dist/test/orchestrator-enqueue.test.d.ts +2 -0
- package/dist/test/orchestrator-enqueue.test.d.ts.map +1 -0
- package/dist/test/orchestrator-enqueue.test.js +64 -0
- package/dist/test/orchestrator-enqueue.test.js.map +1 -0
- package/dist/test/orchestrator-lifecycle.test.d.ts +2 -0
- package/dist/test/orchestrator-lifecycle.test.d.ts.map +1 -0
- package/dist/test/orchestrator-lifecycle.test.js +227 -0
- package/dist/test/orchestrator-lifecycle.test.js.map +1 -0
- package/dist/test/scheduler.test.d.ts +2 -0
- package/dist/test/scheduler.test.d.ts.map +1 -0
- package/dist/test/scheduler.test.js +140 -0
- package/dist/test/scheduler.test.js.map +1 -0
- package/dist/types/index.d.ts +209 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +45 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +17 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +21 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +61 -0
- package/schemas/agent-capability.schema.json +99 -0
- package/schemas/evidence.schema.json +201 -0
- package/schemas/lifecycle.schema.json +80 -0
- package/schemas/message.schema.json +181 -0
- package/schemas/task-unit.schema.json +137 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestrator — the core dispatch loop.
|
|
3
|
+
*
|
|
4
|
+
* Reads task queue → matches to agents → dispatches → collects results.
|
|
5
|
+
*
|
|
6
|
+
* Design:
|
|
7
|
+
* - Polling-based (v0.1): orchestrator drives the loop, not event-driven
|
|
8
|
+
* - Single-threaded dispatch with async execution
|
|
9
|
+
* - Retry policy is configurable
|
|
10
|
+
* - Human escalation on blocked tasks
|
|
11
|
+
*/
|
|
12
|
+
import { isValidTransition, isInputRef, } from "../types/index.js";
|
|
13
|
+
import { consoleLogger } from "../utils/logger.js";
|
|
14
|
+
import { Scheduler } from "./scheduler.js";
|
|
15
|
+
export class Orchestrator {
|
|
16
|
+
registry;
|
|
17
|
+
scheduler;
|
|
18
|
+
log;
|
|
19
|
+
options;
|
|
20
|
+
activeTasks = new Map();
|
|
21
|
+
taskQueue = [];
|
|
22
|
+
retryAttempts = new Map();
|
|
23
|
+
completedTaskIds = new Set();
|
|
24
|
+
/** Stores evidence from completed tasks, keyed by task ID. Used to resolve InputRef values. */
|
|
25
|
+
completedEvidence = new Map();
|
|
26
|
+
pollTimer = null;
|
|
27
|
+
running = false;
|
|
28
|
+
tickInProgress = false;
|
|
29
|
+
constructor(registry, options) {
|
|
30
|
+
this.registry = registry;
|
|
31
|
+
this.scheduler = new Scheduler(registry);
|
|
32
|
+
this.log = options?.logger ?? consoleLogger;
|
|
33
|
+
this.options = {
|
|
34
|
+
pollIntervalMs: options?.pollIntervalMs ?? 5000,
|
|
35
|
+
maxRetries: options?.maxRetries ?? 3,
|
|
36
|
+
logger: this.log,
|
|
37
|
+
onProgress: options?.onProgress ?? (() => { }),
|
|
38
|
+
onBlocked: options?.onBlocked ?? (() => { }),
|
|
39
|
+
onCompleted: options?.onCompleted ?? (() => { }),
|
|
40
|
+
onFailed: options?.onFailed ?? (() => { }),
|
|
41
|
+
onDispatched: options?.onDispatched ?? (() => { }),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Enqueue tasks for dispatch. Rejects tasks involved in dependency cycles. */
|
|
45
|
+
enqueue(...tasks) {
|
|
46
|
+
// Detect cycles among the incoming tasks combined with already-queued tasks
|
|
47
|
+
const cyclicIds = this.detectCycles(tasks);
|
|
48
|
+
if (cyclicIds.size > 0) {
|
|
49
|
+
for (const task of tasks) {
|
|
50
|
+
if (cyclicIds.has(task.id)) {
|
|
51
|
+
this.log.error(`[orchestrator] Rejecting ${task.id}: dependency cycle detected`);
|
|
52
|
+
this.options.onFailed(task.id, {
|
|
53
|
+
taskId: task.id,
|
|
54
|
+
status: "failed",
|
|
55
|
+
failureDetail: {
|
|
56
|
+
failureType: "unknown",
|
|
57
|
+
attempted: "enqueue",
|
|
58
|
+
hypothesis: `Dependency cycle detected involving task ${task.id}`,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.taskQueue.push(task);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.taskQueue.push(...tasks);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Get current status of all active tasks. */
|
|
72
|
+
status() {
|
|
73
|
+
return Array.from(this.activeTasks.values()).map((t) => ({
|
|
74
|
+
taskId: t.task.id,
|
|
75
|
+
agentId: t.agentId,
|
|
76
|
+
state: t.state,
|
|
77
|
+
attempt: t.attempt,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/** Number of tasks in queue + active. */
|
|
81
|
+
get pendingCount() {
|
|
82
|
+
return this.taskQueue.length + this.activeTasks.size;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Start the orchestration loop.
|
|
86
|
+
* Dispatches queued tasks and polls active ones.
|
|
87
|
+
*/
|
|
88
|
+
start() {
|
|
89
|
+
if (this.running)
|
|
90
|
+
return;
|
|
91
|
+
this.running = true;
|
|
92
|
+
// Run immediately, then on interval
|
|
93
|
+
void this.tick();
|
|
94
|
+
this.pollTimer = setInterval(() => {
|
|
95
|
+
void this.tick();
|
|
96
|
+
}, this.options.pollIntervalMs);
|
|
97
|
+
}
|
|
98
|
+
/** Stop the orchestration loop. */
|
|
99
|
+
stop() {
|
|
100
|
+
this.running = false;
|
|
101
|
+
if (this.pollTimer) {
|
|
102
|
+
clearInterval(this.pollTimer);
|
|
103
|
+
this.pollTimer = null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Dispatch a single task immediately (bypasses queue).
|
|
108
|
+
* Returns the correlation ID.
|
|
109
|
+
*/
|
|
110
|
+
async dispatchNow(task) {
|
|
111
|
+
// Resolve InputRef values from completed dependency outputs
|
|
112
|
+
const resolvedTask = this.resolveInputs(task);
|
|
113
|
+
const result = this.scheduler.schedule(resolvedTask);
|
|
114
|
+
if (result.type === "rejected") {
|
|
115
|
+
this.log.error(`[orchestrator] Rejected ${resolvedTask.id}: ${result.rejection.reason}`);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const { decision } = result;
|
|
119
|
+
const dispatchResult = await decision.adapter.dispatch(resolvedTask);
|
|
120
|
+
if (!dispatchResult.accepted) {
|
|
121
|
+
this.log.error(`[orchestrator] Agent ${decision.agentId} rejected ${task.id}: ${dispatchResult.reason}`);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
// Track concurrency so the scheduler knows this slot is occupied
|
|
125
|
+
this.scheduler.acquire(decision.agentId);
|
|
126
|
+
this.activeTasks.set(dispatchResult.correlationId, {
|
|
127
|
+
task: resolvedTask,
|
|
128
|
+
correlationId: dispatchResult.correlationId,
|
|
129
|
+
agentId: decision.agentId,
|
|
130
|
+
adapter: decision.adapter,
|
|
131
|
+
state: "running",
|
|
132
|
+
attempt: this.retryAttempts.get(resolvedTask.id) ?? 1,
|
|
133
|
+
dispatchedAt: new Date().toISOString(),
|
|
134
|
+
});
|
|
135
|
+
this.options.onDispatched(resolvedTask.id, decision.agentId, dispatchResult.correlationId);
|
|
136
|
+
this.log.info(`[orchestrator] Dispatched ${resolvedTask.id} → ${decision.agentId} (${dispatchResult.correlationId})`);
|
|
137
|
+
return dispatchResult.correlationId;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Unblock a task that is in "blocked" state.
|
|
141
|
+
* Transitions it back to "running" and optionally forwards a resolution
|
|
142
|
+
* string to the adapter (if the adapter supports it).
|
|
143
|
+
*/
|
|
144
|
+
async unblock(correlationId, resolution) {
|
|
145
|
+
const active = this.activeTasks.get(correlationId);
|
|
146
|
+
if (!active) {
|
|
147
|
+
this.log.error(`[orchestrator] unblock: no active task for ${correlationId}`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (active.state !== "blocked") {
|
|
151
|
+
this.log.error(`[orchestrator] unblock: task ${active.task.id} is "${active.state}", not "blocked"`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!isValidTransition("blocked", "running")) {
|
|
155
|
+
this.log.error(`[orchestrator] unblock: blocked → running is not a valid transition`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Re-acquire concurrency slot before resuming
|
|
159
|
+
this.scheduler.acquire(active.agentId);
|
|
160
|
+
// Notify the adapter if it supports unblock
|
|
161
|
+
if (active.adapter.unblock) {
|
|
162
|
+
await active.adapter.unblock(correlationId, resolution);
|
|
163
|
+
}
|
|
164
|
+
active.state = "running";
|
|
165
|
+
// Store resolution in task metadata if provided
|
|
166
|
+
if (resolution) {
|
|
167
|
+
active.task.metadata = {
|
|
168
|
+
...active.task.metadata,
|
|
169
|
+
unblockResolution: resolution,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
this.log.info(`[orchestrator] Unblocked: ${active.task.id}${resolution ? ` — ${resolution}` : ""}`);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Cancel a running task.
|
|
176
|
+
*/
|
|
177
|
+
async cancelTask(correlationId) {
|
|
178
|
+
const active = this.activeTasks.get(correlationId);
|
|
179
|
+
if (!active)
|
|
180
|
+
return;
|
|
181
|
+
await active.adapter.cancel(correlationId);
|
|
182
|
+
this.scheduler.release(active.agentId);
|
|
183
|
+
this.activeTasks.delete(correlationId);
|
|
184
|
+
this.log.info(`[orchestrator] Cancelled ${active.task.id}`);
|
|
185
|
+
}
|
|
186
|
+
// ─── Internal loop ───────────────────────────────────────────────────────
|
|
187
|
+
async tick() {
|
|
188
|
+
if (this.tickInProgress)
|
|
189
|
+
return;
|
|
190
|
+
this.tickInProgress = true;
|
|
191
|
+
try {
|
|
192
|
+
// 1. Dispatch queued tasks
|
|
193
|
+
await this.dispatchQueued();
|
|
194
|
+
// 2. Poll active tasks
|
|
195
|
+
await this.pollActive();
|
|
196
|
+
// 3. If polling produced new queued tasks (e.g. retries), dispatch them
|
|
197
|
+
// immediately rather than waiting for the next tick.
|
|
198
|
+
if (this.taskQueue.length > 0) {
|
|
199
|
+
await this.dispatchQueued();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
this.tickInProgress = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async dispatchQueued() {
|
|
207
|
+
const toDispatch = [...this.taskQueue];
|
|
208
|
+
this.taskQueue = [];
|
|
209
|
+
// Collect IDs of completed tasks (for dependency checking)
|
|
210
|
+
const completedIds = new Set(this.completedTaskIds);
|
|
211
|
+
// Also treat currently active tasks as "in flight" — not completed
|
|
212
|
+
const ready = [];
|
|
213
|
+
const deferred = [];
|
|
214
|
+
for (const task of toDispatch) {
|
|
215
|
+
const deps = task.dependsOn ?? [];
|
|
216
|
+
if (deps.every((dep) => completedIds.has(dep))) {
|
|
217
|
+
ready.push(task);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
deferred.push(task);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Re-queue deferred tasks (dependencies not yet met)
|
|
224
|
+
this.taskQueue.push(...deferred);
|
|
225
|
+
for (const task of ready) {
|
|
226
|
+
const correlationId = await this.dispatchNow(task);
|
|
227
|
+
if (correlationId === null) {
|
|
228
|
+
// Re-queue if rejected (might succeed later when agents free up)
|
|
229
|
+
this.taskQueue.push(task);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async pollActive() {
|
|
234
|
+
const entries = Array.from(this.activeTasks.entries());
|
|
235
|
+
// Poll all active tasks in parallel to avoid one slow adapter blocking others
|
|
236
|
+
const results = await Promise.allSettled(entries.map(async ([correlationId, active]) => {
|
|
237
|
+
const pollResult = await active.adapter.poll(correlationId);
|
|
238
|
+
return { correlationId, active, pollResult };
|
|
239
|
+
}));
|
|
240
|
+
// Handle results sequentially (state mutations must be serialized)
|
|
241
|
+
for (const result of results) {
|
|
242
|
+
if (result.status === "fulfilled") {
|
|
243
|
+
const { correlationId, active, pollResult } = result.value;
|
|
244
|
+
try {
|
|
245
|
+
await this.handlePollResult(correlationId, active, pollResult);
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
this.log.error(`[orchestrator] Handle error for ${active.task.id}:`, err);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.log.error(`[orchestrator] Poll error:`, result.reason);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async handlePollResult(correlationId, active, result) {
|
|
257
|
+
// Always surface progress if present (even without state change)
|
|
258
|
+
if (result.progress) {
|
|
259
|
+
result.progress.agentId = active.agentId;
|
|
260
|
+
this.options.onProgress(active.task.id, result.progress);
|
|
261
|
+
}
|
|
262
|
+
// Check timeout
|
|
263
|
+
if (active.task.timeout && active.task.timeout > 0) {
|
|
264
|
+
const elapsed = Date.now() - new Date(active.dispatchedAt).getTime();
|
|
265
|
+
if (elapsed > active.task.timeout) {
|
|
266
|
+
this.log.info(`[orchestrator] Timeout: ${active.task.id} after ${elapsed}ms`);
|
|
267
|
+
await this.cancelTask(correlationId);
|
|
268
|
+
this.options.onFailed(active.task.id, {
|
|
269
|
+
taskId: active.task.id,
|
|
270
|
+
status: "failed",
|
|
271
|
+
failureDetail: {
|
|
272
|
+
failureType: "timeout",
|
|
273
|
+
attempted: `Execution exceeded ${active.task.timeout}ms`,
|
|
274
|
+
hypothesis: "Task took longer than allowed timeout.",
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// No state change — nothing more to do
|
|
281
|
+
if (result.state === active.state)
|
|
282
|
+
return;
|
|
283
|
+
// Validate transition before applying
|
|
284
|
+
if (!isValidTransition(active.state, result.state)) {
|
|
285
|
+
this.log.error(`[orchestrator] Invalid transition for ${active.task.id}: ${active.state} → ${result.state}. Ignoring.`);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
active.state = result.state;
|
|
289
|
+
switch (result.state) {
|
|
290
|
+
case "completed": {
|
|
291
|
+
this.scheduler.release(active.agentId);
|
|
292
|
+
this.activeTasks.delete(correlationId);
|
|
293
|
+
this.completedTaskIds.add(active.task.id);
|
|
294
|
+
this.retryAttempts.delete(active.task.id);
|
|
295
|
+
const evidence = result.evidence ?? {
|
|
296
|
+
taskId: active.task.id,
|
|
297
|
+
status: "completed",
|
|
298
|
+
};
|
|
299
|
+
// Store evidence for input resolution by downstream tasks
|
|
300
|
+
this.completedEvidence.set(active.task.id, evidence);
|
|
301
|
+
this.options.onCompleted(active.task.id, evidence);
|
|
302
|
+
this.log.info(`[orchestrator] Completed: ${active.task.id}`);
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case "failed": {
|
|
306
|
+
this.scheduler.release(active.agentId);
|
|
307
|
+
this.activeTasks.delete(correlationId);
|
|
308
|
+
// attempt counts from 1 (initial run). Retries = attempt - 1.
|
|
309
|
+
// maxRetries means how many retries are allowed after the initial attempt.
|
|
310
|
+
const retriesSoFar = active.attempt - 1;
|
|
311
|
+
if (retriesSoFar < this.options.maxRetries) {
|
|
312
|
+
const nextAttempt = active.attempt + 1;
|
|
313
|
+
this.log.info(`[orchestrator] Retrying ${active.task.id} (retry ${retriesSoFar + 1}/${this.options.maxRetries})`);
|
|
314
|
+
// Inject failure as pitfall context for retry
|
|
315
|
+
const retryTask = this.enrichWithPitfall(active.task, result);
|
|
316
|
+
this.retryAttempts.set(retryTask.id, nextAttempt);
|
|
317
|
+
this.taskQueue.push(retryTask);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
this.options.onFailed(active.task.id, result.evidence ?? {
|
|
321
|
+
taskId: active.task.id,
|
|
322
|
+
status: "failed",
|
|
323
|
+
});
|
|
324
|
+
this.log.info(`[orchestrator] Failed permanently: ${active.task.id} after ${active.attempt} attempts`);
|
|
325
|
+
this.retryAttempts.delete(active.task.id);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case "blocked":
|
|
330
|
+
// Release concurrency slot so other tasks can proceed while blocked
|
|
331
|
+
this.scheduler.release(active.agentId);
|
|
332
|
+
this.options.onBlocked(active.task.id, result.evidence?.blockReason?.description ??
|
|
333
|
+
"Unknown block reason");
|
|
334
|
+
this.log.info(`[orchestrator] Blocked: ${active.task.id}`);
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
// running — just update state
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Detect dependency cycles among the given tasks plus already-queued tasks.
|
|
343
|
+
* Returns a set of task IDs that are involved in cycles.
|
|
344
|
+
*/
|
|
345
|
+
detectCycles(newTasks) {
|
|
346
|
+
// Build adjacency: taskId → set of dependency taskIds
|
|
347
|
+
const adj = new Map();
|
|
348
|
+
const allTasks = [...this.taskQueue, ...newTasks];
|
|
349
|
+
for (const task of allTasks) {
|
|
350
|
+
adj.set(task.id, task.dependsOn ?? []);
|
|
351
|
+
}
|
|
352
|
+
const cyclic = new Set();
|
|
353
|
+
const visited = new Set();
|
|
354
|
+
const inStack = new Set();
|
|
355
|
+
const dfs = (id) => {
|
|
356
|
+
if (inStack.has(id))
|
|
357
|
+
return true; // cycle found
|
|
358
|
+
if (visited.has(id))
|
|
359
|
+
return false;
|
|
360
|
+
visited.add(id);
|
|
361
|
+
inStack.add(id);
|
|
362
|
+
for (const dep of adj.get(id) ?? []) {
|
|
363
|
+
if (adj.has(dep) && dfs(dep)) {
|
|
364
|
+
cyclic.add(id);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
inStack.delete(id);
|
|
369
|
+
return false;
|
|
370
|
+
};
|
|
371
|
+
for (const id of adj.keys()) {
|
|
372
|
+
if (!visited.has(id)) {
|
|
373
|
+
dfs(id);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return cyclic;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Resolve InputRef values in task.inputs using completed task evidence.
|
|
380
|
+
* Static values are passed through unchanged. InputRef values are replaced
|
|
381
|
+
* with the actual output from the referenced task.
|
|
382
|
+
*/
|
|
383
|
+
resolveInputs(task) {
|
|
384
|
+
if (!task.inputs)
|
|
385
|
+
return task;
|
|
386
|
+
const resolvedInputs = {};
|
|
387
|
+
let hasUnresolved = false;
|
|
388
|
+
for (const [key, value] of Object.entries(task.inputs)) {
|
|
389
|
+
if (isInputRef(value)) {
|
|
390
|
+
const evidence = this.completedEvidence.get(value.fromTask);
|
|
391
|
+
if (!evidence?.outputs?.[value.outputKey]) {
|
|
392
|
+
this.log.error(`[orchestrator] Input resolution failed for ${task.id}: ${key} references ${value.fromTask}.outputs.${value.outputKey} which is not available`);
|
|
393
|
+
hasUnresolved = true;
|
|
394
|
+
resolvedInputs[key] = value; // Keep original ref
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
resolvedInputs[key] = evidence.outputs[value.outputKey];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
resolvedInputs[key] = value;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (hasUnresolved) {
|
|
405
|
+
this.log.warn(`[orchestrator] Task ${task.id} has unresolved InputRefs — dispatching with partial inputs`);
|
|
406
|
+
}
|
|
407
|
+
return { ...task, inputs: resolvedInputs };
|
|
408
|
+
}
|
|
409
|
+
/** Enrich a task with pitfall from its previous failure (for retry). */
|
|
410
|
+
enrichWithPitfall(task, failResult) {
|
|
411
|
+
if (!failResult.evidence?.failureDetail)
|
|
412
|
+
return task;
|
|
413
|
+
const pitfall = {
|
|
414
|
+
id: `PF-${Date.now()}`,
|
|
415
|
+
failureType: failResult.evidence.failureDetail.failureType,
|
|
416
|
+
attempted: failResult.evidence.failureDetail.attempted,
|
|
417
|
+
hypothesis: failResult.evidence.failureDetail.hypothesis,
|
|
418
|
+
missingContext: failResult.evidence.failureDetail.missingContext,
|
|
419
|
+
};
|
|
420
|
+
return {
|
|
421
|
+
...task,
|
|
422
|
+
context: {
|
|
423
|
+
...task.context,
|
|
424
|
+
pitfalls: [...(task.context?.pitfalls ?? []), pitfall],
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
/** Shut down: stop loop and dispose all adapters. */
|
|
429
|
+
async shutdown() {
|
|
430
|
+
this.stop();
|
|
431
|
+
// Cancel all active tasks — collect IDs first to avoid mutation during iteration
|
|
432
|
+
const ids = [...this.activeTasks.keys()];
|
|
433
|
+
for (const id of ids) {
|
|
434
|
+
try {
|
|
435
|
+
await this.cancelTask(id);
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
this.log.error(`[orchestrator] Error cancelling ${id}:`, err);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// Dispose all registered adapters
|
|
442
|
+
for (const agent of this.registry.list()) {
|
|
443
|
+
try {
|
|
444
|
+
await agent.adapter.dispose?.();
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
this.log.error(`[orchestrator] Error disposing agent:`, err);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,OAAO,EAGL,iBAAiB,EACjB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+B3C,MAAM,OAAO,YAAY;IACN,QAAQ,CAAgB;IACxB,SAAS,CAAY;IACrB,GAAG,CAAS;IACZ,OAAO,CAAgC;IAChD,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,SAAS,GAAe,EAAE,CAAC;IAC3B,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7C,+FAA+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AE;gBACP,GAAG,IAAI,CAAC,OAAO;gBACf,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC;aACvD;SACF,CAAC;IACJ,CAAC;IAED,qDAAqD;IACrD,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,IAAI,EAAE,CAAC;QAEZ,iFAAiF;QACjF,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,kCAAkC;QAClC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC;gBACH,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAClC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry — discover and query available agents by capability.
|
|
3
|
+
*
|
|
4
|
+
* Agents register themselves with their capability declarations.
|
|
5
|
+
* The orchestrator queries the registry to find agents that can handle a task.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentAdapter } from "../adapter/agent-adapter.js";
|
|
8
|
+
import type { AgentCapability } from "../types/index.js";
|
|
9
|
+
export interface RegisteredAgent {
|
|
10
|
+
adapter: AgentAdapter;
|
|
11
|
+
capability: AgentCapability;
|
|
12
|
+
registeredAt: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class AgentRegistry {
|
|
15
|
+
private agents;
|
|
16
|
+
/** Register an agent adapter. */
|
|
17
|
+
register(adapter: AgentAdapter): void;
|
|
18
|
+
/** Unregister an agent. */
|
|
19
|
+
unregister(agentId: string): boolean;
|
|
20
|
+
/** Get a specific agent by ID. */
|
|
21
|
+
get(agentId: string): RegisteredAgent | undefined;
|
|
22
|
+
/** List all registered agents. */
|
|
23
|
+
list(): RegisteredAgent[];
|
|
24
|
+
/**
|
|
25
|
+
* Find agents that have ALL of the requested capabilities.
|
|
26
|
+
* Returns agents sorted by specificity (fewer extra capabilities = better match).
|
|
27
|
+
*/
|
|
28
|
+
findByCapabilities(required: string[]): RegisteredAgent[];
|
|
29
|
+
/**
|
|
30
|
+
* Find agents that have ANY of the requested capabilities.
|
|
31
|
+
* Returns agents sorted by number of matching capabilities (most matches first).
|
|
32
|
+
*/
|
|
33
|
+
findByAnyCapability(desired: string[]): RegisteredAgent[];
|
|
34
|
+
/** Check if any agent can handle the given capabilities. */
|
|
35
|
+
hasCapable(required: string[]): boolean;
|
|
36
|
+
/** Total number of registered agents. */
|
|
37
|
+
get size(): number;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/orchestrator/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAsC;IAEpD,iCAAiC;IACjC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IASrC,2BAA2B;IAC3B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIpC,kCAAkC;IAClC,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIjD,kCAAkC;IAClC,IAAI,IAAI,eAAe,EAAE;IAIzB;;;OAGG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE;IAWzD;;;OAGG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE;IAazD,4DAA4D;IAC5D,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO;IAIvC,yCAAyC;IACzC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry — discover and query available agents by capability.
|
|
3
|
+
*
|
|
4
|
+
* Agents register themselves with their capability declarations.
|
|
5
|
+
* The orchestrator queries the registry to find agents that can handle a task.
|
|
6
|
+
*/
|
|
7
|
+
export class AgentRegistry {
|
|
8
|
+
agents = new Map();
|
|
9
|
+
/** Register an agent adapter. */
|
|
10
|
+
register(adapter) {
|
|
11
|
+
const capability = adapter.capabilities();
|
|
12
|
+
this.agents.set(capability.agentId, {
|
|
13
|
+
adapter,
|
|
14
|
+
capability,
|
|
15
|
+
registeredAt: new Date().toISOString(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Unregister an agent. */
|
|
19
|
+
unregister(agentId) {
|
|
20
|
+
return this.agents.delete(agentId);
|
|
21
|
+
}
|
|
22
|
+
/** Get a specific agent by ID. */
|
|
23
|
+
get(agentId) {
|
|
24
|
+
return this.agents.get(agentId);
|
|
25
|
+
}
|
|
26
|
+
/** List all registered agents. */
|
|
27
|
+
list() {
|
|
28
|
+
return Array.from(this.agents.values());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Find agents that have ALL of the requested capabilities.
|
|
32
|
+
* Returns agents sorted by specificity (fewer extra capabilities = better match).
|
|
33
|
+
*/
|
|
34
|
+
findByCapabilities(required) {
|
|
35
|
+
return this.list()
|
|
36
|
+
.filter((entry) => required.every((cap) => entry.capability.capabilities.includes(cap)))
|
|
37
|
+
.sort((a, b) => a.capability.capabilities.length - b.capability.capabilities.length);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find agents that have ANY of the requested capabilities.
|
|
41
|
+
* Returns agents sorted by number of matching capabilities (most matches first).
|
|
42
|
+
*/
|
|
43
|
+
findByAnyCapability(desired) {
|
|
44
|
+
return this.list()
|
|
45
|
+
.map((entry) => ({
|
|
46
|
+
entry,
|
|
47
|
+
matchCount: desired.filter((cap) => entry.capability.capabilities.includes(cap)).length,
|
|
48
|
+
}))
|
|
49
|
+
.filter(({ matchCount }) => matchCount > 0)
|
|
50
|
+
.sort((a, b) => b.matchCount - a.matchCount)
|
|
51
|
+
.map(({ entry }) => entry);
|
|
52
|
+
}
|
|
53
|
+
/** Check if any agent can handle the given capabilities. */
|
|
54
|
+
hasCapable(required) {
|
|
55
|
+
return this.findByCapabilities(required).length > 0;
|
|
56
|
+
}
|
|
57
|
+
/** Total number of registered agents. */
|
|
58
|
+
get size() {
|
|
59
|
+
return this.agents.size;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/orchestrator/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,MAAM,OAAO,aAAa;IAChB,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEpD,iCAAiC;IACjC,QAAQ,CAAC,OAAqB;QAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY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CAC5C,CAAC,MAAM;SACT,CAAC,CAAC;aACF,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,CAAC,CAAC;aAC1C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;aAC3C,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,4DAA4D;IAC5D,UAAU,CAAC,QAAkB;QAC3B,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,yCAAyC;IACzC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler — match tasks to capable agents, respecting constraints.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Match task requirements to agent capabilities
|
|
6
|
+
* - Respect concurrency limits
|
|
7
|
+
* - Handle dependency ordering
|
|
8
|
+
* - Select the best agent when multiple can handle a task
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentAdapter } from "../adapter/agent-adapter.js";
|
|
11
|
+
import type { TaskUnit } from "../types/index.js";
|
|
12
|
+
import type { AgentRegistry } from "./registry.js";
|
|
13
|
+
export interface ScheduleDecision {
|
|
14
|
+
taskId: string;
|
|
15
|
+
agentId: string;
|
|
16
|
+
adapter: AgentAdapter;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ScheduleRejection {
|
|
20
|
+
taskId: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
export type ScheduleResult = {
|
|
24
|
+
type: "scheduled";
|
|
25
|
+
decision: ScheduleDecision;
|
|
26
|
+
} | {
|
|
27
|
+
type: "rejected";
|
|
28
|
+
rejection: ScheduleRejection;
|
|
29
|
+
};
|
|
30
|
+
export declare class Scheduler {
|
|
31
|
+
private readonly registry;
|
|
32
|
+
/** Track how many tasks each agent is currently running. */
|
|
33
|
+
private activeCounts;
|
|
34
|
+
constructor(registry: AgentRegistry);
|
|
35
|
+
/**
|
|
36
|
+
* Schedule a single task: find the best available agent.
|
|
37
|
+
*
|
|
38
|
+
* Selection criteria (in order):
|
|
39
|
+
* 1. Must have required capabilities (inferred from task)
|
|
40
|
+
* 2. Must have available concurrency slots
|
|
41
|
+
* 3. Prefer agents with fewer extra capabilities (more specialized)
|
|
42
|
+
*/
|
|
43
|
+
schedule(task: TaskUnit): ScheduleResult;
|
|
44
|
+
/**
|
|
45
|
+
* Schedule multiple tasks, respecting dependencies.
|
|
46
|
+
* Returns tasks in executable order (dependencies first).
|
|
47
|
+
*/
|
|
48
|
+
scheduleBatch(tasks: TaskUnit[]): {
|
|
49
|
+
scheduled: ScheduleDecision[];
|
|
50
|
+
rejected: ScheduleRejection[];
|
|
51
|
+
deferred: TaskUnit[];
|
|
52
|
+
};
|
|
53
|
+
/** Mark an agent slot as acquired. */
|
|
54
|
+
acquire(agentId: string): void;
|
|
55
|
+
/** Release an agent slot. */
|
|
56
|
+
release(agentId: string): void;
|
|
57
|
+
/** Reset all concurrency tracking. */
|
|
58
|
+
reset(): void;
|
|
59
|
+
private hasCapacity;
|
|
60
|
+
/**
|
|
61
|
+
* Infer required capabilities from task content.
|
|
62
|
+
* This is a simple heuristic — adapters can override with explicit capability tags.
|
|
63
|
+
*/
|
|
64
|
+
private inferCapabilities;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/orchestrator/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,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