@memgrafter/flatagents 0.8.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 +221 -0
- package/dist/index.d.mts +673 -0
- package/dist/index.d.ts +673 -0
- package/dist/index.js +1700 -0
- package/dist/index.mjs +1642 -0
- package/package.json +46 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model configuration for an agent.
|
|
3
|
+
* Can be inline config, profile reference, or profile with overrides.
|
|
4
|
+
*/
|
|
5
|
+
interface ModelConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
provider?: string;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
max_tokens?: number;
|
|
10
|
+
top_p?: number;
|
|
11
|
+
top_k?: number;
|
|
12
|
+
frequency_penalty?: number;
|
|
13
|
+
presence_penalty?: number;
|
|
14
|
+
seed?: number;
|
|
15
|
+
base_url?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Model config that references a profile with optional overrides.
|
|
19
|
+
*/
|
|
20
|
+
interface ProfiledModelConfig extends Partial<ModelConfig> {
|
|
21
|
+
profile: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Model profile configuration (used in profiles.yml).
|
|
25
|
+
*/
|
|
26
|
+
interface ModelProfileConfig {
|
|
27
|
+
name: string;
|
|
28
|
+
provider?: string;
|
|
29
|
+
temperature?: number;
|
|
30
|
+
max_tokens?: number;
|
|
31
|
+
top_p?: number;
|
|
32
|
+
top_k?: number;
|
|
33
|
+
frequency_penalty?: number;
|
|
34
|
+
presence_penalty?: number;
|
|
35
|
+
seed?: number;
|
|
36
|
+
base_url?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Profiles configuration (profiles.yml structure).
|
|
40
|
+
*/
|
|
41
|
+
interface ProfilesConfig {
|
|
42
|
+
spec: "flatprofiles";
|
|
43
|
+
spec_version: string;
|
|
44
|
+
data: {
|
|
45
|
+
model_profiles: Record<string, ModelProfileConfig>;
|
|
46
|
+
default?: string;
|
|
47
|
+
override?: string;
|
|
48
|
+
};
|
|
49
|
+
metadata?: Record<string, any>;
|
|
50
|
+
}
|
|
51
|
+
interface AgentConfig {
|
|
52
|
+
spec: "flatagent";
|
|
53
|
+
spec_version: string;
|
|
54
|
+
data: {
|
|
55
|
+
name?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Model configuration.
|
|
58
|
+
* - String: Profile name lookup (e.g., "fast-cheap")
|
|
59
|
+
* - ModelConfig: Inline config with name, provider, etc.
|
|
60
|
+
* - ProfiledModelConfig: Profile reference with optional overrides
|
|
61
|
+
*/
|
|
62
|
+
model: string | ModelConfig | ProfiledModelConfig;
|
|
63
|
+
system: string;
|
|
64
|
+
user: string;
|
|
65
|
+
instruction_suffix?: string;
|
|
66
|
+
output?: Record<string, {
|
|
67
|
+
type: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
enum?: string[];
|
|
70
|
+
required?: boolean;
|
|
71
|
+
items?: any;
|
|
72
|
+
properties?: any;
|
|
73
|
+
}>;
|
|
74
|
+
mcp?: {
|
|
75
|
+
servers: Record<string, MCPServer>;
|
|
76
|
+
tool_filter?: ToolFilter;
|
|
77
|
+
tool_prompt?: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
interface MachineConfig {
|
|
82
|
+
spec: "flatmachine";
|
|
83
|
+
spec_version: string;
|
|
84
|
+
data: {
|
|
85
|
+
name?: string;
|
|
86
|
+
expression_engine?: "simple" | "cel";
|
|
87
|
+
context?: Record<string, any>;
|
|
88
|
+
agents?: Record<string, string>;
|
|
89
|
+
machines?: Record<string, string | MachineConfig | MachineWrapper | MachineReference>;
|
|
90
|
+
states: Record<string, State>;
|
|
91
|
+
settings?: {
|
|
92
|
+
max_steps?: number;
|
|
93
|
+
backends?: BackendConfig;
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
};
|
|
96
|
+
persistence?: {
|
|
97
|
+
enabled: boolean;
|
|
98
|
+
backend: "local" | "memory" | "redis" | string;
|
|
99
|
+
checkpoint_on?: string[];
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
interface State {
|
|
105
|
+
type?: "initial" | "final";
|
|
106
|
+
agent?: string;
|
|
107
|
+
machine?: string | string[] | MachineInput[];
|
|
108
|
+
action?: string;
|
|
109
|
+
execution?: {
|
|
110
|
+
type: "default" | "retry" | "parallel" | "mdap_voting";
|
|
111
|
+
backoffs?: number[];
|
|
112
|
+
jitter?: number;
|
|
113
|
+
n_samples?: number;
|
|
114
|
+
k_margin?: number;
|
|
115
|
+
max_candidates?: number;
|
|
116
|
+
};
|
|
117
|
+
input?: Record<string, any>;
|
|
118
|
+
output_to_context?: Record<string, any>;
|
|
119
|
+
output?: Record<string, any>;
|
|
120
|
+
transitions?: {
|
|
121
|
+
condition?: string;
|
|
122
|
+
to: string;
|
|
123
|
+
}[];
|
|
124
|
+
on_error?: string | Record<string, string>;
|
|
125
|
+
foreach?: string;
|
|
126
|
+
as?: string;
|
|
127
|
+
key?: string;
|
|
128
|
+
mode?: "settled" | "any";
|
|
129
|
+
timeout?: number;
|
|
130
|
+
launch?: string | string[];
|
|
131
|
+
launch_input?: Record<string, any>;
|
|
132
|
+
tool_loop?: boolean;
|
|
133
|
+
sampling?: "single" | "multi";
|
|
134
|
+
}
|
|
135
|
+
interface MachineSnapshot {
|
|
136
|
+
execution_id: string;
|
|
137
|
+
machine_name: string;
|
|
138
|
+
spec_version: string;
|
|
139
|
+
current_state: string;
|
|
140
|
+
context: Record<string, any>;
|
|
141
|
+
step: number;
|
|
142
|
+
created_at: string;
|
|
143
|
+
event?: string;
|
|
144
|
+
output?: Record<string, any>;
|
|
145
|
+
total_api_calls?: number;
|
|
146
|
+
total_cost?: number;
|
|
147
|
+
parent_execution_id?: string;
|
|
148
|
+
pending_launches?: LaunchIntent[];
|
|
149
|
+
}
|
|
150
|
+
interface LaunchIntent {
|
|
151
|
+
execution_id: string;
|
|
152
|
+
machine: string;
|
|
153
|
+
input: Record<string, any>;
|
|
154
|
+
launched: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface MCPServer {
|
|
157
|
+
command?: string;
|
|
158
|
+
args?: string[];
|
|
159
|
+
env?: Record<string, string>;
|
|
160
|
+
serverUrl?: string;
|
|
161
|
+
headers?: Record<string, string>;
|
|
162
|
+
timeout?: number;
|
|
163
|
+
}
|
|
164
|
+
interface ToolFilter {
|
|
165
|
+
allow?: string[];
|
|
166
|
+
deny?: string[];
|
|
167
|
+
}
|
|
168
|
+
interface ExecutionConfig {
|
|
169
|
+
type: "default" | "retry" | "parallel" | "mdap_voting";
|
|
170
|
+
backoffs?: number[];
|
|
171
|
+
jitter?: number;
|
|
172
|
+
n_samples?: number;
|
|
173
|
+
k_margin?: number;
|
|
174
|
+
max_candidates?: number;
|
|
175
|
+
}
|
|
176
|
+
interface ExecutionType {
|
|
177
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
178
|
+
}
|
|
179
|
+
interface MachineHooks {
|
|
180
|
+
onMachineStart?(context: Record<string, any>): Record<string, any> | Promise<Record<string, any>>;
|
|
181
|
+
onMachineEnd?(context: Record<string, any>, output: any): any | Promise<any>;
|
|
182
|
+
onStateEnter?(state: string, context: Record<string, any>): Record<string, any> | Promise<Record<string, any>>;
|
|
183
|
+
onStateExit?(state: string, context: Record<string, any>, output: any): any | Promise<any>;
|
|
184
|
+
onTransition?(from: string, to: string, context: Record<string, any>): string | Promise<string>;
|
|
185
|
+
onError?(state: string, error: Error, context: Record<string, any>): string | null | Promise<string | null>;
|
|
186
|
+
onAction?(action: string, context: Record<string, any>): Record<string, any> | Promise<Record<string, any>>;
|
|
187
|
+
}
|
|
188
|
+
interface PersistenceBackend {
|
|
189
|
+
save(key: string, snapshot: MachineSnapshot): Promise<void>;
|
|
190
|
+
load(key: string): Promise<MachineSnapshot | null>;
|
|
191
|
+
delete(key: string): Promise<void>;
|
|
192
|
+
list(prefix: string): Promise<string[]>;
|
|
193
|
+
}
|
|
194
|
+
interface ResultBackend {
|
|
195
|
+
write(uri: string, data: any): Promise<void>;
|
|
196
|
+
read(uri: string, options?: {
|
|
197
|
+
block?: boolean;
|
|
198
|
+
timeout?: number;
|
|
199
|
+
}): Promise<any>;
|
|
200
|
+
exists(uri: string): Promise<boolean>;
|
|
201
|
+
delete(uri: string): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
interface MachineOptions {
|
|
204
|
+
config: MachineConfig | string;
|
|
205
|
+
hooks?: MachineHooks;
|
|
206
|
+
persistence?: PersistenceBackend;
|
|
207
|
+
resultBackend?: ResultBackend;
|
|
208
|
+
executionLock?: ExecutionLock;
|
|
209
|
+
configDir?: string;
|
|
210
|
+
executionId?: string;
|
|
211
|
+
parentExecutionId?: string;
|
|
212
|
+
/** Path to profiles.yml for model profile resolution */
|
|
213
|
+
profilesFile?: string;
|
|
214
|
+
}
|
|
215
|
+
interface MachineInput {
|
|
216
|
+
name: string;
|
|
217
|
+
input?: Record<string, any>;
|
|
218
|
+
}
|
|
219
|
+
interface MachineReference {
|
|
220
|
+
path?: string;
|
|
221
|
+
inline?: MachineConfig;
|
|
222
|
+
}
|
|
223
|
+
interface MachineWrapper {
|
|
224
|
+
spec: "flatmachine";
|
|
225
|
+
spec_version: string;
|
|
226
|
+
data: MachineConfig["data"];
|
|
227
|
+
}
|
|
228
|
+
interface BackendConfig {
|
|
229
|
+
persistence?: "memory" | "local" | "redis" | "postgres" | "s3";
|
|
230
|
+
locking?: "none" | "local" | "redis" | "consul";
|
|
231
|
+
results?: "memory" | "redis";
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Prevents concurrent execution of the same machine instance.
|
|
235
|
+
* See flatagents-runtime.d.ts for spec.
|
|
236
|
+
*/
|
|
237
|
+
interface ExecutionLock {
|
|
238
|
+
acquire(key: string): Promise<boolean>;
|
|
239
|
+
release(key: string): Promise<void>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* LLM Backend Types
|
|
244
|
+
*
|
|
245
|
+
* Matches flatagents-runtime.d.ts specification.
|
|
246
|
+
* These types abstract over different LLM providers.
|
|
247
|
+
*/
|
|
248
|
+
interface Message {
|
|
249
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
250
|
+
content: string;
|
|
251
|
+
tool_call_id?: string;
|
|
252
|
+
tool_calls?: ToolCall[];
|
|
253
|
+
}
|
|
254
|
+
interface ToolCall {
|
|
255
|
+
id: string;
|
|
256
|
+
type: 'function';
|
|
257
|
+
function: {
|
|
258
|
+
name: string;
|
|
259
|
+
arguments: string;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
interface LLMOptions {
|
|
263
|
+
temperature?: number;
|
|
264
|
+
max_tokens?: number;
|
|
265
|
+
top_p?: number;
|
|
266
|
+
top_k?: number;
|
|
267
|
+
frequency_penalty?: number;
|
|
268
|
+
presence_penalty?: number;
|
|
269
|
+
seed?: number;
|
|
270
|
+
tools?: ToolDefinition[];
|
|
271
|
+
response_format?: {
|
|
272
|
+
type: 'json_object';
|
|
273
|
+
} | {
|
|
274
|
+
type: 'text';
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
interface ToolDefinition {
|
|
278
|
+
type: 'function';
|
|
279
|
+
function: {
|
|
280
|
+
name: string;
|
|
281
|
+
description?: string;
|
|
282
|
+
parameters?: Record<string, any>;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Abstraction over LLM providers.
|
|
287
|
+
* See flatagents-runtime.d.ts for canonical definition.
|
|
288
|
+
*/
|
|
289
|
+
interface LLMBackend {
|
|
290
|
+
/** Total cost accumulated across all calls. */
|
|
291
|
+
totalCost: number;
|
|
292
|
+
/** Total API calls made. */
|
|
293
|
+
totalApiCalls: number;
|
|
294
|
+
/**
|
|
295
|
+
* Call LLM and return content string.
|
|
296
|
+
*/
|
|
297
|
+
call(messages: Message[], options?: LLMOptions): Promise<string>;
|
|
298
|
+
/**
|
|
299
|
+
* Call LLM and return raw provider response.
|
|
300
|
+
*/
|
|
301
|
+
callRaw(messages: Message[], options?: LLMOptions): Promise<any>;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Configuration for creating an LLM backend.
|
|
305
|
+
*/
|
|
306
|
+
interface LLMBackendConfig {
|
|
307
|
+
provider: string;
|
|
308
|
+
name: string;
|
|
309
|
+
apiKey?: string;
|
|
310
|
+
baseURL?: string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* VercelAIBackend - LLM backend using Vercel AI SDK
|
|
315
|
+
*
|
|
316
|
+
* Supports multiple providers through Vercel AI SDK:
|
|
317
|
+
* - OpenAI
|
|
318
|
+
* - Anthropic
|
|
319
|
+
* - Cerebras
|
|
320
|
+
* - OpenAI-compatible (Groq, Together, Fireworks, etc.)
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
declare class VercelAIBackend implements LLMBackend {
|
|
324
|
+
totalCost: number;
|
|
325
|
+
totalApiCalls: number;
|
|
326
|
+
private model;
|
|
327
|
+
constructor(config: LLMBackendConfig);
|
|
328
|
+
private createModel;
|
|
329
|
+
call(messages: Message[], options?: LLMOptions): Promise<string>;
|
|
330
|
+
callRaw(messages: Message[], options?: LLMOptions): Promise<any>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* MockLLMBackend - Mock backend for testing
|
|
335
|
+
*
|
|
336
|
+
* Provides predictable responses for testing without hitting real APIs.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
interface MockResponse {
|
|
340
|
+
content: string;
|
|
341
|
+
raw?: any;
|
|
342
|
+
}
|
|
343
|
+
declare class MockLLMBackend implements LLMBackend {
|
|
344
|
+
totalCost: number;
|
|
345
|
+
totalApiCalls: number;
|
|
346
|
+
private responses;
|
|
347
|
+
private responseIndex;
|
|
348
|
+
private defaultResponse;
|
|
349
|
+
/**
|
|
350
|
+
* Create a mock backend with predefined responses.
|
|
351
|
+
*
|
|
352
|
+
* @param responses - Array of responses to return in order
|
|
353
|
+
* @param defaultResponse - Response to use when responses are exhausted
|
|
354
|
+
*/
|
|
355
|
+
constructor(responses?: MockResponse[], defaultResponse?: MockResponse);
|
|
356
|
+
call(messages: Message[], options?: LLMOptions): Promise<string>;
|
|
357
|
+
callRaw(messages: Message[], options?: LLMOptions): Promise<any>;
|
|
358
|
+
/**
|
|
359
|
+
* Reset the response index to start from the beginning.
|
|
360
|
+
*/
|
|
361
|
+
reset(): void;
|
|
362
|
+
/**
|
|
363
|
+
* Add responses to the queue.
|
|
364
|
+
*/
|
|
365
|
+
addResponses(responses: MockResponse[]): void;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Options for constructing a FlatAgent with custom backends.
|
|
370
|
+
*/
|
|
371
|
+
interface AgentOptions {
|
|
372
|
+
/** Path to YAML config file or inline AgentConfig */
|
|
373
|
+
config: string | AgentConfig;
|
|
374
|
+
/** Custom LLM backend (if not provided, uses VercelAIBackend based on config) */
|
|
375
|
+
llmBackend?: LLMBackend;
|
|
376
|
+
/** Base directory for resolving relative paths */
|
|
377
|
+
configDir?: string;
|
|
378
|
+
/** Path to profiles.yml for model profile resolution */
|
|
379
|
+
profilesFile?: string;
|
|
380
|
+
}
|
|
381
|
+
declare class FlatAgent {
|
|
382
|
+
config: AgentConfig;
|
|
383
|
+
private mcpProvider?;
|
|
384
|
+
private llmBackend?;
|
|
385
|
+
private configDir;
|
|
386
|
+
private profilesFile?;
|
|
387
|
+
private resolvedModelConfig;
|
|
388
|
+
/**
|
|
389
|
+
* Create a FlatAgent.
|
|
390
|
+
*
|
|
391
|
+
* @param configOrOptions - Config path, config object, or AgentOptions
|
|
392
|
+
*/
|
|
393
|
+
constructor(configOrOptions: AgentConfig | string | AgentOptions);
|
|
394
|
+
/**
|
|
395
|
+
* Get or create the LLM backend.
|
|
396
|
+
*/
|
|
397
|
+
private getBackend;
|
|
398
|
+
call(input: Record<string, any>): Promise<{
|
|
399
|
+
content: string;
|
|
400
|
+
output: any;
|
|
401
|
+
}>;
|
|
402
|
+
private extractOutput;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
declare class FlatMachine {
|
|
406
|
+
config: MachineConfig;
|
|
407
|
+
executionId: string;
|
|
408
|
+
private agents;
|
|
409
|
+
private context;
|
|
410
|
+
private input;
|
|
411
|
+
private hooks?;
|
|
412
|
+
private checkpointManager?;
|
|
413
|
+
private resultBackend?;
|
|
414
|
+
private executionLock;
|
|
415
|
+
private configDir;
|
|
416
|
+
private profilesFile?;
|
|
417
|
+
private checkpointEvents;
|
|
418
|
+
private parentExecutionId?;
|
|
419
|
+
private pendingLaunches;
|
|
420
|
+
private currentState?;
|
|
421
|
+
private currentStep;
|
|
422
|
+
constructor(options: MachineOptions);
|
|
423
|
+
execute(input?: Record<string, any>, resumeSnapshot?: MachineSnapshot): Promise<any>;
|
|
424
|
+
private executeInternal;
|
|
425
|
+
resume(executionId: string): Promise<any>;
|
|
426
|
+
private findInitialState;
|
|
427
|
+
private executeAgent;
|
|
428
|
+
private executeMachine;
|
|
429
|
+
private launchMachines;
|
|
430
|
+
private evaluateTransitions;
|
|
431
|
+
private checkpoint;
|
|
432
|
+
private render;
|
|
433
|
+
private renderDirectValue;
|
|
434
|
+
private resolvePath;
|
|
435
|
+
private shouldCheckpoint;
|
|
436
|
+
private createResultBackend;
|
|
437
|
+
private createExecutionLock;
|
|
438
|
+
private createSettingsPersistenceBackend;
|
|
439
|
+
private createPersistenceBackend;
|
|
440
|
+
private createAgent;
|
|
441
|
+
private createMachine;
|
|
442
|
+
private resolveMachineConfig;
|
|
443
|
+
private resolveMachinePath;
|
|
444
|
+
private resolveProfilesFile;
|
|
445
|
+
private getMachineName;
|
|
446
|
+
private makeResultUri;
|
|
447
|
+
private addPendingLaunch;
|
|
448
|
+
private markLaunched;
|
|
449
|
+
private clearPendingLaunch;
|
|
450
|
+
private resumePendingLaunches;
|
|
451
|
+
private launchAndWrite;
|
|
452
|
+
private normalizeMachineResult;
|
|
453
|
+
private invokeMachineSingle;
|
|
454
|
+
private launchFireAndForget;
|
|
455
|
+
private awaitWithMode;
|
|
456
|
+
private firstCompleted;
|
|
457
|
+
private withTimeout;
|
|
458
|
+
private pickFirstKeyedResult;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Model profile management for FlatAgents.
|
|
463
|
+
*
|
|
464
|
+
* Provides centralized model configuration through profiles.yml files.
|
|
465
|
+
* Profiles enable easy switching between model configurations (e.g., dev vs prod).
|
|
466
|
+
*
|
|
467
|
+
* Resolution order (low to high priority):
|
|
468
|
+
* 1. default profile (fallback)
|
|
469
|
+
* 2. Named profile from agent's model field
|
|
470
|
+
* 3. Inline overrides from agent's model field
|
|
471
|
+
* 4. override profile (trumps all)
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Manages model profiles from profiles.yml files.
|
|
476
|
+
*
|
|
477
|
+
* Resolution order (low to high priority):
|
|
478
|
+
* 1. default profile (fallback)
|
|
479
|
+
* 2. Named profile from agent's model field
|
|
480
|
+
* 3. Inline overrides from agent's model field
|
|
481
|
+
* 4. override profile (trumps all)
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const manager = new ProfileManager("config/profiles.yml");
|
|
486
|
+
* const config = manager.resolveModelConfig("fast-cheap");
|
|
487
|
+
* console.log(config);
|
|
488
|
+
* // { provider: 'cerebras', name: 'zai-glm-4.6', temperature: 0.6 }
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare class ProfileManager {
|
|
492
|
+
private profiles;
|
|
493
|
+
private defaultProfile;
|
|
494
|
+
private overrideProfile;
|
|
495
|
+
readonly profilesFile: string | undefined;
|
|
496
|
+
constructor(profilesFile?: string);
|
|
497
|
+
/**
|
|
498
|
+
* Get or create a ProfileManager for a directory.
|
|
499
|
+
* Caches instances by directory to avoid re-reading profiles.yml.
|
|
500
|
+
*/
|
|
501
|
+
static getInstance(configDir: string): ProfileManager;
|
|
502
|
+
/**
|
|
503
|
+
* Clear cached ProfileManager instances.
|
|
504
|
+
*/
|
|
505
|
+
static clearCache(): void;
|
|
506
|
+
private loadProfiles;
|
|
507
|
+
/**
|
|
508
|
+
* Get a profile by name.
|
|
509
|
+
*/
|
|
510
|
+
getProfile(name: string): ModelProfileConfig | undefined;
|
|
511
|
+
/**
|
|
512
|
+
* Get all loaded profiles.
|
|
513
|
+
*/
|
|
514
|
+
getProfiles(): Record<string, ModelProfileConfig>;
|
|
515
|
+
/**
|
|
516
|
+
* Get the default profile name.
|
|
517
|
+
*/
|
|
518
|
+
getDefaultProfile(): string | undefined;
|
|
519
|
+
/**
|
|
520
|
+
* Get the override profile name.
|
|
521
|
+
*/
|
|
522
|
+
getOverrideProfile(): string | undefined;
|
|
523
|
+
/**
|
|
524
|
+
* Resolve the final model configuration.
|
|
525
|
+
*
|
|
526
|
+
* Resolution order:
|
|
527
|
+
* 1. Start with default profile (if set)
|
|
528
|
+
* 2. Apply named profile (if agentModelConfig is string or has 'profile' key)
|
|
529
|
+
* 3. Merge inline overrides (if agentModelConfig is dict)
|
|
530
|
+
* 4. Apply override profile (trumps all)
|
|
531
|
+
*
|
|
532
|
+
* @param agentModelConfig - Agent's model config (string, object, or undefined)
|
|
533
|
+
* @returns Fully resolved model configuration
|
|
534
|
+
* @throws Error if a referenced profile is not found
|
|
535
|
+
*/
|
|
536
|
+
resolveModelConfig(agentModelConfig: string | ModelConfig | undefined): ModelConfig;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Convenience function to resolve model configuration.
|
|
540
|
+
*
|
|
541
|
+
* @param agentModelConfig - Agent's model config (string, object, or undefined)
|
|
542
|
+
* @param configDir - Directory containing agent config (for profiles.yml lookup)
|
|
543
|
+
* @param profilesFile - Explicit path to profiles.yml (overrides auto-discovery)
|
|
544
|
+
* @returns Fully resolved model configuration
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* const config = resolveModelConfig("fast-cheap", "./config");
|
|
549
|
+
* console.log(config);
|
|
550
|
+
* // { provider: 'cerebras', name: 'zai-glm-4.6', temperature: 0.6 }
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
declare function resolveModelConfig(agentModelConfig: string | ModelConfig | undefined, configDir: string, profilesFile?: string): ModelConfig;
|
|
554
|
+
|
|
555
|
+
declare class DefaultExecution implements ExecutionType {
|
|
556
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
557
|
+
}
|
|
558
|
+
declare class RetryExecution implements ExecutionType {
|
|
559
|
+
private backoffs;
|
|
560
|
+
private jitter;
|
|
561
|
+
constructor(backoffs?: number[], jitter?: number);
|
|
562
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
563
|
+
}
|
|
564
|
+
declare class ParallelExecution implements ExecutionType {
|
|
565
|
+
private nSamples;
|
|
566
|
+
constructor(nSamples?: number);
|
|
567
|
+
execute<T>(fn: () => Promise<T>): Promise<any>;
|
|
568
|
+
}
|
|
569
|
+
declare class MDAPVotingExecution implements ExecutionType {
|
|
570
|
+
private kMargin;
|
|
571
|
+
private maxCandidates;
|
|
572
|
+
constructor(kMargin?: number, maxCandidates?: number);
|
|
573
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
574
|
+
}
|
|
575
|
+
declare function getExecutionType(config?: ExecutionConfig): ExecutionType;
|
|
576
|
+
|
|
577
|
+
declare class WebhookHooks implements MachineHooks {
|
|
578
|
+
private url;
|
|
579
|
+
constructor(url: string);
|
|
580
|
+
private send;
|
|
581
|
+
onMachineStart(context: Record<string, any>): Promise<Record<string, any>>;
|
|
582
|
+
onMachineEnd(context: Record<string, any>, output: any): Promise<any>;
|
|
583
|
+
onStateEnter(state: string, context: Record<string, any>): Promise<Record<string, any>>;
|
|
584
|
+
onStateExit(state: string, context: Record<string, any>, output: any): Promise<any>;
|
|
585
|
+
onAction(action: string, context: Record<string, any>): Promise<Record<string, any>>;
|
|
586
|
+
}
|
|
587
|
+
declare class CompositeHooks implements MachineHooks {
|
|
588
|
+
private hooks;
|
|
589
|
+
constructor(hooks: MachineHooks[]);
|
|
590
|
+
onMachineStart(context: Record<string, any>): Promise<Record<string, any>>;
|
|
591
|
+
onMachineEnd(context: Record<string, any>, output: any): Promise<any>;
|
|
592
|
+
onStateEnter(state: string, context: Record<string, any>): Promise<Record<string, any>>;
|
|
593
|
+
onStateExit(state: string, context: Record<string, any>, output: any): Promise<any>;
|
|
594
|
+
onTransition(from: string, to: string, context: Record<string, any>): Promise<string>;
|
|
595
|
+
onError(state: string, error: Error, context: Record<string, any>): Promise<string | null>;
|
|
596
|
+
onAction(action: string, context: Record<string, any>): Promise<Record<string, any>>;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
declare class MemoryBackend implements PersistenceBackend {
|
|
600
|
+
private store;
|
|
601
|
+
save(key: string, snapshot: MachineSnapshot): Promise<void>;
|
|
602
|
+
load(key: string): Promise<MachineSnapshot | null>;
|
|
603
|
+
delete(key: string): Promise<void>;
|
|
604
|
+
list(prefix: string): Promise<string[]>;
|
|
605
|
+
}
|
|
606
|
+
declare class LocalFileBackend implements PersistenceBackend {
|
|
607
|
+
private dir;
|
|
608
|
+
constructor(dir?: string);
|
|
609
|
+
private ensureDir;
|
|
610
|
+
private getPath;
|
|
611
|
+
save(key: string, snapshot: MachineSnapshot): Promise<void>;
|
|
612
|
+
load(key: string): Promise<MachineSnapshot | null>;
|
|
613
|
+
delete(key: string): Promise<void>;
|
|
614
|
+
list(prefix: string): Promise<string[]>;
|
|
615
|
+
}
|
|
616
|
+
declare class CheckpointManager {
|
|
617
|
+
private backend;
|
|
618
|
+
constructor(backend: PersistenceBackend);
|
|
619
|
+
checkpoint(snapshot: MachineSnapshot): Promise<void>;
|
|
620
|
+
restore(executionId: string): Promise<MachineSnapshot | null>;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
declare const inMemoryResultBackend: ResultBackend;
|
|
624
|
+
|
|
625
|
+
declare class MCPToolProvider {
|
|
626
|
+
private clients;
|
|
627
|
+
connect(servers: Record<string, MCPServer>): Promise<void>;
|
|
628
|
+
listTools(filter?: ToolFilter): Promise<any[]>;
|
|
629
|
+
callTool(name: string, args: any): Promise<any>;
|
|
630
|
+
private matchesFilter;
|
|
631
|
+
private match;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
declare function evaluate(expr: string, ctx: {
|
|
635
|
+
context: any;
|
|
636
|
+
input: any;
|
|
637
|
+
output: any;
|
|
638
|
+
}): any;
|
|
639
|
+
|
|
640
|
+
type TemplateAllowlist = {
|
|
641
|
+
filters?: string[];
|
|
642
|
+
tags?: string[];
|
|
643
|
+
patterns?: string[];
|
|
644
|
+
};
|
|
645
|
+
declare function setTemplateAllowlist(allowlist?: TemplateAllowlist | null): void;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* NoOpLock - Always acquires the lock.
|
|
649
|
+
* Use when locking is handled externally or disabled.
|
|
650
|
+
*
|
|
651
|
+
* Required by flatagents-runtime.d.ts spec.
|
|
652
|
+
*/
|
|
653
|
+
declare class NoOpLock implements ExecutionLock {
|
|
654
|
+
acquire(key: string): Promise<boolean>;
|
|
655
|
+
release(key: string): Promise<void>;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* LocalFileLock - File-based locking for single-node deployments.
|
|
659
|
+
* Uses exclusive file creation to prevent concurrent execution.
|
|
660
|
+
*
|
|
661
|
+
* Recommended by flatagents-runtime.d.ts spec.
|
|
662
|
+
*/
|
|
663
|
+
declare class LocalFileLock implements ExecutionLock {
|
|
664
|
+
private lockDir;
|
|
665
|
+
private handles;
|
|
666
|
+
constructor(lockDir?: string);
|
|
667
|
+
private getLockPath;
|
|
668
|
+
private ensureDir;
|
|
669
|
+
acquire(key: string): Promise<boolean>;
|
|
670
|
+
release(key: string): Promise<void>;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export { type AgentConfig, type AgentOptions, type BackendConfig, CheckpointManager, CompositeHooks, DefaultExecution, type ExecutionConfig, type ExecutionLock, type ExecutionType, FlatAgent, FlatMachine, type LLMBackend, type LLMBackendConfig, type LLMOptions, LocalFileBackend, LocalFileLock, type MCPServer, MCPToolProvider, MDAPVotingExecution, type MachineConfig, type MachineHooks, type MachineOptions, type MachineSnapshot, MemoryBackend, type Message, MockLLMBackend, type MockResponse, type ModelConfig, type ModelProfileConfig, NoOpLock, ParallelExecution, type PersistenceBackend, ProfileManager, type ProfiledModelConfig, type ProfilesConfig, type ResultBackend, RetryExecution, type State, type TemplateAllowlist, type ToolCall, type ToolDefinition, type ToolFilter, VercelAIBackend, WebhookHooks, evaluate, getExecutionType, inMemoryResultBackend, resolveModelConfig, setTemplateAllowlist };
|