@framers/agentos 0.1.121 → 0.1.123

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.
Files changed (136) hide show
  1. package/dist/api/TextToolCallParser.d.ts +61 -0
  2. package/dist/api/TextToolCallParser.d.ts.map +1 -0
  3. package/dist/api/TextToolCallParser.js +137 -0
  4. package/dist/api/TextToolCallParser.js.map +1 -0
  5. package/dist/api/agent.d.ts +7 -0
  6. package/dist/api/agent.d.ts.map +1 -1
  7. package/dist/api/agent.js +1 -0
  8. package/dist/api/agent.js.map +1 -1
  9. package/dist/api/generateText.d.ts +105 -0
  10. package/dist/api/generateText.d.ts.map +1 -1
  11. package/dist/api/generateText.js +191 -2
  12. package/dist/api/generateText.js.map +1 -1
  13. package/dist/cognitive_substrate/GMI.d.ts.map +1 -1
  14. package/dist/cognitive_substrate/GMI.js +27 -1
  15. package/dist/cognitive_substrate/GMI.js.map +1 -1
  16. package/dist/cognitive_substrate/IGMI.d.ts +5 -0
  17. package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
  18. package/dist/cognitive_substrate/IGMI.js.map +1 -1
  19. package/dist/emergent/AdaptPersonalityTool.d.ts +142 -0
  20. package/dist/emergent/AdaptPersonalityTool.d.ts.map +1 -0
  21. package/dist/emergent/AdaptPersonalityTool.js +198 -0
  22. package/dist/emergent/AdaptPersonalityTool.js.map +1 -0
  23. package/dist/emergent/CreateWorkflowTool.d.ts +182 -0
  24. package/dist/emergent/CreateWorkflowTool.d.ts.map +1 -0
  25. package/dist/emergent/CreateWorkflowTool.js +330 -0
  26. package/dist/emergent/CreateWorkflowTool.js.map +1 -0
  27. package/dist/emergent/EmergentCapabilityEngine.d.ts +68 -0
  28. package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
  29. package/dist/emergent/EmergentCapabilityEngine.js +99 -0
  30. package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
  31. package/dist/emergent/ManageSkillsTool.d.ts +154 -0
  32. package/dist/emergent/ManageSkillsTool.d.ts.map +1 -0
  33. package/dist/emergent/ManageSkillsTool.js +241 -0
  34. package/dist/emergent/ManageSkillsTool.js.map +1 -0
  35. package/dist/emergent/PersonalityMutationStore.d.ts +183 -0
  36. package/dist/emergent/PersonalityMutationStore.d.ts.map +1 -0
  37. package/dist/emergent/PersonalityMutationStore.js +222 -0
  38. package/dist/emergent/PersonalityMutationStore.js.map +1 -0
  39. package/dist/emergent/SelfEvaluateTool.d.ts +199 -0
  40. package/dist/emergent/SelfEvaluateTool.d.ts.map +1 -0
  41. package/dist/emergent/SelfEvaluateTool.js +410 -0
  42. package/dist/emergent/SelfEvaluateTool.js.map +1 -0
  43. package/dist/emergent/SelfImprovementConfig.d.ts +177 -0
  44. package/dist/emergent/SelfImprovementConfig.d.ts.map +1 -0
  45. package/dist/emergent/SelfImprovementConfig.js +43 -0
  46. package/dist/emergent/SelfImprovementConfig.js.map +1 -0
  47. package/dist/emergent/index.d.ts +8 -0
  48. package/dist/emergent/index.d.ts.map +1 -1
  49. package/dist/emergent/index.js +6 -0
  50. package/dist/emergent/index.js.map +1 -1
  51. package/dist/emergent/types.d.ts +9 -0
  52. package/dist/emergent/types.d.ts.map +1 -1
  53. package/dist/emergent/types.js.map +1 -1
  54. package/dist/memory/AgentMemory.d.ts +2 -2
  55. package/dist/memory/AgentMemory.d.ts.map +1 -1
  56. package/dist/memory/AgentMemory.js +4 -3
  57. package/dist/memory/AgentMemory.js.map +1 -1
  58. package/dist/memory/consolidation/ConsolidationLoop.d.ts +31 -4
  59. package/dist/memory/consolidation/ConsolidationLoop.d.ts.map +1 -1
  60. package/dist/memory/consolidation/ConsolidationLoop.js +112 -69
  61. package/dist/memory/consolidation/ConsolidationLoop.js.map +1 -1
  62. package/dist/memory/facade/Memory.d.ts +12 -6
  63. package/dist/memory/facade/Memory.d.ts.map +1 -1
  64. package/dist/memory/facade/Memory.js +216 -212
  65. package/dist/memory/facade/Memory.js.map +1 -1
  66. package/dist/memory/facade/types.d.ts +11 -1
  67. package/dist/memory/facade/types.d.ts.map +1 -1
  68. package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts +7 -10
  69. package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts.map +1 -1
  70. package/dist/memory/feedback/RetrievalFeedbackSignal.js +40 -36
  71. package/dist/memory/feedback/RetrievalFeedbackSignal.js.map +1 -1
  72. package/dist/memory/io/ChatGptImporter.d.ts.map +1 -1
  73. package/dist/memory/io/ChatGptImporter.js +24 -18
  74. package/dist/memory/io/ChatGptImporter.js.map +1 -1
  75. package/dist/memory/io/CsvImporter.d.ts.map +1 -1
  76. package/dist/memory/io/CsvImporter.js +21 -8
  77. package/dist/memory/io/CsvImporter.js.map +1 -1
  78. package/dist/memory/io/JsonExporter.d.ts.map +1 -1
  79. package/dist/memory/io/JsonExporter.js +6 -17
  80. package/dist/memory/io/JsonExporter.js.map +1 -1
  81. package/dist/memory/io/JsonImporter.d.ts +3 -0
  82. package/dist/memory/io/JsonImporter.d.ts.map +1 -1
  83. package/dist/memory/io/JsonImporter.js +58 -29
  84. package/dist/memory/io/JsonImporter.js.map +1 -1
  85. package/dist/memory/io/MarkdownExporter.d.ts.map +1 -1
  86. package/dist/memory/io/MarkdownExporter.js +1 -4
  87. package/dist/memory/io/MarkdownExporter.js.map +1 -1
  88. package/dist/memory/io/MarkdownImporter.d.ts.map +1 -1
  89. package/dist/memory/io/MarkdownImporter.js +12 -7
  90. package/dist/memory/io/MarkdownImporter.js.map +1 -1
  91. package/dist/memory/io/ObsidianExporter.d.ts +14 -9
  92. package/dist/memory/io/ObsidianExporter.d.ts.map +1 -1
  93. package/dist/memory/io/ObsidianExporter.js +35 -23
  94. package/dist/memory/io/ObsidianExporter.js.map +1 -1
  95. package/dist/memory/io/ObsidianImporter.d.ts.map +1 -1
  96. package/dist/memory/io/ObsidianImporter.js +34 -27
  97. package/dist/memory/io/ObsidianImporter.js.map +1 -1
  98. package/dist/memory/io/SqliteExporter.d.ts +1 -2
  99. package/dist/memory/io/SqliteExporter.d.ts.map +1 -1
  100. package/dist/memory/io/SqliteExporter.js +2 -3
  101. package/dist/memory/io/SqliteExporter.js.map +1 -1
  102. package/dist/memory/io/SqliteImporter.d.ts +3 -0
  103. package/dist/memory/io/SqliteImporter.d.ts.map +1 -1
  104. package/dist/memory/io/SqliteImporter.js +62 -27
  105. package/dist/memory/io/SqliteImporter.js.map +1 -1
  106. package/dist/memory/store/SqliteBrain.d.ts +84 -24
  107. package/dist/memory/store/SqliteBrain.d.ts.map +1 -1
  108. package/dist/memory/store/SqliteBrain.js +139 -55
  109. package/dist/memory/store/SqliteBrain.js.map +1 -1
  110. package/dist/memory/store/SqliteKnowledgeGraph.d.ts +6 -2
  111. package/dist/memory/store/SqliteKnowledgeGraph.d.ts.map +1 -1
  112. package/dist/memory/store/SqliteKnowledgeGraph.js +94 -120
  113. package/dist/memory/store/SqliteKnowledgeGraph.js.map +1 -1
  114. package/dist/memory/store/SqliteMemoryGraph.d.ts +4 -5
  115. package/dist/memory/store/SqliteMemoryGraph.d.ts.map +1 -1
  116. package/dist/memory/store/SqliteMemoryGraph.js +31 -41
  117. package/dist/memory/store/SqliteMemoryGraph.js.map +1 -1
  118. package/dist/memory/tools/MemoryAddTool.d.ts.map +1 -1
  119. package/dist/memory/tools/MemoryAddTool.js +12 -16
  120. package/dist/memory/tools/MemoryAddTool.js.map +1 -1
  121. package/dist/memory/tools/MemoryDeleteTool.d.ts.map +1 -1
  122. package/dist/memory/tools/MemoryDeleteTool.js +1 -3
  123. package/dist/memory/tools/MemoryDeleteTool.js.map +1 -1
  124. package/dist/memory/tools/MemoryMergeTool.d.ts.map +1 -1
  125. package/dist/memory/tools/MemoryMergeTool.js +13 -22
  126. package/dist/memory/tools/MemoryMergeTool.js.map +1 -1
  127. package/dist/memory/tools/MemorySearchTool.js +4 -4
  128. package/dist/memory/tools/MemorySearchTool.js.map +1 -1
  129. package/dist/memory/tools/MemoryUpdateTool.d.ts.map +1 -1
  130. package/dist/memory/tools/MemoryUpdateTool.js +10 -18
  131. package/dist/memory/tools/MemoryUpdateTool.js.map +1 -1
  132. package/dist/orchestration/runtime/LoopController.d.ts +7 -0
  133. package/dist/orchestration/runtime/LoopController.d.ts.map +1 -1
  134. package/dist/orchestration/runtime/LoopController.js +7 -0
  135. package/dist/orchestration/runtime/LoopController.js.map +1 -1
  136. package/package.json +1 -1
