@agent-evolve/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,773 @@
1
+ interface AgentConfig {
2
+ id: string;
3
+ name: string;
4
+ domain: string;
5
+ sub_domains?: string[];
6
+ readable_partitions: string[];
7
+ writable_partitions: string[];
8
+ }
9
+
10
+ interface IntentObject {
11
+ task_type: string;
12
+ domain: string;
13
+ complexity: 'low' | 'medium' | 'high';
14
+ target_audience: string;
15
+ output_format: string;
16
+ style: string;
17
+ key_entities: string[];
18
+ constraints: string[];
19
+ confidence: number;
20
+ unresolved: string[];
21
+ source_trace: {
22
+ [field: string]: 'user_input' | 'memory' | 'knowledge' | 'default' | 'llm_extract' | 'memory(conflict)';
23
+ };
24
+ }
25
+ interface RoughIntent {
26
+ task_type: string;
27
+ domain: string;
28
+ complexity: 'low' | 'medium' | 'high';
29
+ key_entities: string[];
30
+ missing: string[];
31
+ }
32
+ declare const DEFAULT_ROUGH_INTENT: RoughIntent;
33
+
34
+ interface AgentEvolveAdapter {
35
+ onMessage(msg: UserMessage): Promise<EnhancedContext>;
36
+ injectSystemPrompt(original: string): string;
37
+ parseIntentFromResponse(response: string): RoughIntent;
38
+ sendConfirmation(intent: IntentObject): Promise<boolean>;
39
+ askQuestions(questions: string[]): Promise<Record<string, string>>;
40
+ }
41
+ interface UserMessage {
42
+ text: string;
43
+ sender_id: string;
44
+ session_id: string;
45
+ channel: string;
46
+ timestamp: string;
47
+ }
48
+ type Source = 'user_input' | 'memory' | 'knowledge' | 'default' | 'llm_extract' | 'memory(conflict)' | 'recent_pref';
49
+ interface RegistryEntry {
50
+ id: string;
51
+ summary: string;
52
+ tags: string[];
53
+ storage_ptr: string;
54
+ data_type: string;
55
+ confidence: number;
56
+ verified_cnt: number;
57
+ partition: string;
58
+ source_agent?: string | null;
59
+ created_at: string;
60
+ last_accessed?: string | null;
61
+ access_count: number;
62
+ status: 'active' | 'stale' | 'hypothesis' | 'rolled_back';
63
+ }
64
+ interface FillResult extends RegistryEntry {
65
+ source: Source;
66
+ field?: string;
67
+ value?: string;
68
+ }
69
+ interface Conflict {
70
+ field: string;
71
+ options: FillResult[];
72
+ }
73
+ interface ResolvedFills {
74
+ resolved: Record<string, FillResult>;
75
+ conflicts: Conflict[];
76
+ }
77
+ interface ConfirmThreshold {
78
+ skip: number;
79
+ quick: number;
80
+ }
81
+ interface RetrievalTrace {
82
+ id: string;
83
+ intent_id?: string | undefined;
84
+ query_tags: string[];
85
+ partitions_searched: string[];
86
+ hits: string[];
87
+ loaded_l0: string[];
88
+ promoted_l1: string[];
89
+ promoted_l2: string[];
90
+ injected: string[];
91
+ created_at?: string | undefined;
92
+ }
93
+ interface PipelineConfig {
94
+ priorityRules: PriorityRules;
95
+ confirmThreshold: ConfirmThreshold;
96
+ }
97
+ interface PipelineResult {
98
+ intent: IntentObject;
99
+ trace: RetrievalTrace;
100
+ needsConfirmation?: boolean;
101
+ confirmMessage?: string;
102
+ }
103
+ interface RawData {
104
+ id?: string;
105
+ content: string;
106
+ storageLocation: string;
107
+ type: string;
108
+ sourceAgent: string;
109
+ partition?: string;
110
+ tags?: string[];
111
+ }
112
+ interface EnhancedContext {
113
+ userMessage: UserMessage['text'];
114
+ systemPrompt?: string;
115
+ agentConfig?: AgentConfig;
116
+ fills?: FillResult[];
117
+ metadata?: Record<string, unknown>;
118
+ }
119
+ interface PriorityRules {
120
+ order: Source[];
121
+ }
122
+
123
+ interface ExperienceEntry {
124
+ id: string;
125
+ summary: string;
126
+ condition: {
127
+ task_type?: string | undefined;
128
+ domain?: string | undefined;
129
+ entities?: string[] | undefined;
130
+ environment?: string | undefined;
131
+ };
132
+ conclusion: string;
133
+ action: string;
134
+ confidence: number;
135
+ full_context?: {
136
+ original_task: string;
137
+ execution_log: string;
138
+ evaluation: Record<string, any>;
139
+ };
140
+ source_agent: string;
141
+ source_trace_id: string;
142
+ verified_count: number;
143
+ created_at: string;
144
+ status: 'active' | 'hypothesis' | 'rolled_back';
145
+ target: 'skill_doc' | 'memory' | 'knowledge_global' | 'knowledge_dept';
146
+ partition: string;
147
+ abstracted_from?: string[];
148
+ is_abstract: boolean;
149
+ }
150
+
151
+ interface SearchFilters {
152
+ tags?: string[];
153
+ partition?: string | string[];
154
+ dataType?: string | string[];
155
+ minConfidence?: number;
156
+ limit?: number;
157
+ }
158
+ interface RegistryInsertInput {
159
+ id?: string;
160
+ summary: string;
161
+ tags?: string[];
162
+ storage_ptr: string;
163
+ data_type?: string;
164
+ confidence?: number;
165
+ verified_cnt?: number;
166
+ partition?: string;
167
+ source_agent?: string;
168
+ created_at?: string;
169
+ last_accessed?: string | null;
170
+ access_count?: number;
171
+ status?: RegistryEntry['status'];
172
+ }
173
+ type RegistryUpdateInput = Partial<Omit<RegistryInsertInput, 'id'>>;
174
+ declare class IndexTable {
175
+ private readonly db;
176
+ constructor(dbPath?: string);
177
+ insert(entry: RegistryInsertInput): string;
178
+ get(id: string): RegistryEntry | null;
179
+ update(id: string, updates: RegistryUpdateInput): boolean;
180
+ delete(id: string): boolean;
181
+ search(filters?: SearchFilters): RegistryEntry[];
182
+ recordAccess(id: string): boolean;
183
+ saveTrace(trace: RetrievalTrace): string;
184
+ getTrace(id: string): RetrievalTrace | null;
185
+ close(): void;
186
+ }
187
+
188
+ declare function extractKeywords(userMsg: string): string[];
189
+ declare function resolveSource(entry: RegistryEntry): Source;
190
+ declare function dedup(results: FillResult[]): FillResult[];
191
+ declare function contextFill(userMsg: string, registry: IndexTable, agentConfig: AgentConfig): Promise<FillResult[]>;
192
+ declare function contextFillRefine(rough: RoughIntent, initial: FillResult[], registry: IndexTable, agentConfig: AgentConfig): Promise<FillResult[]>;
193
+
194
+ declare const EXTRACTION_PROMPT = "\nAfter your response, output a JSON block (invisible to user):\n```intent\n{\"task_type\":\"...\",\"domain\":\"...\",\"complexity\":\"low|medium|high\",\n\"key_entities\":[\"...\"],\"missing\":[\"...\"]}\n```";
195
+ declare function parseIntentBlock(response: string): RoughIntent;
196
+ declare function stripIntentBlock(response: string): string;
197
+
198
+ declare function groupByField(fills: FillResult[]): Record<string, FillResult[]>;
199
+ declare function isConflicting(a: FillResult, b: FillResult): boolean;
200
+ declare function conflictDetect(fills: FillResult[], rules?: PriorityRules): ResolvedFills;
201
+
202
+ declare function calcConfidence(rough: RoughIntent, resolved: ResolvedFills): number;
203
+ declare function extractConstraints(resolved: ResolvedFills): string[];
204
+ type IntentSource = 'user_input' | 'memory' | 'knowledge' | 'default' | 'llm_extract' | 'memory(conflict)';
205
+ declare function buildSourceTrace(rough: RoughIntent, resolved: ResolvedFills): Record<string, IntentSource>;
206
+ declare function structure(rough: RoughIntent, resolved: ResolvedFills, _userMsg: string): IntentObject;
207
+
208
+ declare const DEFAULT_THRESHOLD: ConfirmThreshold;
209
+ declare function buildQuestions(intent: IntentObject): string[];
210
+ declare function updateIntent(intent: IntentObject, answers: Record<string, string>): IntentObject;
211
+ declare function confirmIfNeeded(intent: IntentObject, adapter: AgentEvolveAdapter, threshold?: ConfirmThreshold): Promise<IntentObject>;
212
+
213
+ declare function buildTrace(rough: RoughIntent, searchResults: FillResult[], refined: FillResult[], _resolved: {
214
+ resolved: Record<string, FillResult>;
215
+ }, confirmed: IntentObject): RetrievalTrace;
216
+ declare function intentPipeline(userMsg: string, adapter: AgentEvolveAdapter, registry: IndexTable, agentConfig: AgentConfig, config: PipelineConfig): Promise<PipelineResult>;
217
+
218
+ interface AttentionBudget {
219
+ maxTokens: number;
220
+ globalPrinciplesRatio: number;
221
+ memoryRatio: number;
222
+ skillDocsRatio: number;
223
+ }
224
+ declare const DEFAULT_ATTENTION_BUDGET: AttentionBudget;
225
+ interface AttentionSlot {
226
+ category: 'global_principle' | 'memory' | 'skill_doc';
227
+ content: string;
228
+ relevanceScore: number;
229
+ tokenEstimate: number;
230
+ }
231
+ declare function selectAttentionSlots(fills: FillResult[], intent: IntentObject, globalPrinciples: string[], skillDocs: string[], budget?: AttentionBudget): AttentionSlot[];
232
+ declare function assembleContext(slots: AttentionSlot[]): string;
233
+
234
+ declare function extractTags(data: RawData): string[];
235
+ declare function resolvePartition(sourceAgent: string): string;
236
+ declare function autoIngest(data: RawData, registry: IndexTable): Promise<string>;
237
+
238
+ /**
239
+ * Deterministic task auto-verification.
240
+ * Code tasks: run tests, pass = correct.
241
+ * Data tasks: format + field completeness validation.
242
+ */
243
+ interface VerificationRule {
244
+ type: 'regex' | 'json_schema' | 'field_presence' | 'custom';
245
+ pattern?: string;
246
+ fields?: string[];
247
+ validator?: (output: string) => boolean;
248
+ }
249
+ interface VerificationResult {
250
+ passed: boolean;
251
+ checks: Array<{
252
+ rule: string;
253
+ passed: boolean;
254
+ message?: string;
255
+ }>;
256
+ overallScore: number;
257
+ }
258
+ declare function verifyRegex(output: string, pattern: string): boolean;
259
+ declare function verifyFieldPresence(output: string, fields: string[]): {
260
+ present: string[];
261
+ missing: string[];
262
+ };
263
+ declare function verifyJsonSchema(output: string, fields: string[]): boolean;
264
+ declare function runVerification(output: string, rules: VerificationRule[]): VerificationResult;
265
+
266
+ /**
267
+ * Non-deterministic task sub-dimension evaluation.
268
+ * Instead of asking "good or bad?", decompose into judgeable sub-dimensions.
269
+ */
270
+ interface SubDimension {
271
+ name: string;
272
+ weight: number;
273
+ evaluator: 'auto' | 'agent_review' | 'human';
274
+ autoCheck?: (output: string) => number;
275
+ description?: string;
276
+ }
277
+ interface EvaluationTemplate {
278
+ id: string;
279
+ name: string;
280
+ taskTypes: string[];
281
+ dimensions: SubDimension[];
282
+ }
283
+ interface DimensionScore {
284
+ dimension: string;
285
+ score: number;
286
+ evaluator: 'auto' | 'agent_review' | 'human';
287
+ feedback?: string;
288
+ }
289
+ interface EvaluationResult {
290
+ templateId: string;
291
+ scores: DimensionScore[];
292
+ overallScore: number;
293
+ needsHumanReview: string[];
294
+ needsAgentReview: string[];
295
+ }
296
+ declare function checkWordCount(min: number, max: number): (output: string) => number;
297
+ declare function checkKeywordCoverage(keywords: string[]): (output: string) => number;
298
+ declare function checkFormatCompliance(expectedFormat: string): (output: string) => number;
299
+ declare function evaluate(output: string, template: EvaluationTemplate, agentScores?: Record<string, number>, humanScores?: Record<string, number>): EvaluationResult;
300
+ declare const TEMPLATES: Record<string, EvaluationTemplate>;
301
+
302
+ /**
303
+ * Prediction deviation learning.
304
+ * Before execution: estimate tokens / duration / steps / risk.
305
+ * After execution: compare actual values. Deviation = learning signal.
306
+ */
307
+ interface Prediction {
308
+ intentId: string;
309
+ taskType: string;
310
+ estimates: {
311
+ tokens?: number;
312
+ durationMs?: number;
313
+ steps?: number;
314
+ skillCount?: number;
315
+ };
316
+ }
317
+ interface Actual {
318
+ tokens?: number;
319
+ durationMs?: number;
320
+ steps?: number;
321
+ skillCount?: number;
322
+ }
323
+ type DeviationLevel = 'normal' | 'mild' | 'significant' | 'reverse';
324
+ interface DeviationResult {
325
+ dimension: string;
326
+ estimated: number;
327
+ actual: number;
328
+ ratio: number;
329
+ level: DeviationLevel;
330
+ alpha: number;
331
+ newEstimate: number;
332
+ }
333
+ interface PredictionAnalysis {
334
+ intentId: string;
335
+ taskType: string;
336
+ deviations: DeviationResult[];
337
+ needsModelUpdate: boolean;
338
+ }
339
+ declare function analyzePrediction(prediction: Prediction, actual: Actual): PredictionAnalysis;
340
+ declare class DeviationAccumulator {
341
+ private counts;
342
+ record(taskType: string, dimension: string, level: DeviationLevel): boolean;
343
+ getCount(taskType: string, dimension: string): number;
344
+ reset(taskType: string, dimension: string): void;
345
+ }
346
+
347
+ /**
348
+ * Structured human feedback collection.
349
+ * Checkbox-style templates instead of open-ended text. Lower friction = more feedback.
350
+ */
351
+ interface FeedbackDimension {
352
+ id: string;
353
+ label: string;
354
+ type: 'rating' | 'select' | 'boolean';
355
+ options?: string[];
356
+ scale?: [number, number];
357
+ }
358
+ interface FeedbackTemplate {
359
+ id: string;
360
+ taskType: string;
361
+ dimensions: FeedbackDimension[];
362
+ }
363
+ interface FeedbackResponse {
364
+ templateId: string;
365
+ taskId: string;
366
+ intentId: string;
367
+ responses: Record<string, number | string | boolean>;
368
+ timestamp: string;
369
+ freeText?: string;
370
+ }
371
+ interface FeedbackSummary {
372
+ taskType: string;
373
+ totalResponses: number;
374
+ dimensionAverages: Record<string, number>;
375
+ commonIssues: string[];
376
+ }
377
+ declare const FEEDBACK_TEMPLATES: Record<string, FeedbackTemplate>;
378
+ declare function selectTemplate(taskType: string): FeedbackTemplate;
379
+ declare function normalizeFeedback(response: FeedbackResponse, template: FeedbackTemplate): Record<string, number>;
380
+ declare function summarizeFeedback(responses: FeedbackResponse[], template: FeedbackTemplate): FeedbackSummary;
381
+
382
+ /**
383
+ * Attribution Analysis Engine.
384
+ * When task results are poor, pinpoint which stage caused the problem.
385
+ */
386
+
387
+ type AttributionTarget = 'intent_recognition' | 'skill_selection' | 'memory_retrieval' | 'output_quality' | 'unknown';
388
+ interface Attribution {
389
+ target: AttributionTarget;
390
+ confidence: number;
391
+ evidence: string;
392
+ isHypothesis: boolean;
393
+ }
394
+ interface AttributionResult {
395
+ intentId: string;
396
+ attributions: Attribution[];
397
+ primaryCause: AttributionTarget;
398
+ actionable: boolean;
399
+ }
400
+ declare function attributeIntentError(intent: IntentObject, groundTruth: {
401
+ task_type: string;
402
+ domain: string;
403
+ }): Attribution | null;
404
+ declare function attributeRetrievalError(trace: RetrievalTrace, expectedHits: string[]): Attribution | null;
405
+ declare function attributeOutputError(evaluation: EvaluationResult): Attribution | null;
406
+ declare function analyzeAttribution(intent: IntentObject, trace: RetrievalTrace, evaluation: EvaluationResult, groundTruth?: {
407
+ task_type: string;
408
+ domain: string;
409
+ }, expectedHits?: string[]): AttributionResult;
410
+
411
+ /**
412
+ * Experience routing: write learnings to the right place.
413
+ * - Professional knowledge / pitfalls → Skill docs (skill partition)
414
+ * - User preferences → User memory (personal partition)
415
+ * - Task type experience → Task memory (domain partition)
416
+ * - Cross-scenario rules → Shared knowledge (global partition)
417
+ */
418
+
419
+ type RouteTarget = ExperienceEntry['target'];
420
+ interface RoutingDecision {
421
+ target: RouteTarget;
422
+ partition: string;
423
+ reason: string;
424
+ }
425
+ declare function routeExperience(attribution: Attribution, taskType: string, domain: string, sourceAgent: string): RoutingDecision;
426
+ declare function createExperienceEntry(attribution: Attribution, routing: RoutingDecision, taskType: string, domain: string, sourceAgent: string, traceId: string): ExperienceEntry;
427
+
428
+ /**
429
+ * Two-layer distillation mechanism.
430
+ * Layer 1: Concrete experiences (with environment tags)
431
+ * Layer 2: Abstract methods (stripped of environment specifics)
432
+ *
433
+ * Concrete: "中文广告标题社交媒体场景下 15 字以内效果最好"
434
+ * Abstract: "标题类内容存在最优长度区间,应基于历史数据找到该区间"
435
+ */
436
+
437
+ interface DistillationResult {
438
+ abstractEntry: ExperienceEntry;
439
+ sourceIds: string[];
440
+ pattern: string;
441
+ }
442
+ /**
443
+ * Group concrete experiences by task_type + conclusion pattern.
444
+ * When 3+ experiences share a pattern, they're candidates for abstraction.
445
+ */
446
+ declare function findDistillationCandidates(experiences: ExperienceEntry[], minGroupSize?: number): Map<string, ExperienceEntry[]>;
447
+ /**
448
+ * Strip environment-specific details from a concrete experience.
449
+ * Remove specific numbers, languages, platforms, etc.
450
+ */
451
+ declare function abstractify(conclusion: string, action: string): {
452
+ conclusion: string;
453
+ action: string;
454
+ };
455
+ /**
456
+ * Distill a group of concrete experiences into one abstract method.
457
+ */
458
+ declare function distillGroup(group: ExperienceEntry[]): DistillationResult | null;
459
+ /**
460
+ * Full distillation pass: find candidates and produce abstractions.
461
+ */
462
+ declare function runDistillation(experiences: ExperienceEntry[], minGroupSize?: number): DistillationResult[];
463
+
464
+ /**
465
+ * Cross-agent propagation + verification weighting.
466
+ * - Verified experiences get higher weight
467
+ * - Contradicted experiences auto-downweight
468
+ * - All agents share a global knowledge partition
469
+ */
470
+
471
+ interface PropagationEvent {
472
+ experienceId: string;
473
+ fromAgent: string;
474
+ toPartition: string;
475
+ action: 'publish' | 'verify' | 'challenge';
476
+ timestamp: string;
477
+ }
478
+ /**
479
+ * Publish a verified experience to global partition for other agents.
480
+ */
481
+ declare function publishToGlobal(experience: ExperienceEntry): PropagationEvent;
482
+ /**
483
+ * Verify an experience: another agent confirms it works.
484
+ * Increases verified_count and confidence.
485
+ */
486
+ declare function verifyExperience(experience: ExperienceEntry, verifyingAgent: string): {
487
+ updated: ExperienceEntry;
488
+ event: PropagationEvent;
489
+ };
490
+ /**
491
+ * Challenge an experience: new evidence contradicts it.
492
+ * Decreases confidence and marks for review.
493
+ */
494
+ declare function challengeExperience(experience: ExperienceEntry, challengingAgent: string, evidence: string): {
495
+ updated: ExperienceEntry;
496
+ event: PropagationEvent;
497
+ };
498
+ /**
499
+ * Rank experiences by reliability for retrieval.
500
+ * verified_count * confidence = effective weight.
501
+ */
502
+ declare function rankByReliability(experiences: ExperienceEntry[]): ExperienceEntry[];
503
+ /**
504
+ * Filter experiences that are safe to propagate.
505
+ * Must be active, confidence >= 0.5, verified at least once.
506
+ */
507
+ declare function filterPropagatable(experiences: ExperienceEntry[]): ExperienceEntry[];
508
+
509
+ /**
510
+ * Rollback mechanism.
511
+ * Track post-write task performance. If same-type task success rate drops,
512
+ * auto-rollback the most recent experience writes.
513
+ */
514
+
515
+ interface PerformanceWindow {
516
+ taskType: string;
517
+ recentScores: number[];
518
+ baselineAvg: number;
519
+ currentAvg: number;
520
+ }
521
+ interface RollbackDecision {
522
+ shouldRollback: boolean;
523
+ experienceId: string;
524
+ reason: string;
525
+ baselineAvg: number;
526
+ currentAvg: number;
527
+ degradation: number;
528
+ }
529
+ /**
530
+ * Check if performance has degraded after an experience was written.
531
+ * Threshold: 15% drop triggers rollback.
532
+ */
533
+ declare function checkPerformanceDegradation(window: PerformanceWindow, degradationThreshold?: number): boolean;
534
+ /**
535
+ * Decide whether to rollback an experience.
536
+ */
537
+ declare function decideRollback(experience: ExperienceEntry, window: PerformanceWindow, threshold?: number): RollbackDecision;
538
+ /**
539
+ * Execute rollback: mark experience as rolled_back.
540
+ * If this experience was used to create abstractions, mark those as "evidence chain incomplete".
541
+ */
542
+ declare function executeRollback(experience: ExperienceEntry, relatedAbstracts?: ExperienceEntry[]): {
543
+ rolledBack: ExperienceEntry;
544
+ affectedAbstracts: ExperienceEntry[];
545
+ };
546
+ /**
547
+ * Calculate performance window from a list of recent scores.
548
+ */
549
+ declare function buildPerformanceWindow(taskType: string, allScores: number[], splitAt: number): PerformanceWindow;
550
+
551
+ /**
552
+ * Agent-to-agent compressed encoding communication.
553
+ * First communication uses full JSON, high-frequency values auto-register short codes.
554
+ * Codec table shared across all agents via registry.
555
+ */
556
+ interface CodecEntry {
557
+ shortCode: string;
558
+ fullValue: string;
559
+ usageCount: number;
560
+ }
561
+ declare class Codec {
562
+ private codeToValue;
563
+ private valueToCode;
564
+ private usageCounts;
565
+ private nextCodeId;
566
+ private readonly autoRegisterThreshold;
567
+ constructor(options?: {
568
+ autoRegisterThreshold?: number;
569
+ });
570
+ /**
571
+ * Register a short code for a frequently used value.
572
+ */
573
+ register(fullValue: string, shortCode?: string): string;
574
+ /**
575
+ * Record usage of a value. Auto-registers after threshold.
576
+ * Returns short code if registered, undefined otherwise.
577
+ */
578
+ recordUsage(value: string): string | undefined;
579
+ /**
580
+ * Encode a message: replace registered full values with short codes.
581
+ */
582
+ encode(message: Record<string, string>): Record<string, string>;
583
+ /**
584
+ * Decode a message: replace short codes with full values.
585
+ */
586
+ decode(message: Record<string, string>): Record<string, string>;
587
+ /**
588
+ * Get all registered entries for persistence.
589
+ */
590
+ getEntries(): CodecEntry[];
591
+ /**
592
+ * Load entries from persistence.
593
+ */
594
+ loadEntries(entries: CodecEntry[]): void;
595
+ /**
596
+ * Cleanup: remove low-frequency codes.
597
+ */
598
+ cleanup(minUsage?: number): number;
599
+ }
600
+
601
+ /**
602
+ * Evaluation Template Market.
603
+ * Users and community contribute task evaluation templates.
604
+ * Templates define sub-dimension breakdown, auto-check rules, agent review rules.
605
+ */
606
+
607
+ interface TemplateSubmission {
608
+ template: EvaluationTemplate;
609
+ author: string;
610
+ description: string;
611
+ submittedAt: string;
612
+ status: 'pending' | 'approved' | 'rejected';
613
+ }
614
+ interface TemplateRating {
615
+ templateId: string;
616
+ usageCount: number;
617
+ avgEffectiveness: number;
618
+ upvotes: number;
619
+ downvotes: number;
620
+ }
621
+ interface MarketQuery {
622
+ taskType?: string;
623
+ minRating?: number;
624
+ limit?: number;
625
+ sortBy?: 'rating' | 'usage' | 'newest';
626
+ }
627
+ declare class TemplateMarket {
628
+ private templates;
629
+ private ratings;
630
+ /**
631
+ * Submit a new template for review.
632
+ */
633
+ submit(submission: TemplateSubmission): string;
634
+ /**
635
+ * Approve a pending template.
636
+ */
637
+ approve(templateId: string): boolean;
638
+ /**
639
+ * Reject a pending template.
640
+ */
641
+ reject(templateId: string): boolean;
642
+ /**
643
+ * Search templates by criteria.
644
+ */
645
+ search(query?: MarketQuery): Array<{
646
+ submission: TemplateSubmission;
647
+ rating: TemplateRating;
648
+ }>;
649
+ /**
650
+ * Record a template usage and update effectiveness.
651
+ */
652
+ recordUsage(templateId: string, effectiveness: number): void;
653
+ /**
654
+ * Upvote a template.
655
+ */
656
+ upvote(templateId: string): void;
657
+ /**
658
+ * Downvote a template.
659
+ */
660
+ downvote(templateId: string): void;
661
+ /**
662
+ * Get a specific template by ID.
663
+ */
664
+ get(templateId: string): TemplateSubmission | undefined;
665
+ /**
666
+ * Get rating for a template.
667
+ */
668
+ getRating(templateId: string): TemplateRating | undefined;
669
+ /**
670
+ * List all templates (including pending/rejected for admin).
671
+ */
672
+ listAll(): TemplateSubmission[];
673
+ }
674
+
675
+ /**
676
+ * Industry preset packs for cold-start reduction.
677
+ * Pre-built knowledge, rules, and templates for common industries.
678
+ */
679
+
680
+ interface IndustryPack {
681
+ id: string;
682
+ name: string;
683
+ industry: string;
684
+ description: string;
685
+ knowledge: Array<{
686
+ summary: string;
687
+ tags: string[];
688
+ partition: string;
689
+ }>;
690
+ templates: EvaluationTemplate[];
691
+ rules: Array<{
692
+ field: string;
693
+ value: string;
694
+ source: string;
695
+ }>;
696
+ }
697
+ declare const MARKETING_PACK: IndustryPack;
698
+ declare const SOFTWARE_DEV_PACK: IndustryPack;
699
+ declare const CONTENT_PACK: IndustryPack;
700
+ declare const ALL_PACKS: Record<string, IndustryPack>;
701
+ /**
702
+ * Install an industry pack: seed registry with knowledge + register templates.
703
+ */
704
+ declare function getPackKnowledge(packId: string): IndustryPack['knowledge'];
705
+ declare function getPackTemplates(packId: string): EvaluationTemplate[];
706
+ declare function getPackRules(packId: string): IndustryPack['rules'];
707
+ declare function listPacks(): Array<{
708
+ id: string;
709
+ name: string;
710
+ industry: string;
711
+ description: string;
712
+ }>;
713
+
714
+ /**
715
+ * Visualization dashboard data provider.
716
+ * Aggregates retrieval traces, attribution analysis, experience flow,
717
+ * and cross-agent propagation into dashboard-ready data structures.
718
+ */
719
+
720
+ interface DashboardOverview {
721
+ totalTasks: number;
722
+ totalExperiences: number;
723
+ activeExperiences: number;
724
+ hypotheses: number;
725
+ rolledBack: number;
726
+ abstractMethods: number;
727
+ avgConfidence: number;
728
+ }
729
+ interface RetrievalStats {
730
+ totalQueries: number;
731
+ avgHitsPerQuery: number;
732
+ avgInjectedPerQuery: number;
733
+ topPartitions: Array<{
734
+ partition: string;
735
+ count: number;
736
+ }>;
737
+ topTags: Array<{
738
+ tag: string;
739
+ count: number;
740
+ }>;
741
+ }
742
+ interface AttributionBreakdown {
743
+ total: number;
744
+ byTarget: Record<AttributionTarget, number>;
745
+ actionableRate: number;
746
+ topIssues: Array<{
747
+ target: AttributionTarget;
748
+ count: number;
749
+ }>;
750
+ }
751
+ interface DeviationTrend {
752
+ taskType: string;
753
+ dimension: string;
754
+ avgRatio: number;
755
+ levelDistribution: Record<DeviationLevel, number>;
756
+ }
757
+ interface PropagationFlow {
758
+ totalPublished: number;
759
+ totalVerified: number;
760
+ totalChallenged: number;
761
+ avgVerifiedCount: number;
762
+ }
763
+ declare function computeOverview(experiences: ExperienceEntry[]): DashboardOverview;
764
+ declare function computeRetrievalStats(traces: RetrievalTrace[]): RetrievalStats;
765
+ declare function computeAttributionBreakdown(attributions: AttributionResult[]): AttributionBreakdown;
766
+ declare function computeDeviationTrends(analyses: PredictionAnalysis[]): DeviationTrend[];
767
+ declare function computePropagationFlow(experiences: ExperienceEntry[]): PropagationFlow;
768
+
769
+ declare function safeguard<T>(fn: () => Promise<T>, fallbackValue: T, options?: {
770
+ logError?: boolean;
771
+ }): Promise<T>;
772
+
773
+ export { ALL_PACKS, type Actual, type AgentConfig, type AgentEvolveAdapter, type AttentionBudget, type AttentionSlot, type Attribution, type AttributionBreakdown, type AttributionResult, type AttributionTarget, CONTENT_PACK, Codec, type CodecEntry, type ConfirmThreshold, type Conflict, DEFAULT_ATTENTION_BUDGET, DEFAULT_ROUGH_INTENT, DEFAULT_THRESHOLD, type DashboardOverview, DeviationAccumulator, type DeviationLevel, type DeviationResult, type DeviationTrend, type DimensionScore, type DistillationResult, EXTRACTION_PROMPT, type EnhancedContext, type EvaluationResult, type EvaluationTemplate, type ExperienceEntry, FEEDBACK_TEMPLATES, type FeedbackDimension, type FeedbackResponse, type FeedbackSummary, type FeedbackTemplate, type FillResult, IndexTable, type IndustryPack, type IntentObject, MARKETING_PACK, type MarketQuery, type PerformanceWindow, type PipelineConfig, type PipelineResult, type Prediction, type PredictionAnalysis, type PriorityRules, type PropagationEvent, type PropagationFlow, type RawData, type RegistryEntry, type RegistryInsertInput, type RegistryUpdateInput, type ResolvedFills, type RetrievalStats, type RetrievalTrace, type RollbackDecision, type RoughIntent, type RouteTarget, type RoutingDecision, SOFTWARE_DEV_PACK, type SearchFilters, type Source, type SubDimension, TEMPLATES, TemplateMarket, type TemplateRating, type TemplateSubmission, type UserMessage, type VerificationResult, type VerificationRule, abstractify, analyzeAttribution, analyzePrediction, assembleContext, attributeIntentError, attributeOutputError, attributeRetrievalError, autoIngest, buildPerformanceWindow, buildQuestions, buildSourceTrace, buildTrace, calcConfidence, challengeExperience, checkFormatCompliance, checkKeywordCoverage, checkPerformanceDegradation, checkWordCount, computeAttributionBreakdown, computeDeviationTrends, computeOverview, computePropagationFlow, computeRetrievalStats, confirmIfNeeded, conflictDetect, contextFill, contextFillRefine, createExperienceEntry, decideRollback, dedup, distillGroup, evaluate, executeRollback, extractConstraints, extractKeywords, extractTags, filterPropagatable, findDistillationCandidates, getPackKnowledge, getPackRules, getPackTemplates, groupByField, intentPipeline, isConflicting, listPacks, normalizeFeedback, parseIntentBlock, publishToGlobal, rankByReliability, resolvePartition, resolveSource, routeExperience, runDistillation, runVerification, safeguard, selectAttentionSlots, selectTemplate, stripIntentBlock, structure, summarizeFeedback, updateIntent, verifyExperience, verifyFieldPresence, verifyJsonSchema, verifyRegex };