@directive-run/ai 0.2.0 → 0.4.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 +26 -31
- package/dist/anthropic.cjs +1 -1
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.d.cts +5 -9
- package/dist/anthropic.d.ts +5 -9
- package/dist/anthropic.js +1 -1
- package/dist/anthropic.js.map +1 -1
- package/dist/gemini.cjs +3 -0
- package/dist/gemini.cjs.map +1 -0
- package/dist/gemini.d.cts +93 -0
- package/dist/gemini.d.ts +93 -0
- package/dist/gemini.js +3 -0
- package/dist/gemini.js.map +1 -0
- package/dist/index.cjs +117 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1388 -2107
- package/dist/index.d.ts +1388 -2107
- package/dist/index.js +117 -45
- package/dist/index.js.map +1 -1
- package/dist/multi-agent-orchestrator-D-WuP4jP.d.ts +2365 -0
- package/dist/multi-agent-orchestrator-YFs28JsF.d.cts +2365 -0
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts +3 -2
- package/dist/ollama.d.ts +3 -2
- package/dist/ollama.js.map +1 -1
- package/dist/openai.cjs +2 -2
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.d.cts +4 -8
- package/dist/openai.d.ts +4 -8
- package/dist/openai.js +2 -2
- package/dist/openai.js.map +1 -1
- package/dist/semantic-cache-F0psCRuz.d.cts +271 -0
- package/dist/semantic-cache-F0psCRuz.d.ts +271 -0
- package/dist/testing.cjs +42 -7
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +390 -5
- package/dist/testing.d.ts +390 -5
- package/dist/testing.js +42 -7
- package/dist/testing.js.map +1 -1
- package/dist/types-D5veI9su.d.cts +1456 -0
- package/dist/types-D5veI9su.d.ts +1456 -0
- package/package.json +7 -2
- package/dist/types-Bbar7yKz.d.cts +0 -304
- package/dist/types-Bbar7yKz.d.ts +0 -304
|
@@ -0,0 +1,1456 @@
|
|
|
1
|
+
import { Requirement } from '@directive-run/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Persistent Checkpointing — Serialize/restore full orchestrator state.
|
|
5
|
+
*
|
|
6
|
+
* Enables long-running workflows, process restarts, and fork-and-replay by
|
|
7
|
+
* capturing a complete snapshot of orchestrator state at rest.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/** Checkpoint local state for single-agent orchestrators */
|
|
12
|
+
interface SingleAgentCheckpointLocalState {
|
|
13
|
+
type: "single";
|
|
14
|
+
}
|
|
15
|
+
/** Checkpoint local state for multi-agent orchestrators */
|
|
16
|
+
interface MultiAgentCheckpointLocalState {
|
|
17
|
+
type: "multi";
|
|
18
|
+
globalTokenCount: number;
|
|
19
|
+
globalStatus: "idle" | "paused";
|
|
20
|
+
agentStates: Record<string, {
|
|
21
|
+
status: "idle" | "running" | "completed" | "error";
|
|
22
|
+
lastInput?: string;
|
|
23
|
+
lastOutput?: unknown;
|
|
24
|
+
lastError?: string;
|
|
25
|
+
runCount: number;
|
|
26
|
+
totalTokens: number;
|
|
27
|
+
}>;
|
|
28
|
+
handoffCounter: number;
|
|
29
|
+
pendingHandoffs: unknown[];
|
|
30
|
+
handoffResults: unknown[];
|
|
31
|
+
roundRobinCounters: Record<string, number> | null;
|
|
32
|
+
/** Serialized task states (task run functions are closures, not serializable) */
|
|
33
|
+
taskStates?: Record<string, {
|
|
34
|
+
lastOutput?: string;
|
|
35
|
+
lastError?: string;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
/** Union of local state types */
|
|
39
|
+
type CheckpointLocalState = SingleAgentCheckpointLocalState | MultiAgentCheckpointLocalState;
|
|
40
|
+
/** Full checkpoint data */
|
|
41
|
+
interface Checkpoint {
|
|
42
|
+
version: 1;
|
|
43
|
+
id: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
label?: string;
|
|
46
|
+
systemExport: string;
|
|
47
|
+
timelineExport: string | null;
|
|
48
|
+
localState: CheckpointLocalState;
|
|
49
|
+
memoryExport: unknown | null;
|
|
50
|
+
orchestratorType: "single" | "multi";
|
|
51
|
+
/** Associated time-travel snapshot ID */
|
|
52
|
+
snapshotId?: number;
|
|
53
|
+
/** Arbitrary metadata */
|
|
54
|
+
metadata?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/** Checkpoint store interface */
|
|
57
|
+
interface CheckpointStore {
|
|
58
|
+
save(checkpoint: Checkpoint): Promise<string>;
|
|
59
|
+
load(checkpointId: string): Promise<Checkpoint | null>;
|
|
60
|
+
list(): Promise<Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
label?: string;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
}>>;
|
|
65
|
+
delete(checkpointId: string): Promise<boolean>;
|
|
66
|
+
clear(): Promise<void>;
|
|
67
|
+
/** Prune old checkpoints based on retention policy. Returns number pruned. */
|
|
68
|
+
prune(): Promise<number>;
|
|
69
|
+
}
|
|
70
|
+
/** Create a unique checkpoint ID */
|
|
71
|
+
declare function createCheckpointId(): string;
|
|
72
|
+
/** Validate that an unknown value is a valid Checkpoint */
|
|
73
|
+
declare function validateCheckpoint(data: unknown): data is Checkpoint;
|
|
74
|
+
/** Options for InMemoryCheckpointStore */
|
|
75
|
+
interface InMemoryCheckpointStoreOptions {
|
|
76
|
+
/** Maximum checkpoints to retain before FIFO eviction. @default 100 */
|
|
77
|
+
maxCheckpoints?: number;
|
|
78
|
+
/** Time-based retention: prune checkpoints older than this (ms). @default Infinity */
|
|
79
|
+
retentionMs?: number;
|
|
80
|
+
/** When true, labeled checkpoints are exempt from auto-prune. @default false */
|
|
81
|
+
preserveLabeled?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* In-memory checkpoint store with FIFO eviction and time-based retention.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const store = new InMemoryCheckpointStore({
|
|
89
|
+
* maxCheckpoints: 50,
|
|
90
|
+
* retentionMs: 3600000, // 1 hour
|
|
91
|
+
* preserveLabeled: true,
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* const id = await store.save(checkpoint);
|
|
95
|
+
* const pruned = await store.prune();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare class InMemoryCheckpointStore implements CheckpointStore {
|
|
99
|
+
private readonly store;
|
|
100
|
+
private readonly order;
|
|
101
|
+
private readonly maxCheckpoints;
|
|
102
|
+
private readonly retentionMs;
|
|
103
|
+
private readonly preserveLabeled;
|
|
104
|
+
constructor(options?: InMemoryCheckpointStoreOptions);
|
|
105
|
+
save(checkpoint: Checkpoint): Promise<string>;
|
|
106
|
+
load(checkpointId: string): Promise<Checkpoint | null>;
|
|
107
|
+
list(): Promise<Array<{
|
|
108
|
+
id: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
createdAt: string;
|
|
111
|
+
}>>;
|
|
112
|
+
delete(checkpointId: string): Promise<boolean>;
|
|
113
|
+
clear(): Promise<void>;
|
|
114
|
+
prune(): Promise<number>;
|
|
115
|
+
/** Evict the oldest non-labeled checkpoint. Returns true if one was evicted. */
|
|
116
|
+
private evictOldest;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Human-in-the-Loop Breakpoints — Pause/inspect/modify/resume at arbitrary execution points.
|
|
121
|
+
*
|
|
122
|
+
* Separate from approvals (which are safety gates for tool calls). Breakpoints are
|
|
123
|
+
* general-purpose pause points for debugging, inspection, and input modification.
|
|
124
|
+
*
|
|
125
|
+
* Zero overhead when breakpoints array is empty — guard at each insertion point.
|
|
126
|
+
*
|
|
127
|
+
* @module
|
|
128
|
+
*/
|
|
129
|
+
/** Breakpoint types for single-agent orchestrator */
|
|
130
|
+
type BreakpointType = "pre_input_guardrails" | "pre_agent_run" | "pre_output_guardrails" | "post_run";
|
|
131
|
+
/** Extended breakpoint types for multi-agent orchestrator */
|
|
132
|
+
type MultiAgentBreakpointType = BreakpointType | "pre_handoff" | "pre_pattern_step";
|
|
133
|
+
/** Breakpoint configuration */
|
|
134
|
+
interface BreakpointConfig<T extends string = BreakpointType> {
|
|
135
|
+
type: T;
|
|
136
|
+
when?: (context: BreakpointContext) => boolean;
|
|
137
|
+
label?: string;
|
|
138
|
+
}
|
|
139
|
+
/** Context available when a breakpoint fires */
|
|
140
|
+
interface BreakpointContext {
|
|
141
|
+
agentId: string;
|
|
142
|
+
agentName: string;
|
|
143
|
+
input: string;
|
|
144
|
+
state: Record<string, unknown>;
|
|
145
|
+
breakpointType: string;
|
|
146
|
+
patternId?: string;
|
|
147
|
+
handoff?: {
|
|
148
|
+
fromAgent: string;
|
|
149
|
+
toAgent: string;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** A pending breakpoint request */
|
|
153
|
+
interface BreakpointRequest {
|
|
154
|
+
id: string;
|
|
155
|
+
type: string;
|
|
156
|
+
agentId: string;
|
|
157
|
+
input: string;
|
|
158
|
+
label?: string;
|
|
159
|
+
requestedAt: number;
|
|
160
|
+
}
|
|
161
|
+
/** Modifications that can be applied when resuming a breakpoint */
|
|
162
|
+
interface BreakpointModifications {
|
|
163
|
+
input?: string;
|
|
164
|
+
skip?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/** Breakpoint state stored in facts */
|
|
167
|
+
interface BreakpointState$1 {
|
|
168
|
+
pending: BreakpointRequest[];
|
|
169
|
+
resolved: string[];
|
|
170
|
+
cancelled: string[];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Maximum number of resolved/cancelled breakpoint IDs to retain (FIFO eviction) */
|
|
174
|
+
declare const MAX_BREAKPOINT_HISTORY = 200;
|
|
175
|
+
/** Create a unique breakpoint ID */
|
|
176
|
+
declare function createBreakpointId(): string;
|
|
177
|
+
/**
|
|
178
|
+
* Match a breakpoint configuration against the current execution point.
|
|
179
|
+
* Returns the matching config or null if no match.
|
|
180
|
+
*/
|
|
181
|
+
declare function matchBreakpoint<T extends string>(breakpoints: BreakpointConfig<T>[], type: T, context: BreakpointContext): BreakpointConfig<T> | null;
|
|
182
|
+
/** Create initial breakpoint state */
|
|
183
|
+
declare function createInitialBreakpointState(): BreakpointState$1;
|
|
184
|
+
|
|
185
|
+
/** Simplified Agent interface */
|
|
186
|
+
interface AgentLike {
|
|
187
|
+
name: string;
|
|
188
|
+
instructions?: string;
|
|
189
|
+
model?: string;
|
|
190
|
+
tools?: unknown[];
|
|
191
|
+
}
|
|
192
|
+
/** Agent run result */
|
|
193
|
+
interface RunResult<T = unknown> {
|
|
194
|
+
output: T;
|
|
195
|
+
messages: Message[];
|
|
196
|
+
toolCalls: ToolCall[];
|
|
197
|
+
totalTokens: number;
|
|
198
|
+
/** Breakdown of input vs output tokens, when available from the provider */
|
|
199
|
+
tokenUsage?: TokenUsage;
|
|
200
|
+
/** True when result was served from semantic cache */
|
|
201
|
+
isCached?: boolean;
|
|
202
|
+
}
|
|
203
|
+
/** Breakdown of token usage by input/output */
|
|
204
|
+
interface TokenUsage {
|
|
205
|
+
inputTokens: number;
|
|
206
|
+
outputTokens: number;
|
|
207
|
+
}
|
|
208
|
+
/** Message from agent run */
|
|
209
|
+
interface Message {
|
|
210
|
+
role: "user" | "assistant" | "tool" | "system";
|
|
211
|
+
content: string;
|
|
212
|
+
toolCallId?: string;
|
|
213
|
+
}
|
|
214
|
+
/** Tool call record */
|
|
215
|
+
interface ToolCall {
|
|
216
|
+
id: string;
|
|
217
|
+
name: string;
|
|
218
|
+
arguments: string;
|
|
219
|
+
result?: string;
|
|
220
|
+
}
|
|
221
|
+
/** Run function type */
|
|
222
|
+
type AgentRunner = <T = unknown>(agent: AgentLike, input: string, options?: RunOptions) => Promise<RunResult<T>>;
|
|
223
|
+
/** Callback-based streaming run function (e.g. for SSE-based LLM APIs) */
|
|
224
|
+
type StreamingCallbackRunner = (agent: AgentLike, input: string, callbacks: {
|
|
225
|
+
onToken?: (token: string) => void;
|
|
226
|
+
onToolStart?: (tool: string, id: string, args: string) => void;
|
|
227
|
+
onToolEnd?: (tool: string, id: string, result: string) => void;
|
|
228
|
+
onMessage?: (message: Message) => void;
|
|
229
|
+
signal?: AbortSignal;
|
|
230
|
+
}) => Promise<RunResult<unknown>>;
|
|
231
|
+
/** Run options */
|
|
232
|
+
interface RunOptions {
|
|
233
|
+
maxTurns?: number;
|
|
234
|
+
signal?: AbortSignal;
|
|
235
|
+
onMessage?: (message: Message) => void;
|
|
236
|
+
onToolCall?: (toolCall: ToolCall) => void | Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Lifecycle hooks for adapter-level observability.
|
|
240
|
+
*
|
|
241
|
+
* Attach to any adapter (runner or streaming runner) to trace, log,
|
|
242
|
+
* or measure individual LLM calls without modifying application code.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const runner = createOpenAIRunner({
|
|
247
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
248
|
+
* hooks: {
|
|
249
|
+
* onBeforeCall: ({ agent, input }) => console.log(`→ ${agent.name}`, input.slice(0, 50)),
|
|
250
|
+
* onAfterCall: ({ durationMs, tokenUsage }) => {
|
|
251
|
+
* metrics.track('llm_call', { durationMs, ...tokenUsage });
|
|
252
|
+
* },
|
|
253
|
+
* onError: ({ error }) => Sentry.captureException(error),
|
|
254
|
+
* },
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
interface AdapterHooks {
|
|
259
|
+
/** Fires before each LLM API call. */
|
|
260
|
+
onBeforeCall?: (event: {
|
|
261
|
+
agent: AgentLike;
|
|
262
|
+
input: string;
|
|
263
|
+
timestamp: number;
|
|
264
|
+
}) => void;
|
|
265
|
+
/** Fires after a successful LLM API call. */
|
|
266
|
+
onAfterCall?: (event: {
|
|
267
|
+
agent: AgentLike;
|
|
268
|
+
input: string;
|
|
269
|
+
output: string;
|
|
270
|
+
totalTokens: number;
|
|
271
|
+
tokenUsage: TokenUsage;
|
|
272
|
+
durationMs: number;
|
|
273
|
+
timestamp: number;
|
|
274
|
+
}) => void;
|
|
275
|
+
/** Fires when an LLM API call fails. */
|
|
276
|
+
onError?: (event: {
|
|
277
|
+
agent: AgentLike;
|
|
278
|
+
input: string;
|
|
279
|
+
error: Error;
|
|
280
|
+
durationMs: number;
|
|
281
|
+
timestamp: number;
|
|
282
|
+
}) => void;
|
|
283
|
+
}
|
|
284
|
+
/** Guardrail function */
|
|
285
|
+
type GuardrailFn<T = unknown> = (data: T, context: GuardrailContext) => GuardrailResult | Promise<GuardrailResult>;
|
|
286
|
+
/** Guardrail context */
|
|
287
|
+
interface GuardrailContext {
|
|
288
|
+
agentName: string;
|
|
289
|
+
input: string;
|
|
290
|
+
facts: Record<string, unknown>;
|
|
291
|
+
}
|
|
292
|
+
/** Guardrail result */
|
|
293
|
+
interface GuardrailResult {
|
|
294
|
+
passed: boolean;
|
|
295
|
+
reason?: string;
|
|
296
|
+
transformed?: unknown;
|
|
297
|
+
}
|
|
298
|
+
/** Input guardrail data */
|
|
299
|
+
interface InputGuardrailData {
|
|
300
|
+
input: string;
|
|
301
|
+
agentName: string;
|
|
302
|
+
}
|
|
303
|
+
/** Output guardrail data */
|
|
304
|
+
interface OutputGuardrailData {
|
|
305
|
+
output: unknown;
|
|
306
|
+
agentName: string;
|
|
307
|
+
input: string;
|
|
308
|
+
messages: Message[];
|
|
309
|
+
}
|
|
310
|
+
/** Tool call guardrail data */
|
|
311
|
+
interface ToolCallGuardrailData {
|
|
312
|
+
toolCall: ToolCall;
|
|
313
|
+
agentName: string;
|
|
314
|
+
input: string;
|
|
315
|
+
}
|
|
316
|
+
/** Retry configuration for guardrails */
|
|
317
|
+
interface GuardrailRetryConfig {
|
|
318
|
+
/** Total attempts (1 = no retries, 2 = one retry, etc.). @default 1 */
|
|
319
|
+
attempts?: number;
|
|
320
|
+
/** @default "exponential" */
|
|
321
|
+
backoff?: "exponential" | "linear" | "fixed";
|
|
322
|
+
/** @default 100 */
|
|
323
|
+
baseDelayMs?: number;
|
|
324
|
+
/** @default 5000 */
|
|
325
|
+
maxDelayMs?: number;
|
|
326
|
+
}
|
|
327
|
+
/** Named guardrail for better debugging */
|
|
328
|
+
interface NamedGuardrail<T = unknown> {
|
|
329
|
+
name: string;
|
|
330
|
+
fn: GuardrailFn<T>;
|
|
331
|
+
/** @default true */
|
|
332
|
+
critical?: boolean;
|
|
333
|
+
retry?: GuardrailRetryConfig;
|
|
334
|
+
}
|
|
335
|
+
/** Guardrails configuration */
|
|
336
|
+
interface GuardrailsConfig {
|
|
337
|
+
input?: Array<GuardrailFn<InputGuardrailData> | NamedGuardrail<InputGuardrailData>>;
|
|
338
|
+
output?: Array<GuardrailFn<OutputGuardrailData> | NamedGuardrail<OutputGuardrailData>>;
|
|
339
|
+
toolCall?: Array<GuardrailFn<ToolCallGuardrailData> | NamedGuardrail<ToolCallGuardrailData>>;
|
|
340
|
+
}
|
|
341
|
+
/** Retry configuration for agent runs */
|
|
342
|
+
interface AgentRetryConfig {
|
|
343
|
+
/** @default 1 */
|
|
344
|
+
attempts?: number;
|
|
345
|
+
/** @default "exponential" */
|
|
346
|
+
backoff?: "exponential" | "linear" | "fixed";
|
|
347
|
+
/** @default 1000 */
|
|
348
|
+
baseDelayMs?: number;
|
|
349
|
+
/** @default 30000 */
|
|
350
|
+
maxDelayMs?: number;
|
|
351
|
+
isRetryable?: (error: Error) => boolean;
|
|
352
|
+
onRetry?: (attempt: number, error: Error, delayMs: number) => void;
|
|
353
|
+
}
|
|
354
|
+
/** Agent state in facts */
|
|
355
|
+
interface AgentState {
|
|
356
|
+
status: "idle" | "running" | "paused" | "completed" | "error";
|
|
357
|
+
currentAgent: string | null;
|
|
358
|
+
input: string | null;
|
|
359
|
+
output: unknown | null;
|
|
360
|
+
error: string | null;
|
|
361
|
+
tokenUsage: number;
|
|
362
|
+
turnCount: number;
|
|
363
|
+
startedAt: number | null;
|
|
364
|
+
completedAt: number | null;
|
|
365
|
+
}
|
|
366
|
+
/** Approval state */
|
|
367
|
+
interface ApprovalState {
|
|
368
|
+
pending: ApprovalRequest[];
|
|
369
|
+
approved: string[];
|
|
370
|
+
rejected: RejectedRequest[];
|
|
371
|
+
}
|
|
372
|
+
/** Rejected request with tracking information */
|
|
373
|
+
interface RejectedRequest {
|
|
374
|
+
id: string;
|
|
375
|
+
reason?: string;
|
|
376
|
+
rejectedAt: number;
|
|
377
|
+
}
|
|
378
|
+
/** Approval request */
|
|
379
|
+
interface ApprovalRequest {
|
|
380
|
+
id: string;
|
|
381
|
+
type: "tool_call" | "output" | "handoff";
|
|
382
|
+
agentName: string;
|
|
383
|
+
description: string;
|
|
384
|
+
data: unknown;
|
|
385
|
+
requestedAt: number;
|
|
386
|
+
}
|
|
387
|
+
/** Combined orchestrator state */
|
|
388
|
+
interface OrchestratorState {
|
|
389
|
+
agent: AgentState;
|
|
390
|
+
approval: ApprovalState;
|
|
391
|
+
conversation: Message[];
|
|
392
|
+
toolCalls: ToolCall[];
|
|
393
|
+
}
|
|
394
|
+
/** Constraint for orchestrator */
|
|
395
|
+
interface OrchestratorConstraint<F extends Record<string, unknown>> {
|
|
396
|
+
when: (facts: F & OrchestratorState) => boolean | Promise<boolean>;
|
|
397
|
+
require: Requirement | ((facts: F & OrchestratorState) => Requirement);
|
|
398
|
+
priority?: number;
|
|
399
|
+
}
|
|
400
|
+
/** Resolver context for orchestrator */
|
|
401
|
+
interface OrchestratorResolverContext<F extends Record<string, unknown>> {
|
|
402
|
+
facts: F & OrchestratorState;
|
|
403
|
+
runAgent: <T>(agent: AgentLike, input: string, options?: RunOptions) => Promise<RunResult<T>>;
|
|
404
|
+
signal: AbortSignal;
|
|
405
|
+
}
|
|
406
|
+
/** Resolver for orchestrator */
|
|
407
|
+
interface OrchestratorResolver<F extends Record<string, unknown>, R extends Requirement = Requirement> {
|
|
408
|
+
requirement: (req: Requirement) => req is R;
|
|
409
|
+
key?: (req: R) => string;
|
|
410
|
+
resolve: (req: R, context: OrchestratorResolverContext<F>) => void | Promise<void>;
|
|
411
|
+
}
|
|
412
|
+
/** Lifecycle hooks for observability */
|
|
413
|
+
interface OrchestratorLifecycleHooks {
|
|
414
|
+
onAgentStart?: (event: {
|
|
415
|
+
agentName: string;
|
|
416
|
+
input: string;
|
|
417
|
+
timestamp: number;
|
|
418
|
+
}) => void;
|
|
419
|
+
onAgentComplete?: (event: {
|
|
420
|
+
agentName: string;
|
|
421
|
+
input: string;
|
|
422
|
+
output: unknown;
|
|
423
|
+
tokenUsage: number;
|
|
424
|
+
durationMs: number;
|
|
425
|
+
timestamp: number;
|
|
426
|
+
}) => void;
|
|
427
|
+
onAgentError?: (event: {
|
|
428
|
+
agentName: string;
|
|
429
|
+
input: string;
|
|
430
|
+
error: Error;
|
|
431
|
+
durationMs: number;
|
|
432
|
+
timestamp: number;
|
|
433
|
+
}) => void;
|
|
434
|
+
onGuardrailCheck?: (event: {
|
|
435
|
+
agentId?: string;
|
|
436
|
+
guardrailName: string;
|
|
437
|
+
guardrailType: "input" | "output" | "toolCall";
|
|
438
|
+
passed: boolean;
|
|
439
|
+
reason?: string;
|
|
440
|
+
durationMs: number;
|
|
441
|
+
timestamp: number;
|
|
442
|
+
}) => void;
|
|
443
|
+
onAgentRetry?: (event: {
|
|
444
|
+
agentName: string;
|
|
445
|
+
input: string;
|
|
446
|
+
attempt: number;
|
|
447
|
+
error: Error;
|
|
448
|
+
delayMs: number;
|
|
449
|
+
timestamp: number;
|
|
450
|
+
}) => void;
|
|
451
|
+
/** Called when a breakpoint is hit and waiting for resolution. */
|
|
452
|
+
onBreakpoint?: (request: BreakpointRequest) => void;
|
|
453
|
+
}
|
|
454
|
+
/** Lifecycle hooks for multi-agent orchestrator observability */
|
|
455
|
+
interface MultiAgentLifecycleHooks {
|
|
456
|
+
onAgentStart?: (event: {
|
|
457
|
+
agentId: string;
|
|
458
|
+
agentName: string;
|
|
459
|
+
input: string;
|
|
460
|
+
timestamp: number;
|
|
461
|
+
}) => void;
|
|
462
|
+
onAgentComplete?: (event: {
|
|
463
|
+
agentId: string;
|
|
464
|
+
agentName: string;
|
|
465
|
+
input: string;
|
|
466
|
+
output: unknown;
|
|
467
|
+
tokenUsage: number;
|
|
468
|
+
durationMs: number;
|
|
469
|
+
timestamp: number;
|
|
470
|
+
}) => void;
|
|
471
|
+
onAgentError?: (event: {
|
|
472
|
+
agentId: string;
|
|
473
|
+
agentName: string;
|
|
474
|
+
input: string;
|
|
475
|
+
error: Error;
|
|
476
|
+
durationMs: number;
|
|
477
|
+
timestamp: number;
|
|
478
|
+
}) => void;
|
|
479
|
+
onGuardrailCheck?: (event: {
|
|
480
|
+
agentId: string;
|
|
481
|
+
guardrailName: string;
|
|
482
|
+
guardrailType: "input" | "output" | "toolCall";
|
|
483
|
+
passed: boolean;
|
|
484
|
+
reason?: string;
|
|
485
|
+
durationMs: number;
|
|
486
|
+
timestamp: number;
|
|
487
|
+
}) => void;
|
|
488
|
+
onAgentRetry?: (event: {
|
|
489
|
+
agentId: string;
|
|
490
|
+
agentName: string;
|
|
491
|
+
input: string;
|
|
492
|
+
attempt: number;
|
|
493
|
+
error: Error;
|
|
494
|
+
delayMs: number;
|
|
495
|
+
timestamp: number;
|
|
496
|
+
}) => void;
|
|
497
|
+
onHandoff?: (request: {
|
|
498
|
+
id: string;
|
|
499
|
+
fromAgent: string;
|
|
500
|
+
toAgent: string;
|
|
501
|
+
input: string;
|
|
502
|
+
requestedAt: number;
|
|
503
|
+
}) => void;
|
|
504
|
+
onHandoffComplete?: (result: {
|
|
505
|
+
request: {
|
|
506
|
+
id: string;
|
|
507
|
+
fromAgent: string;
|
|
508
|
+
toAgent: string;
|
|
509
|
+
};
|
|
510
|
+
completedAt: number;
|
|
511
|
+
}) => void;
|
|
512
|
+
onPatternStart?: (event: {
|
|
513
|
+
patternId: string;
|
|
514
|
+
patternType: "parallel" | "sequential" | "supervisor" | "dag" | "reflect" | "race" | "debate" | "goal";
|
|
515
|
+
input: string;
|
|
516
|
+
timestamp: number;
|
|
517
|
+
}) => void;
|
|
518
|
+
onPatternComplete?: (event: {
|
|
519
|
+
patternId: string;
|
|
520
|
+
patternType: "parallel" | "sequential" | "supervisor" | "dag" | "reflect" | "race" | "debate" | "goal";
|
|
521
|
+
durationMs: number;
|
|
522
|
+
timestamp: number;
|
|
523
|
+
error?: Error;
|
|
524
|
+
}) => void;
|
|
525
|
+
onDagNodeStart?: (event: {
|
|
526
|
+
patternId: string;
|
|
527
|
+
nodeId: string;
|
|
528
|
+
agentId: string;
|
|
529
|
+
nodeType: "agent" | "task";
|
|
530
|
+
timestamp: number;
|
|
531
|
+
}) => void;
|
|
532
|
+
onDagNodeComplete?: (event: {
|
|
533
|
+
patternId: string;
|
|
534
|
+
nodeId: string;
|
|
535
|
+
agentId: string;
|
|
536
|
+
nodeType: "agent" | "task";
|
|
537
|
+
durationMs: number;
|
|
538
|
+
timestamp: number;
|
|
539
|
+
}) => void;
|
|
540
|
+
onDagNodeError?: (event: {
|
|
541
|
+
patternId: string;
|
|
542
|
+
nodeId: string;
|
|
543
|
+
agentId: string;
|
|
544
|
+
nodeType: "agent" | "task";
|
|
545
|
+
error: Error;
|
|
546
|
+
durationMs: number;
|
|
547
|
+
timestamp: number;
|
|
548
|
+
}) => void;
|
|
549
|
+
onDagNodeSkipped?: (event: {
|
|
550
|
+
patternId: string;
|
|
551
|
+
nodeId: string;
|
|
552
|
+
agentId: string;
|
|
553
|
+
nodeType: "agent" | "task";
|
|
554
|
+
reason: string;
|
|
555
|
+
timestamp: number;
|
|
556
|
+
}) => void;
|
|
557
|
+
onHealthChange?: (event: {
|
|
558
|
+
agentId: string;
|
|
559
|
+
oldScore: number;
|
|
560
|
+
newScore: number;
|
|
561
|
+
timestamp: number;
|
|
562
|
+
}) => void;
|
|
563
|
+
onReroute?: (event: RerouteEvent) => void;
|
|
564
|
+
/** Called when a breakpoint is hit and waiting for resolution. */
|
|
565
|
+
onBreakpoint?: (request: BreakpointRequest) => void;
|
|
566
|
+
/** Called when a cross-agent derivation value updates */
|
|
567
|
+
onDerivationUpdate?: (event: {
|
|
568
|
+
derivationId: string;
|
|
569
|
+
value: unknown;
|
|
570
|
+
timestamp: number;
|
|
571
|
+
}) => void;
|
|
572
|
+
/** Called when a cross-agent derivation throws an error */
|
|
573
|
+
onDerivationError?: (event: {
|
|
574
|
+
derivationId: string;
|
|
575
|
+
error: Error;
|
|
576
|
+
timestamp: number;
|
|
577
|
+
}) => void;
|
|
578
|
+
/** Called when scratchpad values are updated */
|
|
579
|
+
onScratchpadUpdate?: (event: {
|
|
580
|
+
keys: string[];
|
|
581
|
+
timestamp: number;
|
|
582
|
+
}) => void;
|
|
583
|
+
/** Called when a task starts executing */
|
|
584
|
+
onTaskStart?: (event: {
|
|
585
|
+
patternId: string;
|
|
586
|
+
taskId: string;
|
|
587
|
+
label: string;
|
|
588
|
+
timestamp: number;
|
|
589
|
+
}) => void;
|
|
590
|
+
/** Called when a task completes successfully */
|
|
591
|
+
onTaskComplete?: (event: {
|
|
592
|
+
patternId: string;
|
|
593
|
+
taskId: string;
|
|
594
|
+
label: string;
|
|
595
|
+
durationMs: number;
|
|
596
|
+
timestamp: number;
|
|
597
|
+
}) => void;
|
|
598
|
+
/** Called when a task fails */
|
|
599
|
+
onTaskError?: (event: {
|
|
600
|
+
patternId: string;
|
|
601
|
+
taskId: string;
|
|
602
|
+
label: string;
|
|
603
|
+
error: Error;
|
|
604
|
+
durationMs: number;
|
|
605
|
+
timestamp: number;
|
|
606
|
+
}) => void;
|
|
607
|
+
/** Called when a task reports progress */
|
|
608
|
+
onTaskProgress?: (event: {
|
|
609
|
+
patternId: string;
|
|
610
|
+
taskId: string;
|
|
611
|
+
label: string;
|
|
612
|
+
percent: number;
|
|
613
|
+
message?: string;
|
|
614
|
+
timestamp: number;
|
|
615
|
+
}) => void;
|
|
616
|
+
/** Called when a pattern checkpoint is saved */
|
|
617
|
+
onCheckpointSave?: (event: {
|
|
618
|
+
checkpointId: string;
|
|
619
|
+
patternType: string;
|
|
620
|
+
step: number;
|
|
621
|
+
timestamp: number;
|
|
622
|
+
}) => void;
|
|
623
|
+
/** Called when a checkpoint save fails */
|
|
624
|
+
onCheckpointError?: (event: {
|
|
625
|
+
patternType: string;
|
|
626
|
+
step: number;
|
|
627
|
+
error: Error;
|
|
628
|
+
timestamp: number;
|
|
629
|
+
}) => void;
|
|
630
|
+
}
|
|
631
|
+
/** Error codes for guardrail errors */
|
|
632
|
+
type GuardrailErrorCode = "INPUT_GUARDRAIL_FAILED" | "OUTPUT_GUARDRAIL_FAILED" | "TOOL_CALL_GUARDRAIL_FAILED" | "APPROVAL_REJECTED" | "BUDGET_EXCEEDED" | "RATE_LIMIT_EXCEEDED" | "AGENT_ERROR";
|
|
633
|
+
/**
|
|
634
|
+
* Structured error for guardrail failures.
|
|
635
|
+
*
|
|
636
|
+
* **Security:** The `input` and `data` properties are non-enumerable to prevent
|
|
637
|
+
* accidental leakage of sensitive data via JSON.stringify or console.log.
|
|
638
|
+
*/
|
|
639
|
+
declare class GuardrailError extends Error {
|
|
640
|
+
readonly code: GuardrailErrorCode;
|
|
641
|
+
readonly guardrailName: string;
|
|
642
|
+
readonly guardrailType: "input" | "output" | "toolCall";
|
|
643
|
+
readonly userMessage: string;
|
|
644
|
+
readonly data: unknown;
|
|
645
|
+
readonly agentName: string;
|
|
646
|
+
readonly input: string;
|
|
647
|
+
constructor(options: {
|
|
648
|
+
code: GuardrailErrorCode;
|
|
649
|
+
message: string;
|
|
650
|
+
guardrailName: string;
|
|
651
|
+
guardrailType: "input" | "output" | "toolCall";
|
|
652
|
+
userMessage?: string;
|
|
653
|
+
data?: unknown;
|
|
654
|
+
agentName: string;
|
|
655
|
+
input: string;
|
|
656
|
+
cause?: Error;
|
|
657
|
+
});
|
|
658
|
+
toJSON(): Record<string, unknown>;
|
|
659
|
+
}
|
|
660
|
+
/** Check if an error is a GuardrailError. */
|
|
661
|
+
declare function isGuardrailError(error: unknown): error is GuardrailError;
|
|
662
|
+
/** Schema validation result */
|
|
663
|
+
interface SchemaValidationResult {
|
|
664
|
+
valid: boolean;
|
|
665
|
+
errors?: string[];
|
|
666
|
+
}
|
|
667
|
+
/** Schema validator function type */
|
|
668
|
+
type SchemaValidator<_T = unknown> = (value: unknown) => SchemaValidationResult | boolean;
|
|
669
|
+
/** Status of a DAG node during execution */
|
|
670
|
+
type DagNodeStatus = "pending" | "ready" | "running" | "completed" | "error" | "skipped";
|
|
671
|
+
/** Execution context available to DAG node callbacks */
|
|
672
|
+
interface DagExecutionContext {
|
|
673
|
+
/** Original input to the DAG */
|
|
674
|
+
input: string;
|
|
675
|
+
/** Outputs keyed by node ID (populated as nodes complete) */
|
|
676
|
+
outputs: Record<string, unknown>;
|
|
677
|
+
/** Statuses keyed by node ID */
|
|
678
|
+
statuses: Record<string, DagNodeStatus>;
|
|
679
|
+
/** Error messages keyed by node ID */
|
|
680
|
+
errors: Record<string, string>;
|
|
681
|
+
/** Full RunResult keyed by node ID */
|
|
682
|
+
results: Record<string, RunResult<unknown>>;
|
|
683
|
+
}
|
|
684
|
+
/** A node in a DAG execution pattern */
|
|
685
|
+
interface DagNode {
|
|
686
|
+
/** Registered handler ID (agent or task) to run for this node */
|
|
687
|
+
handler: string;
|
|
688
|
+
/** Upstream node IDs this node depends on */
|
|
689
|
+
deps?: string[];
|
|
690
|
+
/** Conditional edge — evaluated when deps are met. @default unconditional */
|
|
691
|
+
when?: (context: DagExecutionContext) => boolean;
|
|
692
|
+
/** Build input string for this node's agent. @default JSON.stringify(upstream outputs) */
|
|
693
|
+
transform?: (context: DagExecutionContext) => string;
|
|
694
|
+
/** Per-node timeout (ms) */
|
|
695
|
+
timeout?: number;
|
|
696
|
+
/** Tiebreaker when multiple nodes are ready (higher = first). @default 0 */
|
|
697
|
+
priority?: number;
|
|
698
|
+
}
|
|
699
|
+
/** DAG execution pattern — nodes are agents, edges are reactive conditions */
|
|
700
|
+
interface DagPattern<T = unknown> {
|
|
701
|
+
type: "dag";
|
|
702
|
+
/** Nodes keyed by node ID */
|
|
703
|
+
nodes: Record<string, DagNode>;
|
|
704
|
+
/** Merge all node outputs into the final result */
|
|
705
|
+
merge: (context: DagExecutionContext) => T | Promise<T>;
|
|
706
|
+
/** Overall DAG timeout (ms) */
|
|
707
|
+
timeout?: number;
|
|
708
|
+
/** Maximum nodes running concurrently. @default Infinity. Consider setting this to avoid API rate limits. */
|
|
709
|
+
maxConcurrent?: number;
|
|
710
|
+
/** Error handling strategy. @default "fail" */
|
|
711
|
+
onNodeError?: "fail" | "skip-downstream" | "continue";
|
|
712
|
+
/** Checkpoint configuration for mid-execution fault tolerance */
|
|
713
|
+
checkpoint?: PatternCheckpointConfig;
|
|
714
|
+
}
|
|
715
|
+
/** Debug configuration for orchestrators */
|
|
716
|
+
interface OrchestratorDebugConfig {
|
|
717
|
+
verboseTimeline?: boolean;
|
|
718
|
+
}
|
|
719
|
+
/** All debug event types */
|
|
720
|
+
type DebugEventType = "agent_start" | "agent_complete" | "agent_error" | "agent_retry" | "guardrail_check" | "constraint_evaluate" | "resolver_start" | "resolver_complete" | "resolver_error" | "approval_request" | "approval_response" | "handoff_start" | "handoff_complete" | "pattern_start" | "pattern_complete" | "dag_node_update" | "breakpoint_hit" | "breakpoint_resumed" | "derivation_update" | "scratchpad_update" | "reflection_iteration" | "race_start" | "race_winner" | "race_cancelled" | "debate_round" | "reroute" | "checkpoint_save" | "checkpoint_restore" | "task_start" | "task_complete" | "task_error" | "task_progress" | "goal_step";
|
|
721
|
+
/** Base debug event */
|
|
722
|
+
interface DebugEventBase {
|
|
723
|
+
id: number;
|
|
724
|
+
type: DebugEventType;
|
|
725
|
+
timestamp: number;
|
|
726
|
+
agentId?: string;
|
|
727
|
+
snapshotId: number | null;
|
|
728
|
+
}
|
|
729
|
+
/** Agent start event */
|
|
730
|
+
interface AgentStartEvent extends DebugEventBase {
|
|
731
|
+
type: "agent_start";
|
|
732
|
+
agentId: string;
|
|
733
|
+
inputLength: number;
|
|
734
|
+
/** Truncated input text (max 5000 chars) */
|
|
735
|
+
input?: string;
|
|
736
|
+
}
|
|
737
|
+
/** Agent complete event */
|
|
738
|
+
interface AgentCompleteEvent extends DebugEventBase {
|
|
739
|
+
type: "agent_complete";
|
|
740
|
+
agentId: string;
|
|
741
|
+
outputLength: number;
|
|
742
|
+
totalTokens: number;
|
|
743
|
+
inputTokens: number;
|
|
744
|
+
outputTokens: number;
|
|
745
|
+
durationMs: number;
|
|
746
|
+
modelId?: string;
|
|
747
|
+
/** Truncated output text (max 5000 chars) */
|
|
748
|
+
output?: string;
|
|
749
|
+
}
|
|
750
|
+
/** Agent error event */
|
|
751
|
+
interface AgentErrorEvent extends DebugEventBase {
|
|
752
|
+
type: "agent_error";
|
|
753
|
+
agentId: string;
|
|
754
|
+
errorMessage: string;
|
|
755
|
+
durationMs: number;
|
|
756
|
+
}
|
|
757
|
+
/** Agent retry event */
|
|
758
|
+
interface AgentRetryEvent extends DebugEventBase {
|
|
759
|
+
type: "agent_retry";
|
|
760
|
+
agentId: string;
|
|
761
|
+
attempt: number;
|
|
762
|
+
errorMessage: string;
|
|
763
|
+
delayMs: number;
|
|
764
|
+
}
|
|
765
|
+
/** Guardrail check event */
|
|
766
|
+
interface GuardrailCheckEvent extends DebugEventBase {
|
|
767
|
+
type: "guardrail_check";
|
|
768
|
+
guardrailName: string;
|
|
769
|
+
guardrailType: "input" | "output" | "toolCall";
|
|
770
|
+
passed: boolean;
|
|
771
|
+
reason?: string;
|
|
772
|
+
durationMs: number;
|
|
773
|
+
}
|
|
774
|
+
/** Constraint evaluate event */
|
|
775
|
+
interface ConstraintEvaluateEvent extends DebugEventBase {
|
|
776
|
+
type: "constraint_evaluate";
|
|
777
|
+
constraintId: string;
|
|
778
|
+
fired: boolean;
|
|
779
|
+
}
|
|
780
|
+
/** Resolver start event */
|
|
781
|
+
interface ResolverStartEvent extends DebugEventBase {
|
|
782
|
+
type: "resolver_start";
|
|
783
|
+
resolverId: string;
|
|
784
|
+
requirementType: string;
|
|
785
|
+
}
|
|
786
|
+
/** Resolver complete event */
|
|
787
|
+
interface ResolverCompleteEvent extends DebugEventBase {
|
|
788
|
+
type: "resolver_complete";
|
|
789
|
+
resolverId: string;
|
|
790
|
+
durationMs: number;
|
|
791
|
+
}
|
|
792
|
+
/** Resolver error event */
|
|
793
|
+
interface ResolverErrorEvent extends DebugEventBase {
|
|
794
|
+
type: "resolver_error";
|
|
795
|
+
resolverId: string;
|
|
796
|
+
errorMessage: string;
|
|
797
|
+
durationMs: number;
|
|
798
|
+
}
|
|
799
|
+
/** Approval request event */
|
|
800
|
+
interface ApprovalRequestEvent extends DebugEventBase {
|
|
801
|
+
type: "approval_request";
|
|
802
|
+
requestId: string;
|
|
803
|
+
approvalType: "tool_call" | "output" | "handoff";
|
|
804
|
+
}
|
|
805
|
+
/** Approval response event */
|
|
806
|
+
interface ApprovalResponseEvent extends DebugEventBase {
|
|
807
|
+
type: "approval_response";
|
|
808
|
+
requestId: string;
|
|
809
|
+
approved: boolean;
|
|
810
|
+
reason?: string;
|
|
811
|
+
}
|
|
812
|
+
/** Handoff start event */
|
|
813
|
+
interface HandoffStartEvent extends DebugEventBase {
|
|
814
|
+
type: "handoff_start";
|
|
815
|
+
fromAgent: string;
|
|
816
|
+
toAgent: string;
|
|
817
|
+
}
|
|
818
|
+
/** Handoff complete event */
|
|
819
|
+
interface HandoffCompleteEvent extends DebugEventBase {
|
|
820
|
+
type: "handoff_complete";
|
|
821
|
+
fromAgent: string;
|
|
822
|
+
toAgent: string;
|
|
823
|
+
durationMs: number;
|
|
824
|
+
}
|
|
825
|
+
/** Pattern start event */
|
|
826
|
+
interface PatternStartEvent extends DebugEventBase {
|
|
827
|
+
type: "pattern_start";
|
|
828
|
+
patternId: string;
|
|
829
|
+
patternType: "parallel" | "sequential" | "supervisor" | "dag" | "reflect" | "race" | "debate" | "goal";
|
|
830
|
+
/** All handler IDs in this pattern (agents + tasks) */
|
|
831
|
+
handlers?: string[];
|
|
832
|
+
/** Which handler IDs are tasks (rest are agents) */
|
|
833
|
+
taskIds?: string[];
|
|
834
|
+
}
|
|
835
|
+
/** Pattern complete event */
|
|
836
|
+
interface PatternCompleteEvent extends DebugEventBase {
|
|
837
|
+
type: "pattern_complete";
|
|
838
|
+
patternId: string;
|
|
839
|
+
patternType: "parallel" | "sequential" | "supervisor" | "dag" | "reflect" | "race" | "debate" | "goal";
|
|
840
|
+
durationMs: number;
|
|
841
|
+
error?: string;
|
|
842
|
+
}
|
|
843
|
+
/** DAG node update event */
|
|
844
|
+
interface DagNodeUpdateEvent extends DebugEventBase {
|
|
845
|
+
type: "dag_node_update";
|
|
846
|
+
nodeId: string;
|
|
847
|
+
status: DagNodeStatus;
|
|
848
|
+
deps?: string[];
|
|
849
|
+
}
|
|
850
|
+
/** Breakpoint hit event */
|
|
851
|
+
interface BreakpointHitEvent extends DebugEventBase {
|
|
852
|
+
type: "breakpoint_hit";
|
|
853
|
+
breakpointId: string;
|
|
854
|
+
breakpointType: string;
|
|
855
|
+
label?: string;
|
|
856
|
+
}
|
|
857
|
+
/** Breakpoint resumed event */
|
|
858
|
+
interface BreakpointResumedEvent extends DebugEventBase {
|
|
859
|
+
type: "breakpoint_resumed";
|
|
860
|
+
breakpointId: string;
|
|
861
|
+
modified: boolean;
|
|
862
|
+
skipped: boolean;
|
|
863
|
+
}
|
|
864
|
+
/** Derivation update event */
|
|
865
|
+
interface DerivationUpdateEvent extends DebugEventBase {
|
|
866
|
+
type: "derivation_update";
|
|
867
|
+
derivationId: string;
|
|
868
|
+
valueType: string;
|
|
869
|
+
}
|
|
870
|
+
/** Scratchpad update event */
|
|
871
|
+
interface ScratchpadUpdateEvent extends DebugEventBase {
|
|
872
|
+
type: "scratchpad_update";
|
|
873
|
+
keys: string[];
|
|
874
|
+
}
|
|
875
|
+
/** Reflection iteration event */
|
|
876
|
+
interface ReflectionIterationEvent extends DebugEventBase {
|
|
877
|
+
type: "reflection_iteration";
|
|
878
|
+
iteration: number;
|
|
879
|
+
passed: boolean;
|
|
880
|
+
score?: number;
|
|
881
|
+
durationMs: number;
|
|
882
|
+
producerTokens: number;
|
|
883
|
+
evaluatorTokens: number;
|
|
884
|
+
}
|
|
885
|
+
/** Race start event */
|
|
886
|
+
interface RaceStartEvent extends DebugEventBase {
|
|
887
|
+
type: "race_start";
|
|
888
|
+
patternId: string;
|
|
889
|
+
agents: string[];
|
|
890
|
+
}
|
|
891
|
+
/** Race winner event */
|
|
892
|
+
interface RaceWinnerEvent extends DebugEventBase {
|
|
893
|
+
type: "race_winner";
|
|
894
|
+
patternId: string;
|
|
895
|
+
winnerId: string;
|
|
896
|
+
durationMs: number;
|
|
897
|
+
}
|
|
898
|
+
/** Race cancelled event */
|
|
899
|
+
interface RaceCancelledEvent extends DebugEventBase {
|
|
900
|
+
type: "race_cancelled";
|
|
901
|
+
patternId: string;
|
|
902
|
+
cancelledIds: string[];
|
|
903
|
+
reason: "winner_found" | "timeout" | "all_failed";
|
|
904
|
+
}
|
|
905
|
+
/** Debate round event — emitted after each round's judgement */
|
|
906
|
+
interface DebateRoundEvent extends DebugEventBase {
|
|
907
|
+
type: "debate_round";
|
|
908
|
+
patternId: string;
|
|
909
|
+
round: number;
|
|
910
|
+
totalRounds: number;
|
|
911
|
+
winnerId: string;
|
|
912
|
+
score?: number;
|
|
913
|
+
agentCount: number;
|
|
914
|
+
}
|
|
915
|
+
/** Reroute debug event recorded when self-healing reroutes to an alternate agent */
|
|
916
|
+
interface RerouteDebugEvent extends DebugEventBase {
|
|
917
|
+
type: "reroute";
|
|
918
|
+
agentId: string;
|
|
919
|
+
from: string;
|
|
920
|
+
to: string;
|
|
921
|
+
reason: string;
|
|
922
|
+
}
|
|
923
|
+
/** Checkpoint save event */
|
|
924
|
+
interface CheckpointSaveEvent extends DebugEventBase {
|
|
925
|
+
type: "checkpoint_save";
|
|
926
|
+
checkpointId: string;
|
|
927
|
+
patternType: string;
|
|
928
|
+
step: number;
|
|
929
|
+
}
|
|
930
|
+
/** Checkpoint restore event */
|
|
931
|
+
interface CheckpointRestoreEvent extends DebugEventBase {
|
|
932
|
+
type: "checkpoint_restore";
|
|
933
|
+
checkpointId: string;
|
|
934
|
+
patternType: string;
|
|
935
|
+
step: number;
|
|
936
|
+
}
|
|
937
|
+
/** Task start event */
|
|
938
|
+
interface TaskStartEvent extends DebugEventBase {
|
|
939
|
+
type: "task_start";
|
|
940
|
+
taskId: string;
|
|
941
|
+
label: string;
|
|
942
|
+
description?: string;
|
|
943
|
+
inputLength: number;
|
|
944
|
+
}
|
|
945
|
+
/** Task complete event */
|
|
946
|
+
interface TaskCompleteEvent extends DebugEventBase {
|
|
947
|
+
type: "task_complete";
|
|
948
|
+
taskId: string;
|
|
949
|
+
label: string;
|
|
950
|
+
durationMs: number;
|
|
951
|
+
}
|
|
952
|
+
/** Task error event */
|
|
953
|
+
interface TaskErrorEvent extends DebugEventBase {
|
|
954
|
+
type: "task_error";
|
|
955
|
+
taskId: string;
|
|
956
|
+
label: string;
|
|
957
|
+
error: string;
|
|
958
|
+
durationMs: number;
|
|
959
|
+
attempt?: number;
|
|
960
|
+
}
|
|
961
|
+
/** Task progress event */
|
|
962
|
+
interface TaskProgressEvent extends DebugEventBase {
|
|
963
|
+
type: "task_progress";
|
|
964
|
+
taskId: string;
|
|
965
|
+
label: string;
|
|
966
|
+
percent: number;
|
|
967
|
+
message?: string;
|
|
968
|
+
}
|
|
969
|
+
/** Goal step event — emitted for each agent invocation within a goal step */
|
|
970
|
+
interface GoalStepEvent extends DebugEventBase {
|
|
971
|
+
type: "goal_step";
|
|
972
|
+
agentId: string;
|
|
973
|
+
step: number;
|
|
974
|
+
nodeId: string;
|
|
975
|
+
satisfaction: number;
|
|
976
|
+
satisfactionDelta: number;
|
|
977
|
+
}
|
|
978
|
+
/** Union of all debug event types */
|
|
979
|
+
type DebugEvent = AgentStartEvent | AgentCompleteEvent | AgentErrorEvent | AgentRetryEvent | GuardrailCheckEvent | ConstraintEvaluateEvent | ResolverStartEvent | ResolverCompleteEvent | ResolverErrorEvent | ApprovalRequestEvent | ApprovalResponseEvent | HandoffStartEvent | HandoffCompleteEvent | PatternStartEvent | PatternCompleteEvent | DagNodeUpdateEvent | BreakpointHitEvent | BreakpointResumedEvent | DerivationUpdateEvent | ScratchpadUpdateEvent | ReflectionIterationEvent | RaceStartEvent | RaceWinnerEvent | RaceCancelledEvent | DebateRoundEvent | RerouteDebugEvent | CheckpointSaveEvent | CheckpointRestoreEvent | TaskStartEvent | TaskCompleteEvent | TaskErrorEvent | TaskProgressEvent | GoalStepEvent;
|
|
980
|
+
/** Health state for an agent stored in facts */
|
|
981
|
+
interface AgentHealthState {
|
|
982
|
+
circuitState: "CLOSED" | "OPEN" | "HALF_OPEN";
|
|
983
|
+
healthScore: number;
|
|
984
|
+
lastUpdated: number;
|
|
985
|
+
}
|
|
986
|
+
/** Reroute event fired when an agent is rerouted */
|
|
987
|
+
interface RerouteEvent {
|
|
988
|
+
originalAgent: string;
|
|
989
|
+
reroutedTo: string;
|
|
990
|
+
reason: string;
|
|
991
|
+
timestamp: number;
|
|
992
|
+
}
|
|
993
|
+
/** Health monitor configuration */
|
|
994
|
+
interface HealthMonitorConfig {
|
|
995
|
+
/** Rolling window for metrics (ms). @default 60000 */
|
|
996
|
+
windowMs?: number;
|
|
997
|
+
/** Weights for health score computation (must sum to ~1.0) */
|
|
998
|
+
weights?: {
|
|
999
|
+
/** Weight for success rate (0-1). @default 0.5 */
|
|
1000
|
+
successRate?: number;
|
|
1001
|
+
/** Weight for latency (0-1). @default 0.3 */
|
|
1002
|
+
latency?: number;
|
|
1003
|
+
/** Weight for circuit state (0-1). @default 0.2 */
|
|
1004
|
+
circuitState?: number;
|
|
1005
|
+
};
|
|
1006
|
+
/** Max latency considered "normal" (ms). @default 5000 */
|
|
1007
|
+
maxNormalLatencyMs?: number;
|
|
1008
|
+
/** Max events per agent before FIFO eviction. @default 1000 */
|
|
1009
|
+
maxEventsPerAgent?: number;
|
|
1010
|
+
}
|
|
1011
|
+
/** Self-healing configuration for single-agent orchestrator */
|
|
1012
|
+
interface SelfHealingConfig {
|
|
1013
|
+
/** Fallback runners to try in order when primary CB is open */
|
|
1014
|
+
fallbackRunners?: AgentRunner[];
|
|
1015
|
+
/** Fallback agent to try when all runners fail */
|
|
1016
|
+
fallbackAgent?: AgentLike;
|
|
1017
|
+
/** Circuit breaker config for primary runner */
|
|
1018
|
+
circuitBreaker?: AgentCircuitBreakerConfig;
|
|
1019
|
+
/** Health score below which to trigger reroute. @default 30 */
|
|
1020
|
+
healthThreshold?: number;
|
|
1021
|
+
/** Behavior when all fallbacks exhausted */
|
|
1022
|
+
degradation?: "reject" | "fallback-response";
|
|
1023
|
+
/** Static response to return when degradation is "fallback-response" */
|
|
1024
|
+
fallbackResponse?: unknown;
|
|
1025
|
+
/** Callback when reroute occurs */
|
|
1026
|
+
onReroute?: (event: RerouteEvent) => void;
|
|
1027
|
+
}
|
|
1028
|
+
/** Self-healing configuration for multi-agent orchestrator */
|
|
1029
|
+
interface MultiAgentSelfHealingConfig {
|
|
1030
|
+
/** Default circuit breaker config for agents without their own */
|
|
1031
|
+
circuitBreakerDefaults?: AgentCircuitBreakerConfig;
|
|
1032
|
+
/** Health score below which to trigger reroute. @default 30 */
|
|
1033
|
+
healthThreshold?: number;
|
|
1034
|
+
/** Explicit equivalency groups (group name → agent IDs) */
|
|
1035
|
+
equivalencyGroups?: Record<string, string[]>;
|
|
1036
|
+
/** Use capability matching for implicit equivalency. @default true */
|
|
1037
|
+
useCapabilities?: boolean;
|
|
1038
|
+
/** Strategy for selecting equivalent agent */
|
|
1039
|
+
selectionStrategy?: "healthiest" | "round-robin";
|
|
1040
|
+
/** Behavior when all equivalents are down */
|
|
1041
|
+
degradation?: "reject" | "fallback-response";
|
|
1042
|
+
/** Static response for "fallback-response" degradation */
|
|
1043
|
+
fallbackResponse?: unknown;
|
|
1044
|
+
/** Callback when reroute occurs */
|
|
1045
|
+
onReroute?: (event: RerouteEvent) => void;
|
|
1046
|
+
/** Callback when agent health changes */
|
|
1047
|
+
onHealthChange?: (event: {
|
|
1048
|
+
agentId: string;
|
|
1049
|
+
oldScore: number;
|
|
1050
|
+
newScore: number;
|
|
1051
|
+
}) => void;
|
|
1052
|
+
/** Health monitor configuration */
|
|
1053
|
+
healthMonitor?: HealthMonitorConfig;
|
|
1054
|
+
}
|
|
1055
|
+
/** Circuit breaker config for AI agent self-healing (simplified subset of core CircuitBreakerConfig) */
|
|
1056
|
+
interface AgentCircuitBreakerConfig {
|
|
1057
|
+
/** Number of failures before opening. @default 5 */
|
|
1058
|
+
failureThreshold?: number;
|
|
1059
|
+
/** Time before trying half-open (ms). @default 30000 */
|
|
1060
|
+
resetTimeoutMs?: number;
|
|
1061
|
+
/** Successes needed to close from half-open. @default 2 */
|
|
1062
|
+
halfOpenSuccesses?: number;
|
|
1063
|
+
/** State change callback */
|
|
1064
|
+
onStateChange?: (from: string, to: string) => void;
|
|
1065
|
+
}
|
|
1066
|
+
/** Breakpoint state stored in bridge schema — canonical definition in breakpoints.ts */
|
|
1067
|
+
type BreakpointState = BreakpointState$1;
|
|
1068
|
+
/** Snapshot of all agent states for cross-agent derivations */
|
|
1069
|
+
interface CrossAgentSnapshot {
|
|
1070
|
+
agents: Record<string, {
|
|
1071
|
+
status: "idle" | "running" | "completed" | "error";
|
|
1072
|
+
lastInput?: string;
|
|
1073
|
+
lastOutput?: unknown;
|
|
1074
|
+
lastError?: string;
|
|
1075
|
+
runCount: number;
|
|
1076
|
+
totalTokens: number;
|
|
1077
|
+
}>;
|
|
1078
|
+
coordinator: {
|
|
1079
|
+
globalTokens: number;
|
|
1080
|
+
status: string;
|
|
1081
|
+
};
|
|
1082
|
+
scratchpad?: Record<string, unknown>;
|
|
1083
|
+
}
|
|
1084
|
+
/** Function that computes a derived value from a cross-agent snapshot */
|
|
1085
|
+
type CrossAgentDerivationFn<T = unknown> = (snapshot: CrossAgentSnapshot) => T;
|
|
1086
|
+
/** Shared scratchpad interface for multi-agent collaboration */
|
|
1087
|
+
interface Scratchpad<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
1088
|
+
get<K extends keyof T>(key: K): T[K];
|
|
1089
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
|
1090
|
+
/** Check if a key exists in the scratchpad */
|
|
1091
|
+
has<K extends keyof T>(key: K): boolean;
|
|
1092
|
+
/** Delete a key from the scratchpad */
|
|
1093
|
+
delete<K extends keyof T>(key: K): void;
|
|
1094
|
+
update(values: Partial<T>): void;
|
|
1095
|
+
getAll(): T;
|
|
1096
|
+
subscribe(keys: (keyof T)[], callback: (key: keyof T, value: unknown) => void): () => void;
|
|
1097
|
+
onChange(callback: (key: string, value: unknown) => void): () => void;
|
|
1098
|
+
reset(): void;
|
|
1099
|
+
}
|
|
1100
|
+
/** A node in a goal execution pattern */
|
|
1101
|
+
interface GoalNode {
|
|
1102
|
+
/** Handler ID — agent or task registered on the orchestrator */
|
|
1103
|
+
handler: string;
|
|
1104
|
+
/** Fact keys this node can produce */
|
|
1105
|
+
produces: string[];
|
|
1106
|
+
/** Fact keys this node needs (must be satisfied before running) */
|
|
1107
|
+
requires?: string[];
|
|
1108
|
+
/** Allow re-run if input facts change after completion */
|
|
1109
|
+
allowRerun?: boolean;
|
|
1110
|
+
/** Priority for selection when multiple nodes are ready. Higher = first */
|
|
1111
|
+
priority?: number;
|
|
1112
|
+
/** Build the input string from current facts */
|
|
1113
|
+
buildInput?: (facts: Record<string, unknown>) => string;
|
|
1114
|
+
/** Extract output facts from the agent's result */
|
|
1115
|
+
extractOutput?: (result: RunResult<unknown>) => Record<string, unknown>;
|
|
1116
|
+
}
|
|
1117
|
+
/** Goal step metrics */
|
|
1118
|
+
interface GoalStepMetrics {
|
|
1119
|
+
step: number;
|
|
1120
|
+
durationMs: number;
|
|
1121
|
+
nodesRun: string[];
|
|
1122
|
+
factsProduced: string[];
|
|
1123
|
+
satisfaction: number;
|
|
1124
|
+
satisfactionDelta: number;
|
|
1125
|
+
tokensConsumed: number;
|
|
1126
|
+
}
|
|
1127
|
+
/** Goal progress metrics */
|
|
1128
|
+
interface GoalMetrics {
|
|
1129
|
+
satisfaction: number;
|
|
1130
|
+
progressRate: number;
|
|
1131
|
+
estimatedStepsRemaining: number | null;
|
|
1132
|
+
decelerating: boolean;
|
|
1133
|
+
}
|
|
1134
|
+
/** Agent selection strategy for goal pattern */
|
|
1135
|
+
interface AgentSelectionStrategy {
|
|
1136
|
+
/**
|
|
1137
|
+
* Select which ready agents to run this step.
|
|
1138
|
+
*
|
|
1139
|
+
* @param readyAgents - Agent IDs whose `requires` are satisfied
|
|
1140
|
+
* @param metrics - Per-agent performance metrics (runs, avgSatisfactionDelta, tokens)
|
|
1141
|
+
* @param goalMetrics - Global goal progress metrics. Built-in strategies use per-agent
|
|
1142
|
+
* metrics only; this parameter enables custom strategies that account for overall goal
|
|
1143
|
+
* progress (e.g., switching to cheaper agents as satisfaction approaches 1.0).
|
|
1144
|
+
*/
|
|
1145
|
+
select: (readyAgents: string[], metrics: Record<string, {
|
|
1146
|
+
runs: number;
|
|
1147
|
+
avgSatisfactionDelta: number;
|
|
1148
|
+
tokens: number;
|
|
1149
|
+
}>, goalMetrics: GoalMetrics) => string[];
|
|
1150
|
+
}
|
|
1151
|
+
/** Relaxation context passed to custom relaxation strategies */
|
|
1152
|
+
interface RelaxationContext {
|
|
1153
|
+
step: number;
|
|
1154
|
+
facts: Record<string, unknown>;
|
|
1155
|
+
metrics: GoalMetrics;
|
|
1156
|
+
completedNodes: Set<string>;
|
|
1157
|
+
failedNodes: Map<string, number>;
|
|
1158
|
+
}
|
|
1159
|
+
/** Relaxation strategy for when goal pursuit stalls */
|
|
1160
|
+
type RelaxationStrategy = {
|
|
1161
|
+
type: "allow_rerun";
|
|
1162
|
+
nodes: string[];
|
|
1163
|
+
} | {
|
|
1164
|
+
type: "alternative_nodes";
|
|
1165
|
+
nodes: GoalNode[];
|
|
1166
|
+
} | {
|
|
1167
|
+
type: "inject_facts";
|
|
1168
|
+
facts: Record<string, unknown>;
|
|
1169
|
+
} | {
|
|
1170
|
+
type: "accept_partial";
|
|
1171
|
+
} | {
|
|
1172
|
+
type: "custom";
|
|
1173
|
+
apply: (context: RelaxationContext) => void | Promise<void>;
|
|
1174
|
+
};
|
|
1175
|
+
/** Relaxation tier — progressively applied when goal pursuit stalls */
|
|
1176
|
+
interface RelaxationTier {
|
|
1177
|
+
label: string;
|
|
1178
|
+
/** Steps of no progress before applying. @default 3 */
|
|
1179
|
+
afterStallSteps?: number;
|
|
1180
|
+
strategy: RelaxationStrategy;
|
|
1181
|
+
}
|
|
1182
|
+
/** Record of a relaxation event */
|
|
1183
|
+
interface RelaxationRecord {
|
|
1184
|
+
step: number;
|
|
1185
|
+
tierIndex: number;
|
|
1186
|
+
label: string;
|
|
1187
|
+
strategy: RelaxationStrategy["type"];
|
|
1188
|
+
}
|
|
1189
|
+
/** Goal execution pattern — declare desired state, let the runtime resolve */
|
|
1190
|
+
interface GoalPattern<T = unknown> {
|
|
1191
|
+
type: "goal";
|
|
1192
|
+
/** Nodes with produces/requires declarations */
|
|
1193
|
+
nodes: Record<string, GoalNode>;
|
|
1194
|
+
/** Goal condition — when this returns true, the goal is achieved */
|
|
1195
|
+
when: (facts: Record<string, unknown>) => boolean;
|
|
1196
|
+
/** Quantitative satisfaction: 0.0 to 1.0. Enables progress tracking.
|
|
1197
|
+
* If omitted, binary: 0.0 when when() is false, 1.0 when true. */
|
|
1198
|
+
satisfaction?: (facts: Record<string, unknown>) => number;
|
|
1199
|
+
/** Max goal steps. @default 50 */
|
|
1200
|
+
maxSteps?: number;
|
|
1201
|
+
/** Extract final result from achieved facts */
|
|
1202
|
+
extract?: (facts: Record<string, unknown>) => T;
|
|
1203
|
+
/** Timeout in ms. @default 300000 */
|
|
1204
|
+
timeout?: number;
|
|
1205
|
+
/** Abort signal */
|
|
1206
|
+
signal?: AbortSignal;
|
|
1207
|
+
/** Agent selection strategy. @default "all-ready" */
|
|
1208
|
+
selectionStrategy?: AgentSelectionStrategy;
|
|
1209
|
+
/** Relaxation tiers — progressively applied when goal pursuit stalls */
|
|
1210
|
+
relaxation?: RelaxationTier[];
|
|
1211
|
+
/** Lifecycle hooks */
|
|
1212
|
+
onStep?: (step: number, facts: Record<string, unknown>, readyAgents: string[]) => void;
|
|
1213
|
+
onStall?: (step: number, metrics: GoalMetrics) => void;
|
|
1214
|
+
/** Checkpoint configuration for mid-execution fault tolerance */
|
|
1215
|
+
checkpoint?: PatternCheckpointConfig;
|
|
1216
|
+
}
|
|
1217
|
+
/** Result of a goal pattern execution */
|
|
1218
|
+
interface GoalResult<T = unknown> {
|
|
1219
|
+
/** Whether the when() condition was satisfied */
|
|
1220
|
+
achieved: boolean;
|
|
1221
|
+
/** Final value (from extract, or raw facts) */
|
|
1222
|
+
result: T;
|
|
1223
|
+
/** Final facts state */
|
|
1224
|
+
facts: Record<string, unknown>;
|
|
1225
|
+
/** Nodes that ran, in execution order */
|
|
1226
|
+
executionOrder: string[];
|
|
1227
|
+
/** Per-node results */
|
|
1228
|
+
nodeResults: Record<string, RunResult<unknown>>;
|
|
1229
|
+
/** Total goal steps taken */
|
|
1230
|
+
steps: number;
|
|
1231
|
+
/** Total tokens consumed */
|
|
1232
|
+
totalTokens: number;
|
|
1233
|
+
/** Total duration (ms) */
|
|
1234
|
+
durationMs: number;
|
|
1235
|
+
/** Per-step metrics (satisfaction, nodes run, etc.) */
|
|
1236
|
+
stepMetrics: GoalStepMetrics[];
|
|
1237
|
+
/** Relaxation events applied */
|
|
1238
|
+
relaxations: RelaxationRecord[];
|
|
1239
|
+
/** Error message if goal was not achieved */
|
|
1240
|
+
error?: string;
|
|
1241
|
+
}
|
|
1242
|
+
/** Universal checkpoint configuration for all execution patterns */
|
|
1243
|
+
interface PatternCheckpointConfig {
|
|
1244
|
+
/** Save a checkpoint every N steps/rounds/iterations. @default 5 */
|
|
1245
|
+
everyN?: number;
|
|
1246
|
+
/** Checkpoint store. Uses the orchestrator's store if not provided. */
|
|
1247
|
+
store?: CheckpointStore;
|
|
1248
|
+
/** Label prefix for checkpoints. @default pattern type name */
|
|
1249
|
+
labelPrefix?: string;
|
|
1250
|
+
/** Conditional: only save when this returns true */
|
|
1251
|
+
when?: (context: CheckpointContext) => boolean;
|
|
1252
|
+
}
|
|
1253
|
+
/** Context passed to conditional checkpoint predicates */
|
|
1254
|
+
interface CheckpointContext {
|
|
1255
|
+
/** Current step/round/iteration number */
|
|
1256
|
+
step: number;
|
|
1257
|
+
/** Pattern type identifier */
|
|
1258
|
+
patternType: string;
|
|
1259
|
+
/** Pattern-specific facts (goal only) */
|
|
1260
|
+
facts?: Record<string, unknown>;
|
|
1261
|
+
/** Satisfaction score 0-1 (goal only) */
|
|
1262
|
+
satisfaction?: number;
|
|
1263
|
+
}
|
|
1264
|
+
type GoalCheckpointConfig = PatternCheckpointConfig;
|
|
1265
|
+
/** Common fields present on all pattern checkpoint states */
|
|
1266
|
+
interface PatternCheckpointBase {
|
|
1267
|
+
/** Checkpoint format version */
|
|
1268
|
+
version: 1;
|
|
1269
|
+
/** Unique ID */
|
|
1270
|
+
id: string;
|
|
1271
|
+
/** ISO timestamp */
|
|
1272
|
+
createdAt: string;
|
|
1273
|
+
/** User label */
|
|
1274
|
+
label?: string;
|
|
1275
|
+
/** Pattern ID */
|
|
1276
|
+
patternId: string;
|
|
1277
|
+
/** Total expected steps/rounds/iterations (null for unbounded) */
|
|
1278
|
+
stepsTotal?: number | null;
|
|
1279
|
+
}
|
|
1280
|
+
/** Checkpoint state for sequential pattern */
|
|
1281
|
+
interface SequentialCheckpointState extends PatternCheckpointBase {
|
|
1282
|
+
type: "sequential";
|
|
1283
|
+
/** Next agent index to run */
|
|
1284
|
+
step: number;
|
|
1285
|
+
/** Current input for the next agent */
|
|
1286
|
+
currentInput: string;
|
|
1287
|
+
/** Results collected so far (output + tokens) */
|
|
1288
|
+
results: Array<{
|
|
1289
|
+
agentId: string;
|
|
1290
|
+
output: unknown;
|
|
1291
|
+
totalTokens: number;
|
|
1292
|
+
}>;
|
|
1293
|
+
}
|
|
1294
|
+
/** Checkpoint state for supervisor pattern */
|
|
1295
|
+
interface SupervisorCheckpointState extends PatternCheckpointBase {
|
|
1296
|
+
type: "supervisor";
|
|
1297
|
+
/** Next round number */
|
|
1298
|
+
round: number;
|
|
1299
|
+
/** Last supervisor output */
|
|
1300
|
+
supervisorOutput: unknown;
|
|
1301
|
+
/** Worker results so far */
|
|
1302
|
+
workerResults: Array<{
|
|
1303
|
+
output: unknown;
|
|
1304
|
+
totalTokens: number;
|
|
1305
|
+
}>;
|
|
1306
|
+
/** Current input to supervisor */
|
|
1307
|
+
currentInput: string;
|
|
1308
|
+
}
|
|
1309
|
+
/** Checkpoint state for reflect pattern */
|
|
1310
|
+
interface ReflectCheckpointState extends PatternCheckpointBase {
|
|
1311
|
+
type: "reflect";
|
|
1312
|
+
/** Next iteration number */
|
|
1313
|
+
iteration: number;
|
|
1314
|
+
/** Current effective input */
|
|
1315
|
+
effectiveInput: string;
|
|
1316
|
+
/** Iteration history */
|
|
1317
|
+
history: Array<{
|
|
1318
|
+
iteration: number;
|
|
1319
|
+
passed: boolean;
|
|
1320
|
+
score?: number;
|
|
1321
|
+
feedback?: string;
|
|
1322
|
+
durationMs: number;
|
|
1323
|
+
producerTokens: number;
|
|
1324
|
+
evaluatorTokens: number;
|
|
1325
|
+
}>;
|
|
1326
|
+
/** Producer outputs so far */
|
|
1327
|
+
producerOutputs: Array<{
|
|
1328
|
+
output: unknown;
|
|
1329
|
+
score?: number;
|
|
1330
|
+
}>;
|
|
1331
|
+
/** Last producer output */
|
|
1332
|
+
lastProducerOutput: unknown | null;
|
|
1333
|
+
}
|
|
1334
|
+
/** Checkpoint state for debate pattern */
|
|
1335
|
+
interface DebateCheckpointState extends PatternCheckpointBase {
|
|
1336
|
+
type: "debate";
|
|
1337
|
+
/** Next round number */
|
|
1338
|
+
round: number;
|
|
1339
|
+
/** Current input for the round */
|
|
1340
|
+
currentInput: string;
|
|
1341
|
+
/** Completed rounds */
|
|
1342
|
+
rounds: Array<{
|
|
1343
|
+
proposals: Array<{
|
|
1344
|
+
agentId: string;
|
|
1345
|
+
output: unknown;
|
|
1346
|
+
}>;
|
|
1347
|
+
judgement: {
|
|
1348
|
+
winnerId: string;
|
|
1349
|
+
feedback?: string;
|
|
1350
|
+
score?: number;
|
|
1351
|
+
};
|
|
1352
|
+
}>;
|
|
1353
|
+
/** Last winning agent ID */
|
|
1354
|
+
lastWinnerId: string;
|
|
1355
|
+
/** Last winning output */
|
|
1356
|
+
lastWinnerOutput: unknown;
|
|
1357
|
+
/** Tokens consumed so far */
|
|
1358
|
+
tokensConsumed: number;
|
|
1359
|
+
}
|
|
1360
|
+
/** Checkpoint state for DAG pattern */
|
|
1361
|
+
interface DagCheckpointState extends PatternCheckpointBase {
|
|
1362
|
+
type: "dag";
|
|
1363
|
+
/** Per-node statuses */
|
|
1364
|
+
statuses: Record<string, DagNodeStatus>;
|
|
1365
|
+
/** Per-node outputs */
|
|
1366
|
+
outputs: Record<string, unknown>;
|
|
1367
|
+
/** Per-node errors */
|
|
1368
|
+
errors: Record<string, string>;
|
|
1369
|
+
/** Number of completed nodes */
|
|
1370
|
+
completedCount: number;
|
|
1371
|
+
/** Full results (output + tokens per node) */
|
|
1372
|
+
nodeResults: Record<string, {
|
|
1373
|
+
output: unknown;
|
|
1374
|
+
totalTokens: number;
|
|
1375
|
+
}>;
|
|
1376
|
+
/** Original input */
|
|
1377
|
+
input: string;
|
|
1378
|
+
}
|
|
1379
|
+
/** Serializable mid-goal state for save/resume */
|
|
1380
|
+
interface GoalCheckpointState extends PatternCheckpointBase {
|
|
1381
|
+
/** Pattern type discriminator */
|
|
1382
|
+
type: "goal";
|
|
1383
|
+
/** Current step */
|
|
1384
|
+
step: number;
|
|
1385
|
+
/** Current facts snapshot */
|
|
1386
|
+
facts: Record<string, unknown>;
|
|
1387
|
+
/** Completed node IDs */
|
|
1388
|
+
completedNodes: string[];
|
|
1389
|
+
/** Failed node IDs with consecutive failure counts */
|
|
1390
|
+
failedNodes: Record<string, number>;
|
|
1391
|
+
/** Node input hashes (for allowRerun detection) */
|
|
1392
|
+
nodeInputHashes: Record<string, string>;
|
|
1393
|
+
/** Per-node results (serialized — output only, not the full RunResult) */
|
|
1394
|
+
nodeOutputs: Record<string, {
|
|
1395
|
+
output: unknown;
|
|
1396
|
+
totalTokens: number;
|
|
1397
|
+
}>;
|
|
1398
|
+
/** Execution order so far */
|
|
1399
|
+
executionOrder: string[];
|
|
1400
|
+
/** Step metrics collected so far */
|
|
1401
|
+
stepMetrics: GoalStepMetrics[];
|
|
1402
|
+
/** Relaxations applied so far */
|
|
1403
|
+
relaxations: RelaxationRecord[];
|
|
1404
|
+
/** Applied relaxation tier index */
|
|
1405
|
+
appliedRelaxationTiers: number;
|
|
1406
|
+
/** Stall step counter */
|
|
1407
|
+
stallSteps: number;
|
|
1408
|
+
/** Last satisfaction value */
|
|
1409
|
+
lastSatisfaction: number;
|
|
1410
|
+
/** Per-agent metrics */
|
|
1411
|
+
agentMetrics: Record<string, {
|
|
1412
|
+
runs: number;
|
|
1413
|
+
totalDelta: number;
|
|
1414
|
+
tokens: number;
|
|
1415
|
+
}>;
|
|
1416
|
+
}
|
|
1417
|
+
/** Discriminated union of all pattern checkpoint states */
|
|
1418
|
+
type PatternCheckpointState = SequentialCheckpointState | SupervisorCheckpointState | ReflectCheckpointState | DebateCheckpointState | DagCheckpointState | GoalCheckpointState;
|
|
1419
|
+
/** Progress computed from a checkpoint state */
|
|
1420
|
+
interface CheckpointProgress {
|
|
1421
|
+
/** 0-100 percentage complete */
|
|
1422
|
+
percentage: number;
|
|
1423
|
+
/** Steps/rounds/iterations completed */
|
|
1424
|
+
stepsCompleted: number;
|
|
1425
|
+
/** Total expected steps (null for unbounded patterns) */
|
|
1426
|
+
stepsTotal: number | null;
|
|
1427
|
+
/** Tokens consumed so far */
|
|
1428
|
+
tokensConsumed: number;
|
|
1429
|
+
/** Estimated tokens remaining (null when unknowable) */
|
|
1430
|
+
estimatedTokensRemaining: number | null;
|
|
1431
|
+
/** Estimated steps remaining (null when unknowable) */
|
|
1432
|
+
estimatedStepsRemaining: number | null;
|
|
1433
|
+
}
|
|
1434
|
+
/** Diff between two checkpoint states */
|
|
1435
|
+
interface CheckpointDiff {
|
|
1436
|
+
/** Pattern type */
|
|
1437
|
+
patternType: string;
|
|
1438
|
+
/** Step/round/iteration difference */
|
|
1439
|
+
stepDelta: number;
|
|
1440
|
+
/** Token difference */
|
|
1441
|
+
tokensDelta: number;
|
|
1442
|
+
/** Fact changes (goal only) */
|
|
1443
|
+
facts?: {
|
|
1444
|
+
added: string[];
|
|
1445
|
+
removed: string[];
|
|
1446
|
+
changed: Array<{
|
|
1447
|
+
key: string;
|
|
1448
|
+
before: unknown;
|
|
1449
|
+
after: unknown;
|
|
1450
|
+
}>;
|
|
1451
|
+
};
|
|
1452
|
+
/** Nodes completed between checkpoints (DAG/goal) */
|
|
1453
|
+
nodesCompleted?: string[];
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
export { type DebateRoundEvent as $, type AgentLike as A, type BreakpointState as B, type Checkpoint as C, type DebugEvent as D, type CheckpointDiff as E, type CheckpointLocalState as F, type GuardrailFn as G, type CheckpointProgress as H, type InputGuardrailData as I, type CheckpointRestoreEvent as J, type CheckpointSaveEvent as K, type CheckpointStore as L, type Message as M, type ConstraintEvaluateEvent as N, type OutputGuardrailData as O, type CrossAgentDerivationFn as P, type CrossAgentSnapshot as Q, type RunOptions as R, type SchemaValidator as S, type ToolCallGuardrailData as T, type DagCheckpointState as U, type DagExecutionContext as V, type DagNode as W, type DagNodeStatus as X, type DagNodeUpdateEvent as Y, type DagPattern as Z, type DebateCheckpointState as _, type AdapterHooks as a, type TaskProgressEvent as a$, type DebugEventBase as a0, type DebugEventType as a1, type DerivationUpdateEvent as a2, type GoalCheckpointConfig as a3, type GoalCheckpointState as a4, type GoalMetrics as a5, type GoalNode as a6, type GoalPattern as a7, type GoalStepMetrics as a8, type GuardrailCheckEvent as a9, type PatternCompleteEvent as aA, type PatternStartEvent as aB, type RaceCancelledEvent as aC, type RaceStartEvent as aD, type RaceWinnerEvent as aE, type ReflectCheckpointState as aF, type ReflectionIterationEvent as aG, type RejectedRequest as aH, type RelaxationContext as aI, type RelaxationRecord as aJ, type RelaxationStrategy as aK, type RelaxationTier as aL, type RerouteDebugEvent as aM, type RerouteEvent as aN, type ResolverCompleteEvent as aO, type ResolverErrorEvent as aP, type ResolverStartEvent as aQ, type SchemaValidationResult as aR, type Scratchpad as aS, type ScratchpadUpdateEvent as aT, type SelfHealingConfig as aU, type SequentialCheckpointState as aV, type SingleAgentCheckpointLocalState as aW, type StreamingCallbackRunner as aX, type SupervisorCheckpointState as aY, type TaskCompleteEvent as aZ, type TaskErrorEvent as a_, type GuardrailContext as aa, GuardrailError as ab, type GuardrailErrorCode as ac, type GuardrailResult as ad, type GuardrailRetryConfig as ae, type GuardrailsConfig as af, type HandoffCompleteEvent as ag, type HandoffStartEvent as ah, type HealthMonitorConfig as ai, InMemoryCheckpointStore as aj, type InMemoryCheckpointStoreOptions as ak, MAX_BREAKPOINT_HISTORY as al, type MultiAgentBreakpointType as am, type MultiAgentCheckpointLocalState as an, type MultiAgentLifecycleHooks as ao, type MultiAgentSelfHealingConfig as ap, type NamedGuardrail as aq, type OrchestratorConstraint as ar, type OrchestratorDebugConfig as as, type OrchestratorLifecycleHooks as at, type OrchestratorResolver as au, type OrchestratorResolverContext as av, type OrchestratorState as aw, type PatternCheckpointBase as ax, type PatternCheckpointConfig as ay, type PatternCheckpointState as az, type AgentRunner as b, type TaskStartEvent as b0, type TokenUsage as b1, type ToolCall as b2, createBreakpointId as b3, createCheckpointId as b4, createInitialBreakpointState as b5, isGuardrailError as b6, matchBreakpoint as b7, validateCheckpoint as b8, type ApprovalState as c, type AgentState as d, type RunResult as e, type GoalResult as f, type AgentCircuitBreakerConfig as g, type AgentCompleteEvent as h, type AgentErrorEvent as i, type AgentHealthState as j, type AgentRetryConfig as k, type AgentRetryEvent as l, type AgentSelectionStrategy as m, type AgentStartEvent as n, type ApprovalRequest as o, type ApprovalRequestEvent as p, type ApprovalResponseEvent as q, type BreakpointConfig as r, type BreakpointContext as s, type BreakpointHitEvent as t, type BreakpointModifications as u, type BreakpointRequest as v, type BreakpointResumedEvent as w, type BreakpointState$1 as x, type BreakpointType as y, type CheckpointContext as z };
|