@@ -0,0 +1,222 @@
1
+ /**
2
+ * @fileoverview SQLite persistence for personality mutations with
3
+ * Ebbinghaus-style strength decay.
4
+ *
5
+ * Mutations persist across sessions and gradually fade toward baseline
6
+ * unless reinforced by repeated adaptation. The ConsolidationLoop calls
7
+ * {@link PersonalityMutationStore.decayAll} each cycle to reduce mutation
8
+ * strengths; mutations whose strength drops below the 0.1 threshold are
9
+ * pruned automatically.
10
+ *
11
+ * Uses the same {@link IStorageAdapter} interface as EmergentToolRegistry,
12
+ * keeping storage concerns decoupled from specific SQLite drivers.
13
+ *
14
+ * @module @framers/agentos/emergent/PersonalityMutationStore
15
+ */
16
+ // ============================================================================
17
+ // STORE
18
+ // ============================================================================
19
+ /**
20
+ * SQLite-backed persistence layer for personality mutations with decay.
21
+ *
22
+ * Follows the same `ensureSchema()` pattern as {@link EmergentToolRegistry}:
23
+ * a cached promise guards against concurrent DDL execution, and all DML
24
+ * methods await schema readiness before proceeding.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const store = new PersonalityMutationStore(sqliteAdapter);
29
+ *
30
+ * // Record a mutation
31
+ * const id = await store.record({
32
+ * agentId: 'agent-42',
33
+ * trait: 'openness',
34
+ * delta: 0.1,
35
+ * reasoning: 'User prefers creative responses',
36
+ * baselineValue: 0.7,
37
+ * mutatedValue: 0.8,
38
+ * });
39
+ *
40
+ * // Get strength-weighted effective deltas
41
+ * const deltas = await store.getEffectiveDeltas('agent-42');
42
+ * // => { openness: 0.1 } (strength is 1.0 initially)
43
+ *
44
+ * // Decay all mutations by 5%
45
+ * const { decayed, pruned } = await store.decayAll(0.05);
46
+ * ```
47
+ */
48
+ export class PersonalityMutationStore {
49
+ /**
50
+ * Create a new PersonalityMutationStore.
51
+ *
52
+ * @param db - A storage adapter implementing the {@link IStorageAdapter}
53
+ * interface. The same adapter used by EmergentToolRegistry can be reused.
54
+ */
55
+ constructor(db) {
56
+ /**
57
+ * Cached schema initialization promise.
58
+ * Ensures DDL runs exactly once, even under concurrent access.
59
+ */
60
+ this.schemaReady = null;
61
+ this.db = db;
62
+ }
63
+ // --------------------------------------------------------------------------
64
+ // SCHEMA
65
+ // --------------------------------------------------------------------------
66
+ /**
67
+ * Idempotent schema initialization.
68
+ *
69
+ * Creates the `personality_mutations` table and its agent/trait index if
70
+ * they don't already exist. Uses the adapter's `exec()` method when
71
+ * available (for multi-statement DDL), falling back to individual `run()`
72
+ * calls for adapters that don't support it.
73
+ *
74
+ * @returns A promise that resolves when the schema is ready.
75
+ */
76
+ async ensureSchema() {
77
+ if (!this.schemaReady) {
78
+ this.schemaReady = (async () => {
79
+ const ddl = `
80
+ CREATE TABLE IF NOT EXISTS personality_mutations (
81
+ id TEXT PRIMARY KEY,
82
+ agent_id TEXT NOT NULL,
83
+ trait TEXT NOT NULL,
84
+ delta REAL NOT NULL,
85
+ reasoning TEXT NOT NULL,
86
+ baseline_value REAL NOT NULL,
87
+ mutated_value REAL NOT NULL,
88
+ strength REAL NOT NULL DEFAULT 1.0,
89
+ created_at BIGINT NOT NULL
90
+ );
91
+ CREATE INDEX IF NOT EXISTS idx_personality_mutations_agent
92
+ ON personality_mutations(agent_id, trait);
93
+ `;
94
+ if (this.db.exec) {
95
+ await this.db.exec(ddl);
96
+ }
97
+ else {
98
+ // Split on semicolons and execute each non-empty statement individually.
99
+ for (const stmt of ddl.split(';').filter((s) => s.trim())) {
100
+ await this.db.run(stmt);
101
+ }
102
+ }
103
+ })();
104
+ }
105
+ return this.schemaReady;
106
+ }
107
+ // --------------------------------------------------------------------------
108
+ // RECORD
109
+ // --------------------------------------------------------------------------
110
+ /**
111
+ * Record a new personality mutation.
112
+ *
113
+ * Inserts a mutation record with initial strength of 1.0 and the current
114
+ * timestamp. The mutation ID is generated deterministically from the
115
+ * current time and a random suffix.
116
+ *
117
+ * @param input - The mutation parameters (agent, trait, delta, reasoning, values).
118
+ * @returns The generated mutation ID.
119
+ */
120
+ async record(input) {
121
+ await this.ensureSchema();
122
+ const id = `pm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
123
+ await this.db.run(`INSERT INTO personality_mutations
124
+ (id, agent_id, trait, delta, reasoning, baseline_value, mutated_value, strength, created_at)
125
+ VALUES (?, ?, ?, ?, ?, ?, ?, 1.0, ?)`, [
126
+ id,
127
+ input.agentId,
128
+ input.trait,
129
+ input.delta,
130
+ input.reasoning,
131
+ input.baselineValue,
132
+ input.mutatedValue,
133
+ Date.now(),
134
+ ]);
135
+ return id;
136
+ }
137
+ // --------------------------------------------------------------------------
138
+ // LOAD
139
+ // --------------------------------------------------------------------------
140
+ /**
141
+ * Load all active mutations for a given agent.
142
+ *
143
+ * Returns only mutations whose strength is above the 0.1 pruning threshold,
144
+ * ordered by creation time (newest first).
145
+ *
146
+ * @param agentId - The agent whose mutations to load.
147
+ * @returns An array of {@link PersonalityMutation} records.
148
+ */
149
+ async loadForAgent(agentId) {
150
+ await this.ensureSchema();
151
+ const rows = await this.db.all('SELECT * FROM personality_mutations WHERE agent_id = ? AND strength > 0.1 ORDER BY created_at DESC', [agentId]);
152
+ return rows.map((r) => ({
153
+ id: r.id,
154
+ agentId: r.agent_id,
155
+ trait: r.trait,
156
+ delta: r.delta,
157
+ reasoning: r.reasoning,
158
+ baselineValue: r.baseline_value,
159
+ mutatedValue: r.mutated_value,
160
+ strength: r.strength,
161
+ createdAt: r.created_at,
162
+ }));
163
+ }
164
+ // --------------------------------------------------------------------------
165
+ // EFFECTIVE DELTAS
166
+ // --------------------------------------------------------------------------
167
+ /**
168
+ * Compute the effective (strength-weighted) delta for each trait.
169
+ *
170
+ * For each active mutation, multiplies the raw delta by the mutation's
171
+ * current strength, then sums per trait. This gives a realistic picture
172
+ * of how much each trait has drifted from baseline, accounting for decay.
173
+ *
174
+ * @param agentId - The agent whose effective deltas to compute.
175
+ * @returns A map of trait name to effective delta (sum of `delta * strength`).
176
+ */
177
+ async getEffectiveDeltas(agentId) {
178
+ const mutations = await this.loadForAgent(agentId);
179
+ const deltas = {};
180
+ for (const m of mutations) {
181
+ deltas[m.trait] = (deltas[m.trait] ?? 0) + m.delta * m.strength;
182
+ }
183
+ return deltas;
184
+ }
185
+ // --------------------------------------------------------------------------
186
+ // DECAY
187
+ // --------------------------------------------------------------------------
188
+ /**
189
+ * Decay all active mutations by the given rate and prune expired ones.
190
+ *
191
+ * For each mutation with strength above 0.1:
192
+ * - Subtracts `rate` from its strength.
193
+ * - If the new strength is at or below 0.1, the mutation is deleted (pruned).
194
+ * - Otherwise, the strength is updated in place.
195
+ *
196
+ * This implements Ebbinghaus-style forgetting: mutations that aren't
197
+ * reinforced by repeated adaptation gradually fade away.
198
+ *
199
+ * @param rate - The amount to subtract from each mutation's strength.
200
+ * Typically 0.05 (the default from SelfImprovementConfig).
201
+ * @returns A {@link DecayResult} with counts of decayed and pruned mutations.
202
+ */
203
+ async decayAll(rate) {
204
+ await this.ensureSchema();
205
+ const all = await this.db.all('SELECT id, strength FROM personality_mutations WHERE strength > 0.1', []);
206
+ let decayed = 0;
207
+ let pruned = 0;
208
+ for (const row of all) {
209
+ const newStrength = row.strength - rate;
210
+ if (newStrength <= 0.1) {
211
+ await this.db.run('DELETE FROM personality_mutations WHERE id = ?', [row.id]);
212
+ pruned++;
213
+ }
214
+ else {
215
+ await this.db.run('UPDATE personality_mutations SET strength = ? WHERE id = ?', [newStrength, row.id]);
216
+ decayed++;
217
+ }
218
+ }
219
+ return { decayed, pruned };
220
+ }
221
+ }
222
+ //# sourceMappingURL=PersonalityMutationStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersonalityMutationStore.js","sourceRoot":"","sources":["../../src/emergent/PersonalityMutationStore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@
1
+ /**
2
+ * @fileoverview SelfEvaluateTool — ITool implementation that enables agents to
3
+ * evaluate their own response quality, adjust runtime parameters, and report
4
+ * on performance drift over a session.
5
+ *
6
+ * @module @framers/agentos/emergent/SelfEvaluateTool
7
+ *
8
+ * Three actions:
9
+ * - `evaluate` — Score a response using an LLM judge (via generateText).
10
+ * - `adjust` — Tweak runtime parameters (temperature, verbosity) or
11
+ * delegate personality adjustments to {@link AdaptPersonalityTool}.
12
+ * - `report` — Aggregate session evaluation history, compute score averages,
13
+ * and list all adjustments made.
14
+ *
15
+ * The tool mutates session state during `adjust`, either by delegating to
16
+ * `adapt_personality` or by updating ephemeral runtime parameters.
17
+ */
18
+ import type { ITool, ToolExecutionResult, ToolExecutionContext, JSONSchemaObject } from '../core/tools/ITool.js';
19
+ import { generateText } from '../api/generateText.js';
20
+ import { type AdaptPersonalityTool } from './AdaptPersonalityTool.js';
21
+ /**
22
+ * Score dimensions returned by the LLM evaluation judge.
23
+ */
24
+ export interface EvaluationScores {
25
+ /** How relevant the response is to the user's query (0–1). */
26
+ relevance: number;
27
+ /** How clear and well-structured the response is (0–1). */
28
+ clarity: number;
29
+ /** How accurate the factual content is (0–1). */
30
+ accuracy: number;
31
+ /** How helpful the response is for the user's goal (0–1). */
32
+ helpfulness: number;
33
+ }
34
+ /**
35
+ * A recorded evaluation with scores and timestamp.
36
+ */
37
+ export interface EvaluationRecord {
38
+ /** The scores assigned by the LLM judge. */
39
+ scores: EvaluationScores;
40
+ /** ISO-8601 timestamp of when the evaluation was performed. */
41
+ timestamp: string;
42
+ }
43
+ /**
44
+ * A recorded parameter adjustment.
45
+ */
46
+ export interface AdjustmentRecord {
47
+ /** The parameter that was adjusted. */
48
+ param: string;
49
+ /** Value before adjustment. */
50
+ prev: unknown;
51
+ /** Value after adjustment. */
52
+ new: unknown;
53
+ /** ISO-8601 timestamp of when the adjustment was made. */
54
+ timestamp: string;
55
+ }
56
+ /**
57
+ * Memory trace stored via the optional storeMemory callback.
58
+ */
59
+ export interface MemoryTrace {
60
+ /** Trace type identifier. */
61
+ type: string;
62
+ /** Scope of the trace (e.g. 'session'). */
63
+ scope: string;
64
+ /** Serialized trace content. */
65
+ content: string;
66
+ /** Tags for categorization and retrieval. */
67
+ tags: string[];
68
+ }
69
+ /**
70
+ * Input arguments accepted by the `self_evaluate` tool.
71
+ * Discriminated on the `action` field.
72
+ */
73
+ export interface SelfEvaluateInput extends Record<string, any> {
74
+ /** The action to perform: evaluate, adjust, or report. */
75
+ action: 'evaluate' | 'adjust' | 'report';
76
+ /** The response text to evaluate (required for evaluate). */
77
+ response?: string;
78
+ /** The original user query for context (required for evaluate). */
79
+ query?: string;
80
+ /** The parameter to adjust (required for adjust). */
81
+ param?: string;
82
+ /** The new value for the parameter (required for adjust). */
83
+ value?: unknown;
84
+ /** Reasoning for personality adjustments (required when param is a personality trait). */
85
+ reasoning?: string;
86
+ }
87
+ /**
88
+ * Dependencies injected into the {@link SelfEvaluateTool} constructor.
89
+ */
90
+ export interface SelfEvaluateDeps {
91
+ /** Configuration controlling auto-adjust behaviour and evaluation limits. */
92
+ config: {
93
+ /** Whether adjustments are applied automatically after evaluations. */
94
+ autoAdjust: boolean;
95
+ /** Parameters that may be adjusted (e.g. 'temperature', 'verbosity', 'openness'). */
96
+ adjustableParams: string[];
97
+ /** Maximum number of evaluations allowed per session. */
98
+ maxEvaluationsPerSession: number;
99
+ /** Optional explicit model override for the evaluation judge. */
100
+ evaluationModel?: string;
101
+ };
102
+ /** Optional AdaptPersonalityTool for delegating personality adjustments. */
103
+ adaptPersonality?: AdaptPersonalityTool;
104
+ /** Optional callback to persist evaluation traces to long-term memory. */
105
+ storeMemory?: (trace: MemoryTrace) => Promise<void>;
106
+ /** Optional override for tests or custom judge routing. */
107
+ generateTextImpl?: typeof generateText;
108
+ }
109
+ /**
110
+ * ITool implementation enabling agents to evaluate their own responses,
111
+ * adjust runtime parameters, and generate performance reports.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const tool = new SelfEvaluateTool({
116
+ * config: {
117
+ * autoAdjust: false,
118
+ * adjustableParams: ['temperature', 'verbosity'],
119
+ * maxEvaluationsPerSession: 20,
120
+ * },
121
+ * });
122
+ *
123
+ * const result = await tool.execute({
124
+ * action: 'evaluate',
125
+ * response: 'The capital of France is Paris.',
126
+ * query: 'What is the capital of France?',
127
+ * }, context);
128
+ * ```
129
+ */
130
+ export declare class SelfEvaluateTool implements ITool<SelfEvaluateInput> {
131
+ /** @inheritdoc */
132
+ readonly id = "com.framers.emergent.self-evaluate";
133
+ /** @inheritdoc */
134
+ readonly name = "self_evaluate";
135
+ /** @inheritdoc */
136
+ readonly displayName = "Self Evaluate";
137
+ /** @inheritdoc */
138
+ readonly description: string;
139
+ /** @inheritdoc */
140
+ readonly category = "emergent";
141
+ /** @inheritdoc */
142
+ readonly hasSideEffects = true;
143
+ /** @inheritdoc */
144
+ readonly inputSchema: JSONSchemaObject;
145
+ /** Session evaluation history. */
146
+ private readonly evaluations;
147
+ /** Session adjustment history. */
148
+ private readonly adjustments;
149
+ /** Current session parameter values (non-personality). */
150
+ private readonly sessionParams;
151
+ /** Number of evaluations performed this session. */
152
+ private evalCount;
153
+ /** Injected dependencies. */
154
+ private readonly deps;
155
+ /**
156
+ * Create a new SelfEvaluateTool.
157
+ *
158
+ * @param deps - Injected dependencies including config, optional
159
+ * adaptPersonality tool, and optional memory store callback.
160
+ */
161
+ constructor(deps: SelfEvaluateDeps);
162
+ /**
163
+ * Execute the requested self-evaluation action.
164
+ *
165
+ * @param args - Action type and associated parameters.
166
+ * @param context - Tool execution context.
167
+ * @returns A {@link ToolExecutionResult} wrapping the action outcome.
168
+ */
169
+ execute(args: SelfEvaluateInput, context: ToolExecutionContext): Promise<ToolExecutionResult>;
170
+ /**
171
+ * Evaluate a response using an LLM judge and record the scores.
172
+ *
173
+ * Calls generateText with a small model to produce structured JSON scores,
174
+ * then persists the evaluation as a memory trace if storeMemory is provided.
175
+ */
176
+ private handleEvaluate;
177
+ /**
178
+ * Adjust a runtime parameter.
179
+ *
180
+ * For personality traits (openness, conscientiousness, etc.), delegates to
181
+ * the injected AdaptPersonalityTool. For non-personality params (temperature,
182
+ * verbosity), stores the value in session state.
183
+ */
184
+ private handleAdjust;
185
+ /**
186
+ * Generate a session performance report.
187
+ *
188
+ * Aggregates all evaluations, computes score averages, lists all adjustments,
189
+ * and summarizes personality drift and skill changes.
190
+ */
191
+ private handleReport;
192
+ private resolveEvaluationModel;
193
+ private parseScores;
194
+ private extractJsonPayload;
195
+ private normalizeScore;
196
+ private isPersonalityTrait;
197
+ private delegatePersonalityAdjustment;
198
+ }
199
+ //# sourceMappingURL=SelfEvaluateTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelfEvaluateTool.d.ts","sourceRoot":"","sources":["../../src/emergent/SelfEvaluateTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAgB,KAAK,oBAAoB,EAAoB,MAAM,2BAA2B,CAAC;AAMtG;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,MAAM,EAAE,gBAAgB,CAAC;IACzB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,+BA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