agentflow-core 0.8.0 → 0.8.1
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 +99 -0
- package/dist/{chunk-DY7YHFIB.js → chunk-BYWLDTZK.js} +2 -1
- package/dist/{chunk-6X5HU5LB.js → chunk-NVFWBTAZ.js} +75 -37
- package/dist/cli.cjs +76 -38
- package/dist/cli.js +6 -6
- package/dist/index.cjs +945 -740
- package/dist/index.d.cts +344 -137
- package/dist/index.d.ts +344 -137
- package/dist/index.js +380 -215
- package/dist/{loader-LYRR6LMM.js → loader-JMFEFI3Q.js} +1 -1
- package/package.json +7 -3
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,25 @@ interface TraceEvent {
|
|
|
50
50
|
readonly nodeId: string;
|
|
51
51
|
readonly data: Readonly<Record<string, unknown>>;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Optional typed data for `decision` trace events.
|
|
55
|
+
* Frameworks can emit these to provide richer decision data than graph inference.
|
|
56
|
+
* SOMA will use these fields if present, falling back to graph-structure inference.
|
|
57
|
+
*/
|
|
58
|
+
interface DecisionTraceData {
|
|
59
|
+
/** What was selected */
|
|
60
|
+
readonly choice: string;
|
|
61
|
+
/** Other options available */
|
|
62
|
+
readonly alternatives?: readonly string[];
|
|
63
|
+
/** Why this choice was made */
|
|
64
|
+
readonly rationale?: string;
|
|
65
|
+
/** Confidence in the decision (0.0-1.0) */
|
|
66
|
+
readonly confidence?: number;
|
|
67
|
+
/** Arbitrary context */
|
|
68
|
+
readonly context?: Readonly<Record<string, unknown>>;
|
|
69
|
+
/** Decision outcome */
|
|
70
|
+
readonly outcome?: string;
|
|
71
|
+
}
|
|
53
72
|
/** The complete execution graph for one agent run. */
|
|
54
73
|
interface ExecutionGraph {
|
|
55
74
|
readonly id: string;
|
|
@@ -71,6 +90,8 @@ interface ExecutionGraph {
|
|
|
71
90
|
readonly spanId?: string;
|
|
72
91
|
/** Parent span ID, or null if this is the root span. */
|
|
73
92
|
readonly parentSpanId?: string | null;
|
|
93
|
+
/** Arbitrary metadata preserved from the trace file. */
|
|
94
|
+
readonly metadata?: Record<string, unknown>;
|
|
74
95
|
}
|
|
75
96
|
/**
|
|
76
97
|
* Configuration for AgentFlow.
|
|
@@ -307,14 +328,135 @@ interface ConformanceReport {
|
|
|
307
328
|
/** List of specific deviations found. */
|
|
308
329
|
readonly deviations: readonly Deviation[];
|
|
309
330
|
}
|
|
331
|
+
/** Explanation attached to every guard violation for transparency. */
|
|
332
|
+
interface GuardExplanation {
|
|
333
|
+
/** The guard rule name (e.g., 'max-depth', 'timeout'). */
|
|
334
|
+
readonly rule: string;
|
|
335
|
+
/** The configured threshold that was exceeded. */
|
|
336
|
+
readonly threshold: number | string;
|
|
337
|
+
/** The actual observed value. */
|
|
338
|
+
readonly actual: number | string;
|
|
339
|
+
/** Where the threshold came from. */
|
|
340
|
+
readonly source: 'static' | 'soma-policy' | 'adaptive' | 'assertion';
|
|
341
|
+
/** Optional historical evidence supporting the threshold. */
|
|
342
|
+
readonly evidence?: string;
|
|
343
|
+
}
|
|
344
|
+
/** Outcome assertion for post-action verification. */
|
|
345
|
+
interface OutcomeAssertion {
|
|
346
|
+
/** Human-readable label for this assertion. */
|
|
347
|
+
readonly name: string;
|
|
348
|
+
/** Verification function — returns true if the expected outcome occurred. */
|
|
349
|
+
readonly verify: () => Promise<boolean> | boolean;
|
|
350
|
+
/** Timeout in milliseconds (default: 5000). */
|
|
351
|
+
readonly timeout?: number;
|
|
352
|
+
}
|
|
310
353
|
/**
|
|
311
354
|
* A detected guard violation.
|
|
312
355
|
*/
|
|
313
356
|
interface GuardViolation {
|
|
314
|
-
readonly type: 'timeout' | 'reasoning-loop' | 'spawn-explosion' | 'high-failure-rate' | 'conformance-drift' | 'known-bottleneck';
|
|
357
|
+
readonly type: 'timeout' | 'reasoning-loop' | 'spawn-explosion' | 'high-failure-rate' | 'conformance-drift' | 'known-bottleneck' | 'outcome_mismatch';
|
|
315
358
|
readonly nodeId: string;
|
|
316
359
|
readonly message: string;
|
|
317
360
|
readonly timestamp: number;
|
|
361
|
+
readonly explanation: GuardExplanation;
|
|
362
|
+
}
|
|
363
|
+
/** Per-node cost attribution. */
|
|
364
|
+
interface NodeCost {
|
|
365
|
+
readonly nodeId: string;
|
|
366
|
+
readonly name: string;
|
|
367
|
+
readonly type: NodeType;
|
|
368
|
+
readonly tokenCost: number | null;
|
|
369
|
+
readonly durationMs: number | null;
|
|
370
|
+
}
|
|
371
|
+
/** Wasteful pattern detection flag. */
|
|
372
|
+
interface EfficiencyFlag {
|
|
373
|
+
readonly pattern: 'wasteful_retry' | 'context_bloat';
|
|
374
|
+
readonly nodeName: string;
|
|
375
|
+
readonly retryCount?: number;
|
|
376
|
+
readonly tokenCost: number;
|
|
377
|
+
readonly message: string;
|
|
378
|
+
}
|
|
379
|
+
/** Per-run efficiency summary. */
|
|
380
|
+
interface RunEfficiency {
|
|
381
|
+
readonly graphId: string;
|
|
382
|
+
readonly agentId: string;
|
|
383
|
+
readonly totalTokenCost: number;
|
|
384
|
+
readonly completedNodes: number;
|
|
385
|
+
readonly costPerNode: number;
|
|
386
|
+
}
|
|
387
|
+
/** Aggregate efficiency report across runs. */
|
|
388
|
+
interface EfficiencyReport {
|
|
389
|
+
readonly runs: readonly RunEfficiency[];
|
|
390
|
+
readonly aggregate: {
|
|
391
|
+
mean: number;
|
|
392
|
+
median: number;
|
|
393
|
+
p95: number;
|
|
394
|
+
};
|
|
395
|
+
readonly flags: readonly EfficiencyFlag[];
|
|
396
|
+
readonly nodeCosts: readonly NodeCost[];
|
|
397
|
+
readonly dataCoverage: number;
|
|
398
|
+
}
|
|
399
|
+
/** Per-step summary in a run receipt. */
|
|
400
|
+
interface StepSummary {
|
|
401
|
+
readonly nodeId: string;
|
|
402
|
+
readonly name: string;
|
|
403
|
+
readonly type: NodeType;
|
|
404
|
+
readonly status: NodeStatus;
|
|
405
|
+
readonly durationMs: number | null;
|
|
406
|
+
readonly tokenCost: number | null;
|
|
407
|
+
readonly error: string | null;
|
|
408
|
+
}
|
|
409
|
+
/** Structured run summary. */
|
|
410
|
+
interface RunReceipt {
|
|
411
|
+
readonly runId: string;
|
|
412
|
+
readonly agentId: string;
|
|
413
|
+
readonly status: GraphStatus;
|
|
414
|
+
readonly startTime: number;
|
|
415
|
+
readonly endTime: number | null;
|
|
416
|
+
readonly totalDurationMs: number | null;
|
|
417
|
+
readonly totalTokenCost: number | null;
|
|
418
|
+
readonly steps: readonly StepSummary[];
|
|
419
|
+
readonly summary: {
|
|
420
|
+
readonly attempted: number;
|
|
421
|
+
readonly succeeded: number;
|
|
422
|
+
readonly failed: number;
|
|
423
|
+
readonly skipped: number;
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
/** A single conformance history entry. */
|
|
427
|
+
interface ConformanceHistoryEntry {
|
|
428
|
+
readonly agentId: string;
|
|
429
|
+
readonly timestamp: number;
|
|
430
|
+
readonly score: number;
|
|
431
|
+
readonly runId: string;
|
|
432
|
+
}
|
|
433
|
+
/** Conformance score history for an agent. */
|
|
434
|
+
type ConformanceHistory = ConformanceHistoryEntry[];
|
|
435
|
+
/** Options for drift detection. */
|
|
436
|
+
interface DriftOptions {
|
|
437
|
+
/** Sliding window size (number of runs). Default: 50. */
|
|
438
|
+
readonly windowSize?: number;
|
|
439
|
+
}
|
|
440
|
+
/** Drift detection report. */
|
|
441
|
+
interface DriftReport {
|
|
442
|
+
readonly status: 'stable' | 'degrading' | 'improving' | 'insufficient_data';
|
|
443
|
+
readonly slope: number;
|
|
444
|
+
readonly r2: number;
|
|
445
|
+
readonly windowSize: number;
|
|
446
|
+
readonly dataPoints: number;
|
|
447
|
+
readonly alert?: {
|
|
448
|
+
readonly type: 'conformance_trend_degradation';
|
|
449
|
+
readonly agentId: string;
|
|
450
|
+
readonly currentScore: number;
|
|
451
|
+
readonly trendSlope: number;
|
|
452
|
+
readonly windowSize: number;
|
|
453
|
+
readonly message: string;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
/** Options for variant analysis. */
|
|
457
|
+
interface VariantOptions {
|
|
458
|
+
/** Dimensions to include in variant signature. Default: ['path']. */
|
|
459
|
+
readonly dimensions?: readonly ('path' | 'modelId' | 'status')[];
|
|
318
460
|
}
|
|
319
461
|
/** Event type discriminator for AgentFlow events. */
|
|
320
462
|
type AgentFlowEventType = 'execution.completed' | 'execution.failed' | 'pattern.discovered' | 'pattern.updated';
|
|
@@ -646,35 +788,6 @@ declare function createEventEmitter(config?: EventEmitterConfig): EventEmitter;
|
|
|
646
788
|
*/
|
|
647
789
|
declare function createGraphBuilder(config?: AgentFlowConfig): GraphBuilder;
|
|
648
790
|
|
|
649
|
-
/**
|
|
650
|
-
* LLM-powered semantic analysis engine for agent execution data.
|
|
651
|
-
*
|
|
652
|
-
* The insight engine reads from the knowledge store, constructs prompts via
|
|
653
|
-
* pure prompt builder functions, delegates to a user-provided AnalysisFn,
|
|
654
|
-
* and caches results as InsightEvents in the store.
|
|
655
|
-
*
|
|
656
|
-
* @module
|
|
657
|
-
*/
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Create an LLM-powered semantic analysis engine.
|
|
661
|
-
*
|
|
662
|
-
* @param store - The knowledge store to read data from and cache insights to.
|
|
663
|
-
* @param analysisFn - User-provided LLM function (prompt → response).
|
|
664
|
-
* @param config - Optional configuration (cache TTL).
|
|
665
|
-
* @returns An InsightEngine for semantic analysis of agent execution data.
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```ts
|
|
669
|
-
* const engine = createInsightEngine(store, async (prompt) => {
|
|
670
|
-
* return await myLlm.complete(prompt);
|
|
671
|
-
* });
|
|
672
|
-
* const result = await engine.explainFailures('my-agent');
|
|
673
|
-
* console.log(result.content);
|
|
674
|
-
* ```
|
|
675
|
-
*/
|
|
676
|
-
declare function createInsightEngine(store: KnowledgeStore, analysisFn: AnalysisFn, config?: InsightEngineConfig): InsightEngine;
|
|
677
|
-
|
|
678
791
|
/**
|
|
679
792
|
* Pure query functions for interrogating a built `ExecutionGraph`.
|
|
680
793
|
* Every function takes a frozen graph and returns derived data without mutation.
|
|
@@ -870,6 +983,35 @@ declare function checkGuards(graph: ExecutionGraph, config?: GuardConfig): reado
|
|
|
870
983
|
*/
|
|
871
984
|
declare function withGuards(builder: GraphBuilder, config?: GuardConfig): GraphBuilder;
|
|
872
985
|
|
|
986
|
+
/**
|
|
987
|
+
* LLM-powered semantic analysis engine for agent execution data.
|
|
988
|
+
*
|
|
989
|
+
* The insight engine reads from the knowledge store, constructs prompts via
|
|
990
|
+
* pure prompt builder functions, delegates to a user-provided AnalysisFn,
|
|
991
|
+
* and caches results as InsightEvents in the store.
|
|
992
|
+
*
|
|
993
|
+
* @module
|
|
994
|
+
*/
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Create an LLM-powered semantic analysis engine.
|
|
998
|
+
*
|
|
999
|
+
* @param store - The knowledge store to read data from and cache insights to.
|
|
1000
|
+
* @param analysisFn - User-provided LLM function (prompt → response).
|
|
1001
|
+
* @param config - Optional configuration (cache TTL).
|
|
1002
|
+
* @returns An InsightEngine for semantic analysis of agent execution data.
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```ts
|
|
1006
|
+
* const engine = createInsightEngine(store, async (prompt) => {
|
|
1007
|
+
* return await myLlm.complete(prompt);
|
|
1008
|
+
* });
|
|
1009
|
+
* const result = await engine.explainFailures('my-agent');
|
|
1010
|
+
* console.log(result.content);
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
declare function createInsightEngine(store: KnowledgeStore, analysisFn: AnalysisFn, config?: InsightEngineConfig): InsightEngine;
|
|
1014
|
+
|
|
873
1015
|
/**
|
|
874
1016
|
* JSON file-based event writer for AgentFlow.
|
|
875
1017
|
*
|
|
@@ -941,68 +1083,6 @@ declare function createJsonEventWriter(config: JsonEventWriterConfig): EventWrit
|
|
|
941
1083
|
*/
|
|
942
1084
|
declare function createKnowledgeStore(config?: KnowledgeStoreConfig): KnowledgeStore;
|
|
943
1085
|
|
|
944
|
-
/**
|
|
945
|
-
* PolicySource: read-only interface over the knowledge store for adaptive guards.
|
|
946
|
-
*
|
|
947
|
-
* Bridges accumulated execution knowledge to guard decisions without
|
|
948
|
-
* coupling guards to storage internals.
|
|
949
|
-
*
|
|
950
|
-
* @module
|
|
951
|
-
*/
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Create a PolicySource backed by a knowledge store.
|
|
955
|
-
*
|
|
956
|
-
* All methods delegate to the store's profile data. The PolicySource is a
|
|
957
|
-
* pure read interface — it never writes to the store.
|
|
958
|
-
*
|
|
959
|
-
* @param store - The knowledge store to query.
|
|
960
|
-
* @returns A PolicySource for use with adaptive guards.
|
|
961
|
-
*
|
|
962
|
-
* @example
|
|
963
|
-
* ```ts
|
|
964
|
-
* const store = createKnowledgeStore({ baseDir: '.agentflow/knowledge' });
|
|
965
|
-
* const policy = createPolicySource(store);
|
|
966
|
-
* const rate = policy.recentFailureRate('my-agent'); // 0.0–1.0
|
|
967
|
-
* ```
|
|
968
|
-
*/
|
|
969
|
-
declare function createPolicySource(store: KnowledgeStore): PolicySource;
|
|
970
|
-
|
|
971
|
-
/**
|
|
972
|
-
* Soma-compatible event writer for AgentFlow.
|
|
973
|
-
*
|
|
974
|
-
* Converts AgentFlow events (ExecutionEvent, PatternEvent) into Markdown files
|
|
975
|
-
* with YAML frontmatter that Soma's Curator can ingest from its inbox directory.
|
|
976
|
-
*
|
|
977
|
-
* @module
|
|
978
|
-
*/
|
|
979
|
-
|
|
980
|
-
/**
|
|
981
|
-
* Configuration for the Soma event writer.
|
|
982
|
-
*/
|
|
983
|
-
interface SomaEventWriterConfig {
|
|
984
|
-
/** Directory to write event files to (Soma's inbox). Created if it does not exist. */
|
|
985
|
-
readonly inboxDir: string;
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Create a Soma event writer that persists events as Curator-compatible Markdown files.
|
|
989
|
-
*
|
|
990
|
-
* Each event is written to `{type}-{agentId}-{compact-ISO-timestamp}.md` in the
|
|
991
|
-
* configured inbox directory. The Curator picks up these files on its 60-second cycle.
|
|
992
|
-
*
|
|
993
|
-
* @param config - Writer configuration with inbox directory path.
|
|
994
|
-
* @returns An EventWriter that writes Markdown files to the Soma inbox.
|
|
995
|
-
*
|
|
996
|
-
* @example
|
|
997
|
-
* ```ts
|
|
998
|
-
* const writer = createSomaEventWriter({ inboxDir: '~/.openclaw/workspace/inbox' });
|
|
999
|
-
* const emitter = createEventEmitter({ writers: [writer] });
|
|
1000
|
-
* await emitter.emit(createExecutionEvent(graph));
|
|
1001
|
-
* // Creates: ~/.openclaw/workspace/inbox/execution-alfred-20260314T083502.md
|
|
1002
|
-
* ```
|
|
1003
|
-
*/
|
|
1004
|
-
declare function createSomaEventWriter(config: SomaEventWriterConfig): EventWriter;
|
|
1005
|
-
|
|
1006
1086
|
/**
|
|
1007
1087
|
* AgentFlow Live Monitor — real-time terminal dashboard for any agent system.
|
|
1008
1088
|
*
|
|
@@ -1074,6 +1154,33 @@ declare function loadGraph(input: string | Record<string, unknown>): ExecutionGr
|
|
|
1074
1154
|
*/
|
|
1075
1155
|
declare function graphToJson(graph: ExecutionGraph): Record<string, unknown>;
|
|
1076
1156
|
|
|
1157
|
+
/**
|
|
1158
|
+
* PolicySource: read-only interface over the knowledge store for adaptive guards.
|
|
1159
|
+
*
|
|
1160
|
+
* Bridges accumulated execution knowledge to guard decisions without
|
|
1161
|
+
* coupling guards to storage internals.
|
|
1162
|
+
*
|
|
1163
|
+
* @module
|
|
1164
|
+
*/
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Create a PolicySource backed by a knowledge store.
|
|
1168
|
+
*
|
|
1169
|
+
* All methods delegate to the store's profile data. The PolicySource is a
|
|
1170
|
+
* pure read interface — it never writes to the store.
|
|
1171
|
+
*
|
|
1172
|
+
* @param store - The knowledge store to query.
|
|
1173
|
+
* @returns A PolicySource for use with adaptive guards.
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```ts
|
|
1177
|
+
* const store = createKnowledgeStore({ baseDir: '.agentflow/knowledge' });
|
|
1178
|
+
* const policy = createPolicySource(store);
|
|
1179
|
+
* const rate = policy.recentFailureRate('my-agent'); // 0.0–1.0
|
|
1180
|
+
* ```
|
|
1181
|
+
*/
|
|
1182
|
+
declare function createPolicySource(store: KnowledgeStore): PolicySource;
|
|
1183
|
+
|
|
1077
1184
|
/**
|
|
1078
1185
|
* AgentFlow Process Audit — OS-level process health checks for agent systems.
|
|
1079
1186
|
*
|
|
@@ -1161,6 +1268,22 @@ interface ProcessAuditConfig {
|
|
|
1161
1268
|
* ```
|
|
1162
1269
|
*/
|
|
1163
1270
|
declare function discoverProcessConfig(dirs: string[]): ProcessAuditConfig | null;
|
|
1271
|
+
/**
|
|
1272
|
+
* Discover all process configurations from the given directories and systemd.
|
|
1273
|
+
*
|
|
1274
|
+
* Unlike `discoverProcessConfig` which returns only the first match, this
|
|
1275
|
+
* scans all PID files and also discovers systemd user services to return
|
|
1276
|
+
* a complete list of auditable processes.
|
|
1277
|
+
*
|
|
1278
|
+
* @example
|
|
1279
|
+
* ```ts
|
|
1280
|
+
* const configs = discoverAllProcessConfigs(['./data', '/var/run']);
|
|
1281
|
+
* for (const config of configs) {
|
|
1282
|
+
* console.log(formatAuditReport(auditProcesses(config)));
|
|
1283
|
+
* }
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
declare function discoverAllProcessConfigs(dirs: string[]): ProcessAuditConfig[];
|
|
1164
1287
|
/**
|
|
1165
1288
|
* Run a full process health audit.
|
|
1166
1289
|
*
|
|
@@ -1188,50 +1311,6 @@ declare function auditProcesses(config: ProcessAuditConfig): ProcessAuditResult;
|
|
|
1188
1311
|
*/
|
|
1189
1312
|
declare function formatAuditReport(result: ProcessAuditResult): string;
|
|
1190
1313
|
|
|
1191
|
-
/**
|
|
1192
|
-
* Pure prompt construction functions for LLM-powered semantic analysis.
|
|
1193
|
-
*
|
|
1194
|
-
* Each function takes knowledge store data and returns a structured prompt string.
|
|
1195
|
-
* No side effects, no filesystem access, no external calls.
|
|
1196
|
-
*
|
|
1197
|
-
* @module
|
|
1198
|
-
*/
|
|
1199
|
-
|
|
1200
|
-
/**
|
|
1201
|
-
* Build a structured prompt for LLM analysis of agent failures.
|
|
1202
|
-
*
|
|
1203
|
-
* @param events - Recent failed execution events for the agent.
|
|
1204
|
-
* @param profile - The agent's derived profile.
|
|
1205
|
-
* @returns A structured prompt string.
|
|
1206
|
-
*/
|
|
1207
|
-
declare function buildFailureAnalysisPrompt(events: ExecutionEvent[], profile: AgentProfile): string;
|
|
1208
|
-
/**
|
|
1209
|
-
* Build a structured prompt for explaining why an execution was anomalous.
|
|
1210
|
-
*
|
|
1211
|
-
* @param event - The specific execution event flagged as anomalous.
|
|
1212
|
-
* @param profile - The agent's derived profile for baseline context.
|
|
1213
|
-
* @returns A structured prompt string.
|
|
1214
|
-
*/
|
|
1215
|
-
declare function buildAnomalyExplanationPrompt(event: ExecutionEvent, profile: AgentProfile): string;
|
|
1216
|
-
/**
|
|
1217
|
-
* Build a structured prompt for generating an agent health summary.
|
|
1218
|
-
*
|
|
1219
|
-
* @param profile - The agent's derived profile.
|
|
1220
|
-
* @param recentEvents - Recent execution events.
|
|
1221
|
-
* @param patterns - Recent pattern discovery events.
|
|
1222
|
-
* @returns A structured prompt string.
|
|
1223
|
-
*/
|
|
1224
|
-
declare function buildAgentSummaryPrompt(profile: AgentProfile, recentEvents: ExecutionEvent[], patterns: PatternEvent[]): string;
|
|
1225
|
-
/**
|
|
1226
|
-
* Build a structured prompt for generating actionable fix recommendations.
|
|
1227
|
-
*
|
|
1228
|
-
* @param events - Recent failed execution events.
|
|
1229
|
-
* @param profile - The agent's derived profile.
|
|
1230
|
-
* @param patterns - Recent pattern discovery events.
|
|
1231
|
-
* @returns A structured prompt string.
|
|
1232
|
-
*/
|
|
1233
|
-
declare function buildFixSuggestionPrompt(events: ExecutionEvent[], profile: AgentProfile, patterns: PatternEvent[]): string;
|
|
1234
|
-
|
|
1235
1314
|
/**
|
|
1236
1315
|
* Process mining primitives for cross-run analysis of execution graphs.
|
|
1237
1316
|
*
|
|
@@ -1333,6 +1412,99 @@ declare function getBottlenecks(graphs: ExecutionGraph[]): Bottleneck[];
|
|
|
1333
1412
|
*/
|
|
1334
1413
|
declare function checkConformance(graph: ExecutionGraph, model: ProcessModel): ConformanceReport;
|
|
1335
1414
|
|
|
1415
|
+
/**
|
|
1416
|
+
* Pure prompt construction functions for LLM-powered semantic analysis.
|
|
1417
|
+
*
|
|
1418
|
+
* Each function takes knowledge store data and returns a structured prompt string.
|
|
1419
|
+
* No side effects, no filesystem access, no external calls.
|
|
1420
|
+
*
|
|
1421
|
+
* @module
|
|
1422
|
+
*/
|
|
1423
|
+
|
|
1424
|
+
/**
|
|
1425
|
+
* Build a structured prompt for LLM analysis of agent failures.
|
|
1426
|
+
*
|
|
1427
|
+
* @param events - Recent failed execution events for the agent.
|
|
1428
|
+
* @param profile - The agent's derived profile.
|
|
1429
|
+
* @returns A structured prompt string.
|
|
1430
|
+
*/
|
|
1431
|
+
declare function buildFailureAnalysisPrompt(events: ExecutionEvent[], profile: AgentProfile): string;
|
|
1432
|
+
/**
|
|
1433
|
+
* Build a structured prompt for explaining why an execution was anomalous.
|
|
1434
|
+
*
|
|
1435
|
+
* @param event - The specific execution event flagged as anomalous.
|
|
1436
|
+
* @param profile - The agent's derived profile for baseline context.
|
|
1437
|
+
* @returns A structured prompt string.
|
|
1438
|
+
*/
|
|
1439
|
+
declare function buildAnomalyExplanationPrompt(event: ExecutionEvent, profile: AgentProfile): string;
|
|
1440
|
+
/**
|
|
1441
|
+
* Build a structured prompt for generating an agent health summary.
|
|
1442
|
+
*
|
|
1443
|
+
* @param profile - The agent's derived profile.
|
|
1444
|
+
* @param recentEvents - Recent execution events.
|
|
1445
|
+
* @param patterns - Recent pattern discovery events.
|
|
1446
|
+
* @returns A structured prompt string.
|
|
1447
|
+
*/
|
|
1448
|
+
declare function buildAgentSummaryPrompt(profile: AgentProfile, recentEvents: ExecutionEvent[], patterns: PatternEvent[]): string;
|
|
1449
|
+
/**
|
|
1450
|
+
* Build a structured prompt for generating actionable fix recommendations.
|
|
1451
|
+
*
|
|
1452
|
+
* @param events - Recent failed execution events.
|
|
1453
|
+
* @param profile - The agent's derived profile.
|
|
1454
|
+
* @param patterns - Recent pattern discovery events.
|
|
1455
|
+
* @returns A structured prompt string.
|
|
1456
|
+
*/
|
|
1457
|
+
declare function buildFixSuggestionPrompt(events: ExecutionEvent[], profile: AgentProfile, patterns: PatternEvent[]): string;
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Pure functions for building and formatting run receipts from execution graphs.
|
|
1461
|
+
*
|
|
1462
|
+
* A receipt is a structured summary of a completed (or running) agent execution,
|
|
1463
|
+
* including per-step details, cost attribution, and aggregate counts.
|
|
1464
|
+
* @module
|
|
1465
|
+
*/
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* Walk an execution graph and produce a structured {@link RunReceipt}.
|
|
1469
|
+
*
|
|
1470
|
+
* Steps are sorted by `startTime`. Summary counts classify each node as
|
|
1471
|
+
* succeeded (`completed`), failed (`failed | hung | timeout`), or skipped
|
|
1472
|
+
* (none currently — reserved for future use). `attempted` equals the total
|
|
1473
|
+
* node count.
|
|
1474
|
+
*
|
|
1475
|
+
* @param graph - A built (or snapshot) execution graph.
|
|
1476
|
+
* @returns A frozen run receipt.
|
|
1477
|
+
*/
|
|
1478
|
+
declare function toReceipt(graph: ExecutionGraph): RunReceipt;
|
|
1479
|
+
/**
|
|
1480
|
+
* Format a {@link RunReceipt} into a human-readable text block.
|
|
1481
|
+
*
|
|
1482
|
+
* Layout:
|
|
1483
|
+
* ```
|
|
1484
|
+
* === Run Receipt ===
|
|
1485
|
+
* Run: <runId>
|
|
1486
|
+
* Agent: <agentId>
|
|
1487
|
+
* Status: <status>
|
|
1488
|
+
* Duration: <totalDurationMs>ms
|
|
1489
|
+
*
|
|
1490
|
+
* Summary: <attempted> attempted, <succeeded> succeeded, <failed> failed, <skipped> skipped
|
|
1491
|
+
*
|
|
1492
|
+
* # | Step | Type | Status | Duration | Tokens
|
|
1493
|
+
* ---|------------------|---------|-----------|----------|-------
|
|
1494
|
+
* 1 | fetch-data | tool | completed | 120ms | 450
|
|
1495
|
+
* ...
|
|
1496
|
+
*
|
|
1497
|
+
* Total token cost: 1 250
|
|
1498
|
+
* ```
|
|
1499
|
+
*
|
|
1500
|
+
* Shows `'---'` for missing duration and `'---'` for missing cost data per step.
|
|
1501
|
+
* Shows `'no cost data'` for the totals line when no cost information is available.
|
|
1502
|
+
*
|
|
1503
|
+
* @param receipt - A run receipt produced by {@link toReceipt}.
|
|
1504
|
+
* @returns Multi-line formatted string.
|
|
1505
|
+
*/
|
|
1506
|
+
declare function formatReceipt(receipt: RunReceipt): string;
|
|
1507
|
+
|
|
1336
1508
|
/**
|
|
1337
1509
|
* CLI runner that wraps any command with automatic AgentFlow tracing.
|
|
1338
1510
|
*
|
|
@@ -1382,6 +1554,41 @@ interface RunResult {
|
|
|
1382
1554
|
*/
|
|
1383
1555
|
declare function runTraced(config: RunConfig): Promise<RunResult>;
|
|
1384
1556
|
|
|
1557
|
+
/**
|
|
1558
|
+
* Soma-compatible event writer for AgentFlow.
|
|
1559
|
+
*
|
|
1560
|
+
* Converts AgentFlow events (ExecutionEvent, PatternEvent) into Markdown files
|
|
1561
|
+
* with YAML frontmatter that Soma's Curator can ingest from its inbox directory.
|
|
1562
|
+
*
|
|
1563
|
+
* @module
|
|
1564
|
+
*/
|
|
1565
|
+
|
|
1566
|
+
/**
|
|
1567
|
+
* Configuration for the Soma event writer.
|
|
1568
|
+
*/
|
|
1569
|
+
interface SomaEventWriterConfig {
|
|
1570
|
+
/** Directory to write event files to (Soma's inbox). Created if it does not exist. */
|
|
1571
|
+
readonly inboxDir: string;
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Create a Soma event writer that persists events as Curator-compatible Markdown files.
|
|
1575
|
+
*
|
|
1576
|
+
* Each event is written to `{type}-{agentId}-{compact-ISO-timestamp}.md` in the
|
|
1577
|
+
* configured inbox directory. The Curator picks up these files on its 60-second cycle.
|
|
1578
|
+
*
|
|
1579
|
+
* @param config - Writer configuration with inbox directory path.
|
|
1580
|
+
* @returns An EventWriter that writes Markdown files to the Soma inbox.
|
|
1581
|
+
*
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```ts
|
|
1584
|
+
* const writer = createSomaEventWriter({ inboxDir: '~/.openclaw/workspace/inbox' });
|
|
1585
|
+
* const emitter = createEventEmitter({ writers: [writer] });
|
|
1586
|
+
* await emitter.emit(createExecutionEvent(graph));
|
|
1587
|
+
* // Creates: ~/.openclaw/workspace/inbox/execution-alfred-20260314T083502.md
|
|
1588
|
+
* ```
|
|
1589
|
+
*/
|
|
1590
|
+
declare function createSomaEventWriter(config: SomaEventWriterConfig): EventWriter;
|
|
1591
|
+
|
|
1385
1592
|
/**
|
|
1386
1593
|
* JSON file-based trace storage for ExecutionGraphs.
|
|
1387
1594
|
*
|
|
@@ -1530,4 +1737,4 @@ interface AlertPayload {
|
|
|
1530
1737
|
readonly dirs: readonly string[];
|
|
1531
1738
|
}
|
|
1532
1739
|
|
|
1533
|
-
export { type Adapter, type AgentFlowConfig, type AgentFlowEventType, type AgentProfile, type AlertCondition, type AlertPayload, type AnalysisFn, type Bottleneck, type ConformanceReport, type Deviation, type DeviationType, type DistributedTrace, type EdgeType, type EventEmitter, type EventEmitterConfig, type EventWriter, type ExecutionEdge, type ExecutionEvent, type ExecutionEventOptions, type ExecutionGraph, type ExecutionNode, type FailurePoint, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardViolation, type InsightEngine, type InsightEngineConfig, type InsightEvent, type InsightResult, type JsonEventWriterConfig, type KnowledgeStore, type KnowledgeStoreConfig, type MutableExecutionNode, type NodeStatus, type NodeType, type NotifyChannel, type OsProcess, type PatternEvent, type PidFileResult, type PolicySource, type PolicyThresholds, type ProcessAuditConfig, type ProcessAuditResult, type ProcessContext, type ProcessModel, type ProcessTransition, type RunConfig, type RunResult, type SemanticContext, type SomaEventWriterConfig, type StartNodeOptions, type SystemdUnitResult, type TraceEvent, type TraceEventType, type TraceStore, type Variant, type WatchConfig, type WorkerEntry, type WorkersResult, type Writer, auditProcesses, buildAgentSummaryPrompt, buildAnomalyExplanationPrompt, buildFailureAnalysisPrompt, buildFixSuggestionPrompt, checkConformance, checkGuards, createEventEmitter, createExecutionEvent, createGraphBuilder, createInsightEngine, createJsonEventWriter, createKnowledgeStore, createPatternEvent, createPolicySource, createSomaEventWriter, createTraceStore, discoverProcess, discoverProcessConfig, findVariants, findWaitingOn, formatAuditReport, getBottlenecks, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getPathSignature, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toTimeline, withGuards };
|
|
1740
|
+
export { type Adapter, type AgentFlowConfig, type AgentFlowEventType, type AgentProfile, type AlertCondition, type AlertPayload, type AnalysisFn, type Bottleneck, type ConformanceHistory, type ConformanceHistoryEntry, type ConformanceReport, type DecisionTraceData, type Deviation, type DeviationType, type DistributedTrace, type DriftOptions, type DriftReport, type EdgeType, type EfficiencyFlag, type EfficiencyReport, type EventEmitter, type EventEmitterConfig, type EventWriter, type ExecutionEdge, type ExecutionEvent, type ExecutionEventOptions, type ExecutionGraph, type ExecutionNode, type FailurePoint, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardExplanation, type GuardViolation, type InsightEngine, type InsightEngineConfig, type InsightEvent, type InsightResult, type JsonEventWriterConfig, type KnowledgeStore, type KnowledgeStoreConfig, type MutableExecutionNode, type NodeCost, type NodeStatus, type NodeType, type NotifyChannel, type OsProcess, type OutcomeAssertion, type PatternEvent, type PidFileResult, type PolicySource, type PolicyThresholds, type ProcessAuditConfig, type ProcessAuditResult, type ProcessContext, type ProcessModel, type ProcessTransition, type RunConfig, type RunEfficiency, type RunReceipt, type RunResult, type SemanticContext, type SomaEventWriterConfig, type StartNodeOptions, type StepSummary, type SystemdUnitResult, type TraceEvent, type TraceEventType, type TraceStore, type Variant, type VariantOptions, type WatchConfig, type WorkerEntry, type WorkersResult, type Writer, auditProcesses, buildAgentSummaryPrompt, buildAnomalyExplanationPrompt, buildFailureAnalysisPrompt, buildFixSuggestionPrompt, checkConformance, checkGuards, createEventEmitter, createExecutionEvent, createGraphBuilder, createInsightEngine, createJsonEventWriter, createKnowledgeStore, createPatternEvent, createPolicySource, createSomaEventWriter, createTraceStore, discoverAllProcessConfigs, discoverProcess, discoverProcessConfig, findVariants, findWaitingOn, formatAuditReport, formatReceipt, getBottlenecks, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getPathSignature, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toReceipt, toTimeline, withGuards };
|