@defai.digital/agent-domain 13.0.3
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 +214 -0
- package/dist/enhanced-executor.d.ts +170 -0
- package/dist/enhanced-executor.d.ts.map +1 -0
- package/dist/enhanced-executor.js +1072 -0
- package/dist/enhanced-executor.js.map +1 -0
- package/dist/executor.d.ts +120 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +929 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +50 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +160 -0
- package/dist/loader.js.map +1 -0
- package/dist/persistent-registry.d.ts +105 -0
- package/dist/persistent-registry.d.ts.map +1 -0
- package/dist/persistent-registry.js +183 -0
- package/dist/persistent-registry.js.map +1 -0
- package/dist/production-factories.d.ts +70 -0
- package/dist/production-factories.d.ts.map +1 -0
- package/dist/production-factories.js +434 -0
- package/dist/production-factories.js.map +1 -0
- package/dist/prompt-executor.d.ts +119 -0
- package/dist/prompt-executor.d.ts.map +1 -0
- package/dist/prompt-executor.js +211 -0
- package/dist/prompt-executor.js.map +1 -0
- package/dist/registry.d.ts +57 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +123 -0
- package/dist/registry.js.map +1 -0
- package/dist/selection-service.d.ts +74 -0
- package/dist/selection-service.d.ts.map +1 -0
- package/dist/selection-service.js +322 -0
- package/dist/selection-service.js.map +1 -0
- package/dist/selector.d.ts +51 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +249 -0
- package/dist/selector.js.map +1 -0
- package/dist/stub-checkpoint.d.ts +23 -0
- package/dist/stub-checkpoint.d.ts.map +1 -0
- package/dist/stub-checkpoint.js +137 -0
- package/dist/stub-checkpoint.js.map +1 -0
- package/dist/stub-delegation-tracker.d.ts +25 -0
- package/dist/stub-delegation-tracker.d.ts.map +1 -0
- package/dist/stub-delegation-tracker.js +118 -0
- package/dist/stub-delegation-tracker.js.map +1 -0
- package/dist/stub-parallel-executor.d.ts +19 -0
- package/dist/stub-parallel-executor.d.ts.map +1 -0
- package/dist/stub-parallel-executor.js +176 -0
- package/dist/stub-parallel-executor.js.map +1 -0
- package/dist/types.d.ts +614 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/workflow-templates.d.ts +117 -0
- package/dist/workflow-templates.d.ts.map +1 -0
- package/dist/workflow-templates.js +342 -0
- package/dist/workflow-templates.js.map +1 -0
- package/package.json +51 -0
- package/src/enhanced-executor.ts +1395 -0
- package/src/executor.ts +1153 -0
- package/src/index.ts +172 -0
- package/src/loader.ts +191 -0
- package/src/persistent-registry.ts +235 -0
- package/src/production-factories.ts +613 -0
- package/src/prompt-executor.ts +310 -0
- package/src/registry.ts +167 -0
- package/src/selection-service.ts +411 -0
- package/src/selector.ts +299 -0
- package/src/stub-checkpoint.ts +187 -0
- package/src/stub-delegation-tracker.ts +161 -0
- package/src/stub-parallel-executor.ts +224 -0
- package/src/types.ts +784 -0
- package/src/workflow-templates.ts +393 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Domain Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type AgentProfile,
|
|
7
|
+
type AgentResult,
|
|
8
|
+
type AgentRunOptions,
|
|
9
|
+
type AgentError,
|
|
10
|
+
type AgentEvent,
|
|
11
|
+
type AgentWorkflowStep,
|
|
12
|
+
type ToolExecutionResult,
|
|
13
|
+
type DelegationContext,
|
|
14
|
+
type DelegationCheckResult,
|
|
15
|
+
type DelegationResult,
|
|
16
|
+
type DelegationRequest as ContractDelegationRequest,
|
|
17
|
+
TIMEOUT_PROVIDER_DEFAULT,
|
|
18
|
+
LIMIT_EVENT_BUFFER,
|
|
19
|
+
PROVIDER_DEFAULT,
|
|
20
|
+
LIMIT_DELEGATION_DEPTH,
|
|
21
|
+
} from '@defai.digital/contracts';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Agent registry interface
|
|
25
|
+
*/
|
|
26
|
+
export interface AgentRegistry {
|
|
27
|
+
/**
|
|
28
|
+
* Register a new agent profile
|
|
29
|
+
*/
|
|
30
|
+
register(profile: AgentProfile): Promise<void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get an agent by ID
|
|
34
|
+
*/
|
|
35
|
+
get(agentId: string): Promise<AgentProfile | undefined>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* List all registered agents
|
|
39
|
+
*/
|
|
40
|
+
list(filter?: AgentFilter): Promise<AgentProfile[]>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Update an agent profile
|
|
44
|
+
*/
|
|
45
|
+
update(agentId: string, updates: Partial<AgentProfile>): Promise<void>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Remove an agent
|
|
49
|
+
*/
|
|
50
|
+
remove(agentId: string): Promise<void>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if an agent exists
|
|
54
|
+
*/
|
|
55
|
+
exists(agentId: string): Promise<boolean>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Filter options for listing agents
|
|
60
|
+
*/
|
|
61
|
+
export interface AgentFilter {
|
|
62
|
+
team?: string;
|
|
63
|
+
tags?: string[];
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
capability?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Agent executor interface
|
|
70
|
+
*/
|
|
71
|
+
export interface AgentExecutor {
|
|
72
|
+
/**
|
|
73
|
+
* Execute an agent with the given input
|
|
74
|
+
*/
|
|
75
|
+
execute(
|
|
76
|
+
agentId: string,
|
|
77
|
+
input: unknown,
|
|
78
|
+
options?: AgentRunOptions
|
|
79
|
+
): Promise<AgentResult>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Cancel a running agent execution
|
|
83
|
+
*/
|
|
84
|
+
cancel(executionId: string): Promise<void>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get execution status
|
|
88
|
+
*/
|
|
89
|
+
getStatus(executionId: string): Promise<ExecutionStatus | undefined>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Execution status
|
|
94
|
+
*/
|
|
95
|
+
export interface ExecutionStatus {
|
|
96
|
+
executionId: string;
|
|
97
|
+
agentId: string;
|
|
98
|
+
status: 'running' | 'completed' | 'failed' | 'cancelled';
|
|
99
|
+
currentStep: string | undefined;
|
|
100
|
+
startedAt: string;
|
|
101
|
+
completedAt: string | undefined;
|
|
102
|
+
progress: ExecutionProgress | undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Execution progress
|
|
107
|
+
*/
|
|
108
|
+
export interface ExecutionProgress {
|
|
109
|
+
totalSteps: number;
|
|
110
|
+
completedSteps: number;
|
|
111
|
+
currentStepName: string | undefined;
|
|
112
|
+
percentComplete: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Delegation request
|
|
117
|
+
*/
|
|
118
|
+
export interface DelegationRequest {
|
|
119
|
+
fromAgent: string;
|
|
120
|
+
toAgent: string;
|
|
121
|
+
task: string;
|
|
122
|
+
input: unknown;
|
|
123
|
+
timeout?: number;
|
|
124
|
+
context?: Record<string, unknown>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Delegation tracker interface - port for tracking delegation chains
|
|
129
|
+
*
|
|
130
|
+
* Implementations provided via DelegationTrackerFactory in AgentDomainConfig.
|
|
131
|
+
* This allows the agent-domain to remain independent of execution implementations.
|
|
132
|
+
*
|
|
133
|
+
* Invariants:
|
|
134
|
+
* - INV-DT-001: Depth never exceeds maxDepth
|
|
135
|
+
* - INV-DT-002: No circular delegations allowed
|
|
136
|
+
*/
|
|
137
|
+
export interface DelegationTrackerPort {
|
|
138
|
+
/** Get current delegation context */
|
|
139
|
+
getContext(): DelegationContext;
|
|
140
|
+
|
|
141
|
+
/** Check if delegation to target agent is allowed */
|
|
142
|
+
canDelegate(toAgentId: string): DelegationCheckResult;
|
|
143
|
+
|
|
144
|
+
/** Create delegation request */
|
|
145
|
+
createDelegationRequest(
|
|
146
|
+
toAgentId: string,
|
|
147
|
+
task: string,
|
|
148
|
+
input?: unknown,
|
|
149
|
+
timeout?: number
|
|
150
|
+
): ContractDelegationRequest | null;
|
|
151
|
+
|
|
152
|
+
/** Create child context for delegated agent */
|
|
153
|
+
createChildContext(toAgentId: string): DelegationContext;
|
|
154
|
+
|
|
155
|
+
/** Record delegation result */
|
|
156
|
+
recordResult(result: DelegationResult): void;
|
|
157
|
+
|
|
158
|
+
/** Get delegation history */
|
|
159
|
+
getHistory(): DelegationResult[];
|
|
160
|
+
|
|
161
|
+
/** Check if we're at the root of delegation chain */
|
|
162
|
+
isRoot(): boolean;
|
|
163
|
+
|
|
164
|
+
/** Get remaining delegation depth */
|
|
165
|
+
getRemainingDepth(): number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Factory function type for creating delegation trackers
|
|
170
|
+
* Injected via AgentDomainConfig for dependency inversion
|
|
171
|
+
*/
|
|
172
|
+
export type DelegationTrackerFactory = (
|
|
173
|
+
agentId: string,
|
|
174
|
+
parentContext: DelegationContext | undefined,
|
|
175
|
+
maxDepth: number
|
|
176
|
+
) => DelegationTrackerPort;
|
|
177
|
+
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// Checkpoint Types (Port Interfaces)
|
|
180
|
+
// ============================================================================
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Checkpoint storage port interface
|
|
184
|
+
*
|
|
185
|
+
* Implementations provided via CheckpointStorageFactory in config.
|
|
186
|
+
* INV-CP-001: Checkpoints contain all data needed to resume
|
|
187
|
+
*/
|
|
188
|
+
export interface CheckpointStoragePort {
|
|
189
|
+
/** Save a checkpoint */
|
|
190
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
191
|
+
|
|
192
|
+
/** Load a checkpoint by ID */
|
|
193
|
+
load(checkpointId: string): Promise<Checkpoint | null>;
|
|
194
|
+
|
|
195
|
+
/** Load latest checkpoint for an agent */
|
|
196
|
+
loadLatest(agentId: string, sessionId?: string): Promise<Checkpoint | null>;
|
|
197
|
+
|
|
198
|
+
/** List checkpoints for an agent */
|
|
199
|
+
list(agentId: string, sessionId?: string): Promise<Checkpoint[]>;
|
|
200
|
+
|
|
201
|
+
/** Delete a checkpoint */
|
|
202
|
+
delete(checkpointId: string): Promise<boolean>;
|
|
203
|
+
|
|
204
|
+
/** Delete expired checkpoints */
|
|
205
|
+
deleteExpired(): Promise<number>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Checkpoint data structure
|
|
210
|
+
*/
|
|
211
|
+
export interface Checkpoint {
|
|
212
|
+
checkpointId: string;
|
|
213
|
+
agentId: string;
|
|
214
|
+
sessionId?: string | undefined;
|
|
215
|
+
stepIndex: number;
|
|
216
|
+
stepId: string;
|
|
217
|
+
previousOutputs: Record<string, unknown>;
|
|
218
|
+
metadata?: Record<string, unknown> | undefined;
|
|
219
|
+
createdAt: string;
|
|
220
|
+
expiresAt?: string | undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Checkpoint manager port interface
|
|
225
|
+
*
|
|
226
|
+
* Manages checkpoints for a specific agent execution.
|
|
227
|
+
* INV-CP-002: Resume starts from step after checkpoint
|
|
228
|
+
*/
|
|
229
|
+
export interface CheckpointManagerPort {
|
|
230
|
+
/** Get configuration */
|
|
231
|
+
getConfig(): import('@defai.digital/contracts').CheckpointConfig;
|
|
232
|
+
|
|
233
|
+
/** Check if should create checkpoint at step index */
|
|
234
|
+
shouldCheckpoint(stepIndex: number): boolean;
|
|
235
|
+
|
|
236
|
+
/** Create a checkpoint */
|
|
237
|
+
createCheckpoint(
|
|
238
|
+
stepIndex: number,
|
|
239
|
+
stepId: string,
|
|
240
|
+
previousOutputs: Record<string, unknown>,
|
|
241
|
+
metadata?: Record<string, unknown>
|
|
242
|
+
): Promise<Checkpoint>;
|
|
243
|
+
|
|
244
|
+
/** Get latest checkpoint */
|
|
245
|
+
getLatestCheckpoint(): Promise<Checkpoint | null>;
|
|
246
|
+
|
|
247
|
+
/** Get resume context from checkpoint */
|
|
248
|
+
getResumeContext(checkpointId: string): Promise<{
|
|
249
|
+
startFromStep: number;
|
|
250
|
+
previousOutputs: Record<string, unknown>;
|
|
251
|
+
} | null>;
|
|
252
|
+
|
|
253
|
+
/** Clean up expired checkpoints */
|
|
254
|
+
cleanup(): Promise<number>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Factory for creating checkpoint storage
|
|
259
|
+
*/
|
|
260
|
+
export type CheckpointStorageFactory = () => CheckpointStoragePort;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Factory for creating checkpoint managers
|
|
264
|
+
*/
|
|
265
|
+
export type CheckpointManagerFactory = (
|
|
266
|
+
agentId: string,
|
|
267
|
+
sessionId: string | undefined,
|
|
268
|
+
storage: CheckpointStoragePort,
|
|
269
|
+
config: import('@defai.digital/contracts').CheckpointConfig
|
|
270
|
+
) => CheckpointManagerPort;
|
|
271
|
+
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// Parallel Execution Types (Port Interfaces)
|
|
274
|
+
// ============================================================================
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Step executor function for parallel execution
|
|
278
|
+
*/
|
|
279
|
+
export type ParallelStepExecutor = (
|
|
280
|
+
step: AgentWorkflowStep,
|
|
281
|
+
previousOutputs: Record<string, unknown>
|
|
282
|
+
) => Promise<unknown>;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Result from parallel step execution
|
|
286
|
+
*/
|
|
287
|
+
export interface ParallelStepResult {
|
|
288
|
+
stepId: string;
|
|
289
|
+
success: boolean;
|
|
290
|
+
output?: unknown;
|
|
291
|
+
error?: string;
|
|
292
|
+
durationMs: number;
|
|
293
|
+
cancelled?: boolean;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Result from parallel group execution
|
|
298
|
+
*/
|
|
299
|
+
export interface ParallelGroupResult {
|
|
300
|
+
stepResults: ParallelStepResult[];
|
|
301
|
+
totalDurationMs: number;
|
|
302
|
+
allSucceeded: boolean;
|
|
303
|
+
failedCount: number;
|
|
304
|
+
cancelledCount: number;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Parallel executor port interface
|
|
309
|
+
*
|
|
310
|
+
* Executes workflow steps in parallel while respecting dependencies.
|
|
311
|
+
* INV-PE-001: Independent steps execute concurrently
|
|
312
|
+
* INV-PE-002: Dependencies honored (DAG ordering)
|
|
313
|
+
* INV-PE-003: Concurrency limit respected
|
|
314
|
+
*/
|
|
315
|
+
export interface ParallelExecutorPort {
|
|
316
|
+
/** Get configuration */
|
|
317
|
+
getConfig(): import('@defai.digital/contracts').ParallelExecutionConfig;
|
|
318
|
+
|
|
319
|
+
/** Execute a group of steps in parallel */
|
|
320
|
+
executeGroup(
|
|
321
|
+
steps: AgentWorkflowStep[],
|
|
322
|
+
executor: ParallelStepExecutor,
|
|
323
|
+
previousOutputs?: Record<string, unknown>
|
|
324
|
+
): Promise<ParallelGroupResult>;
|
|
325
|
+
|
|
326
|
+
/** Build execution layers from steps (DAG analysis) */
|
|
327
|
+
buildExecutionLayers(steps: AgentWorkflowStep[]): AgentWorkflowStep[][];
|
|
328
|
+
|
|
329
|
+
/** Cancel ongoing execution */
|
|
330
|
+
cancel(): void;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Factory for creating parallel executors
|
|
335
|
+
*/
|
|
336
|
+
export type ParallelExecutorFactory = (
|
|
337
|
+
config: Partial<import('@defai.digital/contracts').ParallelExecutionConfig>
|
|
338
|
+
) => ParallelExecutorPort;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Delegation manager interface
|
|
342
|
+
*/
|
|
343
|
+
export interface DelegationManager {
|
|
344
|
+
/**
|
|
345
|
+
* Delegate a task to another agent
|
|
346
|
+
*/
|
|
347
|
+
delegate(request: DelegationRequest): Promise<DelegationResult>;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Check if delegation is allowed
|
|
351
|
+
*/
|
|
352
|
+
canDelegate(fromAgent: string, toAgent: string, depth: number): boolean;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get current delegation depth
|
|
356
|
+
*/
|
|
357
|
+
getDepth(executionId: string): number;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Event handler for agent events
|
|
362
|
+
*/
|
|
363
|
+
export type AgentEventHandler = (event: AgentEvent) => void | Promise<void>;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Agent event emitter interface
|
|
367
|
+
*/
|
|
368
|
+
export interface AgentEventEmitter {
|
|
369
|
+
/**
|
|
370
|
+
* Subscribe to agent events
|
|
371
|
+
*/
|
|
372
|
+
on(type: AgentEvent['type'] | '*', handler: AgentEventHandler): void;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Unsubscribe from agent events
|
|
376
|
+
*/
|
|
377
|
+
off(type: AgentEvent['type'] | '*', handler: AgentEventHandler): void;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Emit an agent event
|
|
381
|
+
*/
|
|
382
|
+
emit(event: AgentEvent): void;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Step executor function type
|
|
387
|
+
*/
|
|
388
|
+
export type StepExecutorFn = (
|
|
389
|
+
step: AgentWorkflowStep,
|
|
390
|
+
context: StepExecutionContext
|
|
391
|
+
) => Promise<StepExecutionResult>;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Step execution context
|
|
395
|
+
*/
|
|
396
|
+
export interface StepExecutionContext {
|
|
397
|
+
agentId: string;
|
|
398
|
+
executionId: string;
|
|
399
|
+
sessionId: string | undefined;
|
|
400
|
+
input: unknown;
|
|
401
|
+
previousOutputs: Record<string, unknown>;
|
|
402
|
+
memory: unknown[] | undefined;
|
|
403
|
+
provider: string | undefined;
|
|
404
|
+
model: string | undefined;
|
|
405
|
+
/**
|
|
406
|
+
* Delegation context for tracking delegation depth and chain
|
|
407
|
+
* INV-DT-001: Used to enforce max delegation depth
|
|
408
|
+
* INV-DT-002: Used to prevent circular delegations
|
|
409
|
+
*/
|
|
410
|
+
delegationContext: import('@defai.digital/contracts').DelegationContext | undefined;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Step execution result
|
|
415
|
+
*/
|
|
416
|
+
export interface StepExecutionResult {
|
|
417
|
+
success: boolean;
|
|
418
|
+
output?: unknown;
|
|
419
|
+
error: AgentError | undefined;
|
|
420
|
+
durationMs: number;
|
|
421
|
+
retryCount: number;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Prompt execution request
|
|
426
|
+
*/
|
|
427
|
+
export interface PromptExecutionRequest {
|
|
428
|
+
/**
|
|
429
|
+
* The prompt text to send to the LLM
|
|
430
|
+
*/
|
|
431
|
+
prompt: string;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* System prompt (agent instructions)
|
|
435
|
+
*/
|
|
436
|
+
systemPrompt?: string | undefined;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Provider to use (e.g., 'claude', 'gemini')
|
|
440
|
+
*/
|
|
441
|
+
provider?: string | undefined;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Model to use (if not specified, provider default is used)
|
|
445
|
+
*/
|
|
446
|
+
model?: string | undefined;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Maximum tokens to generate
|
|
450
|
+
*/
|
|
451
|
+
maxTokens?: number | undefined;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Temperature for sampling (0-2)
|
|
455
|
+
*/
|
|
456
|
+
temperature?: number | undefined;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Request timeout in milliseconds
|
|
460
|
+
*/
|
|
461
|
+
timeout?: number | undefined;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Prompt execution response
|
|
466
|
+
*/
|
|
467
|
+
export interface PromptExecutionResponse {
|
|
468
|
+
/**
|
|
469
|
+
* Whether execution succeeded
|
|
470
|
+
*/
|
|
471
|
+
success: boolean;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Generated content (on success)
|
|
475
|
+
*/
|
|
476
|
+
content?: string | undefined;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Error message (on failure)
|
|
480
|
+
*/
|
|
481
|
+
error?: string | undefined;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Error code (on failure)
|
|
485
|
+
*/
|
|
486
|
+
errorCode?: string | undefined;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Provider used
|
|
490
|
+
*/
|
|
491
|
+
provider?: string | undefined;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Model used
|
|
495
|
+
*/
|
|
496
|
+
model?: string | undefined;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Execution latency in milliseconds
|
|
500
|
+
*/
|
|
501
|
+
latencyMs: number;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Token usage (if available)
|
|
505
|
+
*/
|
|
506
|
+
usage?: {
|
|
507
|
+
inputTokens: number;
|
|
508
|
+
outputTokens: number;
|
|
509
|
+
totalTokens: number;
|
|
510
|
+
} | undefined;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Interface for executing prompts via LLM providers
|
|
515
|
+
* This abstraction allows the agent domain to remain independent of provider implementations
|
|
516
|
+
*/
|
|
517
|
+
export interface PromptExecutor {
|
|
518
|
+
/**
|
|
519
|
+
* Execute a prompt and return the response
|
|
520
|
+
*/
|
|
521
|
+
execute(request: PromptExecutionRequest): Promise<PromptExecutionResponse>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Check if a provider is available
|
|
525
|
+
*/
|
|
526
|
+
isProviderAvailable(providerId: string): Promise<boolean>;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Get list of available providers
|
|
530
|
+
*/
|
|
531
|
+
getAvailableProviders(): Promise<string[]>;
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Get the default provider ID
|
|
535
|
+
*/
|
|
536
|
+
getDefaultProvider(): string;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Prompt step configuration
|
|
541
|
+
*/
|
|
542
|
+
export interface PromptStepConfig {
|
|
543
|
+
/**
|
|
544
|
+
* The prompt template (supports ${variable} substitution)
|
|
545
|
+
*/
|
|
546
|
+
prompt?: string | undefined;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* System prompt override (defaults to agent.systemPrompt)
|
|
550
|
+
*/
|
|
551
|
+
systemPrompt?: string | undefined;
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Provider to use
|
|
555
|
+
*/
|
|
556
|
+
provider?: string | undefined;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Model to use
|
|
560
|
+
*/
|
|
561
|
+
model?: string | undefined;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Maximum tokens to generate
|
|
565
|
+
*/
|
|
566
|
+
maxTokens?: number | undefined;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Temperature for sampling
|
|
570
|
+
*/
|
|
571
|
+
temperature?: number | undefined;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Timeout for this step
|
|
575
|
+
*/
|
|
576
|
+
timeout?: number | undefined;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Tool executor interface
|
|
581
|
+
*
|
|
582
|
+
* Bridges agent/workflow execution to MCP tools.
|
|
583
|
+
* Allows tool steps to execute real tools without direct dependency on mcp-server.
|
|
584
|
+
*
|
|
585
|
+
* Invariants:
|
|
586
|
+
* - INV-TOOL-001: Tool execution must validate inputs before execution
|
|
587
|
+
* - INV-TOOL-002: Tool results must be immutable (frozen) after creation
|
|
588
|
+
* - INV-TOOL-003: Unknown tools must return error, not throw
|
|
589
|
+
*/
|
|
590
|
+
export interface ToolExecutor {
|
|
591
|
+
/**
|
|
592
|
+
* Execute a tool by name with the given arguments
|
|
593
|
+
*/
|
|
594
|
+
execute(toolName: string, args: Record<string, unknown>): Promise<ToolExecutionResult>;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Check if a tool is available
|
|
598
|
+
*/
|
|
599
|
+
isToolAvailable(toolName: string): boolean;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Get list of available tool names
|
|
603
|
+
*/
|
|
604
|
+
getAvailableTools(): string[];
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Ability manager interface (from ability-domain)
|
|
609
|
+
* Used to inject abilities into agent prompts
|
|
610
|
+
*/
|
|
611
|
+
export interface AbilityManagerLike {
|
|
612
|
+
/**
|
|
613
|
+
* Inject abilities into agent context
|
|
614
|
+
*/
|
|
615
|
+
injectAbilities(
|
|
616
|
+
agentId: string,
|
|
617
|
+
task: string,
|
|
618
|
+
coreAbilities?: string[],
|
|
619
|
+
options?: { maxAbilities?: number; maxTokens?: number; includeMetadata?: boolean }
|
|
620
|
+
): Promise<{
|
|
621
|
+
agentId: string;
|
|
622
|
+
injectedAbilities: string[];
|
|
623
|
+
combinedContent: string;
|
|
624
|
+
tokenCount?: number | undefined;
|
|
625
|
+
truncated: boolean;
|
|
626
|
+
}>;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Agent domain configuration
|
|
631
|
+
*/
|
|
632
|
+
export interface AgentDomainConfig {
|
|
633
|
+
maxDelegationDepth: number;
|
|
634
|
+
defaultTimeout: number;
|
|
635
|
+
enableCheckpoints: boolean;
|
|
636
|
+
eventBufferSize: number;
|
|
637
|
+
/**
|
|
638
|
+
* Default provider for prompt execution
|
|
639
|
+
*/
|
|
640
|
+
defaultProvider?: string | undefined;
|
|
641
|
+
/**
|
|
642
|
+
* Prompt executor for real LLM calls (if not provided, uses stub executor)
|
|
643
|
+
* NOTE: In production mode (NODE_ENV=production or AX_MODE=production),
|
|
644
|
+
* a real executor must be provided or an error will be thrown.
|
|
645
|
+
*/
|
|
646
|
+
promptExecutor?: PromptExecutor | undefined;
|
|
647
|
+
/**
|
|
648
|
+
* Tool executor for executing MCP tools from workflow/agent steps.
|
|
649
|
+
* If not provided, tool steps will return placeholder results.
|
|
650
|
+
* NOTE: In production mode, a real executor should be provided.
|
|
651
|
+
*
|
|
652
|
+
* Invariants:
|
|
653
|
+
* - INV-TOOL-001: Tool execution validates inputs
|
|
654
|
+
* - INV-TOOL-002: Tool results are immutable
|
|
655
|
+
* - INV-TOOL-003: Unknown tools return errors gracefully
|
|
656
|
+
*/
|
|
657
|
+
toolExecutor?: ToolExecutor | undefined;
|
|
658
|
+
/**
|
|
659
|
+
* Ability manager for injecting abilities into prompts (optional)
|
|
660
|
+
* INV-AGT-ABL-001: When provided, abilities are injected before prompt execution
|
|
661
|
+
*/
|
|
662
|
+
abilityManager?: AbilityManagerLike | undefined;
|
|
663
|
+
/**
|
|
664
|
+
* Enable ability injection for prompt steps (default: true if abilityManager is provided)
|
|
665
|
+
*/
|
|
666
|
+
enableAbilityInjection?: boolean | undefined;
|
|
667
|
+
/**
|
|
668
|
+
* Maximum tokens for ability injection (default: 10000)
|
|
669
|
+
*/
|
|
670
|
+
maxAbilityTokens?: number | undefined;
|
|
671
|
+
/**
|
|
672
|
+
* Factory for creating delegation trackers (dependency injection)
|
|
673
|
+
* If not provided, uses a stub implementation that logs warnings.
|
|
674
|
+
*
|
|
675
|
+
* Invariants:
|
|
676
|
+
* - INV-DT-001: Depth never exceeds maxDepth
|
|
677
|
+
* - INV-DT-002: No circular delegations allowed
|
|
678
|
+
*/
|
|
679
|
+
delegationTrackerFactory?: DelegationTrackerFactory | undefined;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Default agent domain configuration
|
|
684
|
+
*/
|
|
685
|
+
export const DEFAULT_AGENT_DOMAIN_CONFIG: AgentDomainConfig = {
|
|
686
|
+
maxDelegationDepth: LIMIT_DELEGATION_DEPTH,
|
|
687
|
+
defaultTimeout: TIMEOUT_PROVIDER_DEFAULT,
|
|
688
|
+
enableCheckpoints: true,
|
|
689
|
+
eventBufferSize: LIMIT_EVENT_BUFFER,
|
|
690
|
+
defaultProvider: PROVIDER_DEFAULT,
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// ============================================================================
|
|
694
|
+
// Agent Loader Types
|
|
695
|
+
// ============================================================================
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Agent loader interface - loads agent profiles from various sources
|
|
699
|
+
*/
|
|
700
|
+
export interface AgentLoader {
|
|
701
|
+
/**
|
|
702
|
+
* Load an agent profile by ID
|
|
703
|
+
*/
|
|
704
|
+
load(agentId: string): Promise<AgentProfile | undefined>;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Load all agent profiles from the source
|
|
708
|
+
*/
|
|
709
|
+
loadAll(): Promise<AgentProfile[]>;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Check if an agent exists in the source
|
|
713
|
+
*/
|
|
714
|
+
exists(agentId: string): Promise<boolean>;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Reload agent profiles from source
|
|
718
|
+
*/
|
|
719
|
+
reload(): Promise<void>;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Agent loader configuration
|
|
724
|
+
*/
|
|
725
|
+
export interface AgentLoaderConfig {
|
|
726
|
+
/** Directory path to load agents from */
|
|
727
|
+
agentsDir: string;
|
|
728
|
+
/** File extensions to load (default: ['.yaml', '.yml', '.json']) */
|
|
729
|
+
extensions?: string[];
|
|
730
|
+
/** Watch for file changes */
|
|
731
|
+
watch?: boolean;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// ============================================================================
|
|
735
|
+
// Agent Selector Types
|
|
736
|
+
// ============================================================================
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Agent selection result
|
|
740
|
+
*/
|
|
741
|
+
export interface AgentSelectionResult {
|
|
742
|
+
/** Selected agent ID */
|
|
743
|
+
agentId: string;
|
|
744
|
+
/** Confidence score (0-1) */
|
|
745
|
+
confidence: number;
|
|
746
|
+
/** Reason for selection */
|
|
747
|
+
reason: string;
|
|
748
|
+
/** Alternative agents considered */
|
|
749
|
+
alternatives: {
|
|
750
|
+
agentId: string;
|
|
751
|
+
confidence: number;
|
|
752
|
+
}[];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Agent selector interface - selects the best agent for a task
|
|
757
|
+
*/
|
|
758
|
+
export interface AgentSelector {
|
|
759
|
+
/**
|
|
760
|
+
* Select the best agent for a task
|
|
761
|
+
*/
|
|
762
|
+
select(task: string, context?: AgentSelectionContext): Promise<AgentSelectionResult>;
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Get all agents that match a task
|
|
766
|
+
*/
|
|
767
|
+
match(task: string, context?: AgentSelectionContext): Promise<AgentSelectionResult[]>;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Context for agent selection
|
|
772
|
+
*/
|
|
773
|
+
export interface AgentSelectionContext {
|
|
774
|
+
/** Current team (if any) */
|
|
775
|
+
team?: string;
|
|
776
|
+
/** Required capabilities */
|
|
777
|
+
requiredCapabilities?: string[];
|
|
778
|
+
/** Excluded agents */
|
|
779
|
+
excludeAgents?: string[];
|
|
780
|
+
/** Preferred provider */
|
|
781
|
+
preferredProvider?: string;
|
|
782
|
+
/** Maximum delegation depth */
|
|
783
|
+
maxDelegationDepth?: number;
|
|
784
|
+
}
|