@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.
- package/dist/api/TextToolCallParser.d.ts +61 -0
- package/dist/api/TextToolCallParser.d.ts.map +1 -0
- package/dist/api/TextToolCallParser.js +137 -0
- package/dist/api/TextToolCallParser.js.map +1 -0
- package/dist/api/agent.d.ts +7 -0
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +1 -0
- package/dist/api/agent.js.map +1 -1
- package/dist/api/generateText.d.ts +105 -0
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +191 -2
- package/dist/api/generateText.js.map +1 -1
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/GMI.js +27 -1
- package/dist/cognitive_substrate/GMI.js.map +1 -1
- package/dist/cognitive_substrate/IGMI.d.ts +5 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/IGMI.js.map +1 -1
- package/dist/emergent/AdaptPersonalityTool.d.ts +142 -0
- package/dist/emergent/AdaptPersonalityTool.d.ts.map +1 -0
- package/dist/emergent/AdaptPersonalityTool.js +198 -0
- package/dist/emergent/AdaptPersonalityTool.js.map +1 -0
- package/dist/emergent/CreateWorkflowTool.d.ts +182 -0
- package/dist/emergent/CreateWorkflowTool.d.ts.map +1 -0
- package/dist/emergent/CreateWorkflowTool.js +330 -0
- package/dist/emergent/CreateWorkflowTool.js.map +1 -0
- package/dist/emergent/EmergentCapabilityEngine.d.ts +68 -0
- package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.js +99 -0
- package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/emergent/ManageSkillsTool.d.ts +154 -0
- package/dist/emergent/ManageSkillsTool.d.ts.map +1 -0
- package/dist/emergent/ManageSkillsTool.js +241 -0
- package/dist/emergent/ManageSkillsTool.js.map +1 -0
- package/dist/emergent/PersonalityMutationStore.d.ts +183 -0
- package/dist/emergent/PersonalityMutationStore.d.ts.map +1 -0
- package/dist/emergent/PersonalityMutationStore.js +222 -0
- package/dist/emergent/PersonalityMutationStore.js.map +1 -0
- package/dist/emergent/SelfEvaluateTool.d.ts +199 -0
- package/dist/emergent/SelfEvaluateTool.d.ts.map +1 -0
- package/dist/emergent/SelfEvaluateTool.js +410 -0
- package/dist/emergent/SelfEvaluateTool.js.map +1 -0
- package/dist/emergent/SelfImprovementConfig.d.ts +177 -0
- package/dist/emergent/SelfImprovementConfig.d.ts.map +1 -0
- package/dist/emergent/SelfImprovementConfig.js +43 -0
- package/dist/emergent/SelfImprovementConfig.js.map +1 -0
- package/dist/emergent/index.d.ts +8 -0
- package/dist/emergent/index.d.ts.map +1 -1
- package/dist/emergent/index.js +6 -0
- package/dist/emergent/index.js.map +1 -1
- package/dist/emergent/types.d.ts +9 -0
- package/dist/emergent/types.d.ts.map +1 -1
- package/dist/emergent/types.js.map +1 -1
- package/dist/memory/AgentMemory.d.ts +2 -2
- package/dist/memory/AgentMemory.d.ts.map +1 -1
- package/dist/memory/AgentMemory.js +4 -3
- package/dist/memory/AgentMemory.js.map +1 -1
- package/dist/memory/consolidation/ConsolidationLoop.d.ts +31 -4
- package/dist/memory/consolidation/ConsolidationLoop.d.ts.map +1 -1
- package/dist/memory/consolidation/ConsolidationLoop.js +112 -69
- package/dist/memory/consolidation/ConsolidationLoop.js.map +1 -1
- package/dist/memory/facade/Memory.d.ts +12 -6
- package/dist/memory/facade/Memory.d.ts.map +1 -1
- package/dist/memory/facade/Memory.js +216 -212
- package/dist/memory/facade/Memory.js.map +1 -1
- package/dist/memory/facade/types.d.ts +11 -1
- package/dist/memory/facade/types.d.ts.map +1 -1
- package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts +7 -10
- package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts.map +1 -1
- package/dist/memory/feedback/RetrievalFeedbackSignal.js +40 -36
- package/dist/memory/feedback/RetrievalFeedbackSignal.js.map +1 -1
- package/dist/memory/io/ChatGptImporter.d.ts.map +1 -1
- package/dist/memory/io/ChatGptImporter.js +24 -18
- package/dist/memory/io/ChatGptImporter.js.map +1 -1
- package/dist/memory/io/CsvImporter.d.ts.map +1 -1
- package/dist/memory/io/CsvImporter.js +21 -8
- package/dist/memory/io/CsvImporter.js.map +1 -1
- package/dist/memory/io/JsonExporter.d.ts.map +1 -1
- package/dist/memory/io/JsonExporter.js +6 -17
- package/dist/memory/io/JsonExporter.js.map +1 -1
- package/dist/memory/io/JsonImporter.d.ts +3 -0
- package/dist/memory/io/JsonImporter.d.ts.map +1 -1
- package/dist/memory/io/JsonImporter.js +58 -29
- package/dist/memory/io/JsonImporter.js.map +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownExporter.js +1 -4
- package/dist/memory/io/MarkdownExporter.js.map +1 -1
- package/dist/memory/io/MarkdownImporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownImporter.js +12 -7
- package/dist/memory/io/MarkdownImporter.js.map +1 -1
- package/dist/memory/io/ObsidianExporter.d.ts +14 -9
- package/dist/memory/io/ObsidianExporter.d.ts.map +1 -1
- package/dist/memory/io/ObsidianExporter.js +35 -23
- package/dist/memory/io/ObsidianExporter.js.map +1 -1
- package/dist/memory/io/ObsidianImporter.d.ts.map +1 -1
- package/dist/memory/io/ObsidianImporter.js +34 -27
- package/dist/memory/io/ObsidianImporter.js.map +1 -1
- package/dist/memory/io/SqliteExporter.d.ts +1 -2
- package/dist/memory/io/SqliteExporter.d.ts.map +1 -1
- package/dist/memory/io/SqliteExporter.js +2 -3
- package/dist/memory/io/SqliteExporter.js.map +1 -1
- package/dist/memory/io/SqliteImporter.d.ts +3 -0
- package/dist/memory/io/SqliteImporter.d.ts.map +1 -1
- package/dist/memory/io/SqliteImporter.js +62 -27
- package/dist/memory/io/SqliteImporter.js.map +1 -1
- package/dist/memory/store/SqliteBrain.d.ts +84 -24
- package/dist/memory/store/SqliteBrain.d.ts.map +1 -1
- package/dist/memory/store/SqliteBrain.js +139 -55
- package/dist/memory/store/SqliteBrain.js.map +1 -1
- package/dist/memory/store/SqliteKnowledgeGraph.d.ts +6 -2
- package/dist/memory/store/SqliteKnowledgeGraph.d.ts.map +1 -1
- package/dist/memory/store/SqliteKnowledgeGraph.js +94 -120
- package/dist/memory/store/SqliteKnowledgeGraph.js.map +1 -1
- package/dist/memory/store/SqliteMemoryGraph.d.ts +4 -5
- package/dist/memory/store/SqliteMemoryGraph.d.ts.map +1 -1
- package/dist/memory/store/SqliteMemoryGraph.js +31 -41
- package/dist/memory/store/SqliteMemoryGraph.js.map +1 -1
- package/dist/memory/tools/MemoryAddTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryAddTool.js +12 -16
- package/dist/memory/tools/MemoryAddTool.js.map +1 -1
- package/dist/memory/tools/MemoryDeleteTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryDeleteTool.js +1 -3
- package/dist/memory/tools/MemoryDeleteTool.js.map +1 -1
- package/dist/memory/tools/MemoryMergeTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryMergeTool.js +13 -22
- package/dist/memory/tools/MemoryMergeTool.js.map +1 -1
- package/dist/memory/tools/MemorySearchTool.js +4 -4
- package/dist/memory/tools/MemorySearchTool.js.map +1 -1
- package/dist/memory/tools/MemoryUpdateTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryUpdateTool.js +10 -18
- package/dist/memory/tools/MemoryUpdateTool.js.map +1 -1
- package/dist/orchestration/runtime/LoopController.d.ts +7 -0
- package/dist/orchestration/runtime/LoopController.d.ts.map +1 -1
- package/dist/orchestration/runtime/LoopController.js +7 -0
- package/dist/orchestration/runtime/LoopController.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,410 @@
|
|
|
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 { generateText } from '../api/generateText.js';
|
|
19
|
+
import { PROVIDER_DEFAULTS, autoDetectProvider } from '../api/provider-defaults.js';
|
|
20
|
+
import { VALID_TRAITS } from './AdaptPersonalityTool.js';
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// TOOL IMPLEMENTATION
|
|
23
|
+
// ============================================================================
|
|
24
|
+
/**
|
|
25
|
+
* ITool implementation enabling agents to evaluate their own responses,
|
|
26
|
+
* adjust runtime parameters, and generate performance reports.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const tool = new SelfEvaluateTool({
|
|
31
|
+
* config: {
|
|
32
|
+
* autoAdjust: false,
|
|
33
|
+
* adjustableParams: ['temperature', 'verbosity'],
|
|
34
|
+
* maxEvaluationsPerSession: 20,
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const result = await tool.execute({
|
|
39
|
+
* action: 'evaluate',
|
|
40
|
+
* response: 'The capital of France is Paris.',
|
|
41
|
+
* query: 'What is the capital of France?',
|
|
42
|
+
* }, context);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class SelfEvaluateTool {
|
|
46
|
+
/**
|
|
47
|
+
* Create a new SelfEvaluateTool.
|
|
48
|
+
*
|
|
49
|
+
* @param deps - Injected dependencies including config, optional
|
|
50
|
+
* adaptPersonality tool, and optional memory store callback.
|
|
51
|
+
*/
|
|
52
|
+
constructor(deps) {
|
|
53
|
+
/** @inheritdoc */
|
|
54
|
+
this.id = 'com.framers.emergent.self-evaluate';
|
|
55
|
+
/** @inheritdoc */
|
|
56
|
+
this.name = 'self_evaluate';
|
|
57
|
+
/** @inheritdoc */
|
|
58
|
+
this.displayName = 'Self Evaluate';
|
|
59
|
+
/** @inheritdoc */
|
|
60
|
+
this.description = 'Evaluate response quality, adjust runtime parameters, or generate a ' +
|
|
61
|
+
'performance report. Evaluate uses an LLM judge to score relevance, ' +
|
|
62
|
+
'clarity, accuracy, and helpfulness.';
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
this.category = 'emergent';
|
|
65
|
+
/** @inheritdoc */
|
|
66
|
+
this.hasSideEffects = true;
|
|
67
|
+
/** @inheritdoc */
|
|
68
|
+
this.inputSchema = {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
action: {
|
|
72
|
+
type: 'string',
|
|
73
|
+
enum: ['evaluate', 'adjust', 'report'],
|
|
74
|
+
description: 'The self-evaluation action to perform.',
|
|
75
|
+
},
|
|
76
|
+
response: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
description: 'The response text to evaluate.',
|
|
79
|
+
},
|
|
80
|
+
query: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'The original user query for evaluation context.',
|
|
83
|
+
},
|
|
84
|
+
param: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'The parameter to adjust.',
|
|
87
|
+
},
|
|
88
|
+
value: {
|
|
89
|
+
description: 'The new value for the parameter.',
|
|
90
|
+
},
|
|
91
|
+
reasoning: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Reasoning for personality trait adjustments.',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
required: ['action'],
|
|
97
|
+
};
|
|
98
|
+
/** Session evaluation history. */
|
|
99
|
+
this.evaluations = [];
|
|
100
|
+
/** Session adjustment history. */
|
|
101
|
+
this.adjustments = [];
|
|
102
|
+
/** Current session parameter values (non-personality). */
|
|
103
|
+
this.sessionParams = new Map();
|
|
104
|
+
/** Number of evaluations performed this session. */
|
|
105
|
+
this.evalCount = 0;
|
|
106
|
+
this.deps = deps;
|
|
107
|
+
}
|
|
108
|
+
// --------------------------------------------------------------------------
|
|
109
|
+
// EXECUTE
|
|
110
|
+
// --------------------------------------------------------------------------
|
|
111
|
+
/**
|
|
112
|
+
* Execute the requested self-evaluation action.
|
|
113
|
+
*
|
|
114
|
+
* @param args - Action type and associated parameters.
|
|
115
|
+
* @param context - Tool execution context.
|
|
116
|
+
* @returns A {@link ToolExecutionResult} wrapping the action outcome.
|
|
117
|
+
*/
|
|
118
|
+
async execute(args, context) {
|
|
119
|
+
switch (args.action) {
|
|
120
|
+
case 'evaluate':
|
|
121
|
+
return this.handleEvaluate(args, context);
|
|
122
|
+
case 'adjust':
|
|
123
|
+
return this.handleAdjust(args, context);
|
|
124
|
+
case 'report':
|
|
125
|
+
return this.handleReport();
|
|
126
|
+
default:
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
error: `Unknown action "${args.action}". Must be one of: evaluate, adjust, report`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// --------------------------------------------------------------------------
|
|
134
|
+
// EVALUATE
|
|
135
|
+
// --------------------------------------------------------------------------
|
|
136
|
+
/**
|
|
137
|
+
* Evaluate a response using an LLM judge and record the scores.
|
|
138
|
+
*
|
|
139
|
+
* Calls generateText with a small model to produce structured JSON scores,
|
|
140
|
+
* then persists the evaluation as a memory trace if storeMemory is provided.
|
|
141
|
+
*/
|
|
142
|
+
async handleEvaluate(args, _context) {
|
|
143
|
+
const { response, query } = args;
|
|
144
|
+
if (!response || typeof response !== 'string') {
|
|
145
|
+
return { success: false, error: 'response is required for the evaluate action' };
|
|
146
|
+
}
|
|
147
|
+
if (!query || typeof query !== 'string') {
|
|
148
|
+
return { success: false, error: 'query is required for the evaluate action' };
|
|
149
|
+
}
|
|
150
|
+
// Check session evaluation limit
|
|
151
|
+
if (this.evalCount >= this.deps.config.maxEvaluationsPerSession) {
|
|
152
|
+
return {
|
|
153
|
+
success: false,
|
|
154
|
+
error: `Maximum evaluations per session reached (${this.deps.config.maxEvaluationsPerSession})`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// Call LLM to produce evaluation scores
|
|
158
|
+
let scores;
|
|
159
|
+
try {
|
|
160
|
+
const result = await (this.deps.generateTextImpl ?? generateText)({
|
|
161
|
+
model: this.resolveEvaluationModel(),
|
|
162
|
+
system: 'You are a response quality evaluator. Score the following response on four dimensions: ' +
|
|
163
|
+
'relevance, clarity, accuracy, and helpfulness. Each score is a number between 0 and 1. ' +
|
|
164
|
+
'Return ONLY a JSON object with these four keys, no other text.',
|
|
165
|
+
prompt: `User query: ${query}\n\nResponse to evaluate: ${response}`,
|
|
166
|
+
temperature: 0,
|
|
167
|
+
maxTokens: 200,
|
|
168
|
+
});
|
|
169
|
+
scores = this.parseScores(result.text);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
error: `Evaluation LLM call failed: ${err.message ?? String(err)}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Record the evaluation
|
|
178
|
+
const record = {
|
|
179
|
+
scores,
|
|
180
|
+
timestamp: new Date().toISOString(),
|
|
181
|
+
};
|
|
182
|
+
this.evaluations.push(record);
|
|
183
|
+
this.evalCount++;
|
|
184
|
+
// Store as memory trace if callback is provided
|
|
185
|
+
if (this.deps.storeMemory) {
|
|
186
|
+
try {
|
|
187
|
+
await this.deps.storeMemory({
|
|
188
|
+
type: 'self-evaluation',
|
|
189
|
+
scope: 'session',
|
|
190
|
+
content: JSON.stringify({ query, scores }),
|
|
191
|
+
tags: ['evaluation', 'quality'],
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Best-effort memory storage; don't fail the evaluation
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
success: true,
|
|
200
|
+
output: {
|
|
201
|
+
scores,
|
|
202
|
+
evalCount: this.evalCount,
|
|
203
|
+
remainingEvaluations: this.deps.config.maxEvaluationsPerSession - this.evalCount,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// --------------------------------------------------------------------------
|
|
208
|
+
// ADJUST
|
|
209
|
+
// --------------------------------------------------------------------------
|
|
210
|
+
/**
|
|
211
|
+
* Adjust a runtime parameter.
|
|
212
|
+
*
|
|
213
|
+
* For personality traits (openness, conscientiousness, etc.), delegates to
|
|
214
|
+
* the injected AdaptPersonalityTool. For non-personality params (temperature,
|
|
215
|
+
* verbosity), stores the value in session state.
|
|
216
|
+
*/
|
|
217
|
+
async handleAdjust(args, context) {
|
|
218
|
+
const { param, value, reasoning } = args;
|
|
219
|
+
if (!param || typeof param !== 'string') {
|
|
220
|
+
return { success: false, error: 'param is required for the adjust action' };
|
|
221
|
+
}
|
|
222
|
+
if (value === undefined || value === null) {
|
|
223
|
+
return { success: false, error: 'value is required for the adjust action' };
|
|
224
|
+
}
|
|
225
|
+
if (param === 'personality') {
|
|
226
|
+
if (!this.deps.config.adjustableParams.includes('personality')) {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
error: `Parameter "${param}" is not adjustable. Allowed: ${this.deps.config.adjustableParams.join(', ')}`,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const trait = typeof value === 'object' && value !== null
|
|
233
|
+
? value.trait
|
|
234
|
+
: undefined;
|
|
235
|
+
const delta = typeof value === 'object' && value !== null
|
|
236
|
+
? value.delta
|
|
237
|
+
: undefined;
|
|
238
|
+
if (!this.isPersonalityTrait(trait)) {
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
error: `personality adjustments require a valid trait. Must be one of: ${VALID_TRAITS.join(', ')}`,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (typeof delta !== 'number' || !Number.isFinite(delta)) {
|
|
245
|
+
return {
|
|
246
|
+
success: false,
|
|
247
|
+
error: 'personality adjustments require a finite numeric delta',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return this.delegatePersonalityAdjustment(trait, delta, reasoning ?? `Self-evaluation adjustment for ${trait}`, context);
|
|
251
|
+
}
|
|
252
|
+
if (this.isPersonalityTrait(param)) {
|
|
253
|
+
if (!this.deps.config.adjustableParams.includes(param) &&
|
|
254
|
+
!this.deps.config.adjustableParams.includes('personality')) {
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: `Parameter "${param}" is not adjustable. Allowed: ${this.deps.config.adjustableParams.join(', ')}`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
error: `Personality adjustment "${param}" requires a finite numeric delta`,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return this.delegatePersonalityAdjustment(param, value, reasoning ?? `Self-evaluation adjustment for ${param}`, context);
|
|
267
|
+
}
|
|
268
|
+
if (!this.deps.config.adjustableParams.includes(param)) {
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
error: `Parameter "${param}" is not adjustable. Allowed: ${this.deps.config.adjustableParams.join(', ')}`,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// Non-personality parameter (temperature, verbosity, etc.)
|
|
275
|
+
const prevValue = this.sessionParams.get(param);
|
|
276
|
+
this.sessionParams.set(param, value);
|
|
277
|
+
this.adjustments.push({
|
|
278
|
+
param,
|
|
279
|
+
prev: prevValue ?? null,
|
|
280
|
+
new: value,
|
|
281
|
+
timestamp: new Date().toISOString(),
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
success: true,
|
|
285
|
+
output: {
|
|
286
|
+
param,
|
|
287
|
+
previousValue: prevValue ?? null,
|
|
288
|
+
newValue: value,
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// --------------------------------------------------------------------------
|
|
293
|
+
// REPORT
|
|
294
|
+
// --------------------------------------------------------------------------
|
|
295
|
+
/**
|
|
296
|
+
* Generate a session performance report.
|
|
297
|
+
*
|
|
298
|
+
* Aggregates all evaluations, computes score averages, lists all adjustments,
|
|
299
|
+
* and summarizes personality drift and skill changes.
|
|
300
|
+
*/
|
|
301
|
+
async handleReport() {
|
|
302
|
+
// Compute average scores across all evaluations
|
|
303
|
+
const averages = {
|
|
304
|
+
relevance: 0,
|
|
305
|
+
clarity: 0,
|
|
306
|
+
accuracy: 0,
|
|
307
|
+
helpfulness: 0,
|
|
308
|
+
};
|
|
309
|
+
if (this.evaluations.length > 0) {
|
|
310
|
+
for (const evalRecord of this.evaluations) {
|
|
311
|
+
averages.relevance += evalRecord.scores.relevance;
|
|
312
|
+
averages.clarity += evalRecord.scores.clarity;
|
|
313
|
+
averages.accuracy += evalRecord.scores.accuracy;
|
|
314
|
+
averages.helpfulness += evalRecord.scores.helpfulness;
|
|
315
|
+
}
|
|
316
|
+
const count = this.evaluations.length;
|
|
317
|
+
averages.relevance /= count;
|
|
318
|
+
averages.clarity /= count;
|
|
319
|
+
averages.accuracy /= count;
|
|
320
|
+
averages.helpfulness /= count;
|
|
321
|
+
}
|
|
322
|
+
// Summarize personality drift from adjustments
|
|
323
|
+
const personalityDrift = {};
|
|
324
|
+
const paramAdjustments = [];
|
|
325
|
+
for (const adj of this.adjustments) {
|
|
326
|
+
if (this.isPersonalityTrait(adj.param)) {
|
|
327
|
+
if (!personalityDrift[adj.param]) {
|
|
328
|
+
personalityDrift[adj.param] = { totalDelta: 0, adjustmentCount: 0 };
|
|
329
|
+
}
|
|
330
|
+
personalityDrift[adj.param].totalDelta +=
|
|
331
|
+
adj.new - adj.prev;
|
|
332
|
+
personalityDrift[adj.param].adjustmentCount++;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
paramAdjustments.push(adj);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
success: true,
|
|
340
|
+
output: {
|
|
341
|
+
totalEvaluations: this.evaluations.length,
|
|
342
|
+
averageScores: averages,
|
|
343
|
+
adjustments: paramAdjustments,
|
|
344
|
+
personalityDrift,
|
|
345
|
+
evaluations: this.evaluations,
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
resolveEvaluationModel() {
|
|
350
|
+
if (this.deps.config.evaluationModel) {
|
|
351
|
+
return this.deps.config.evaluationModel;
|
|
352
|
+
}
|
|
353
|
+
const providerId = autoDetectProvider('text');
|
|
354
|
+
const providerDefaults = providerId ? PROVIDER_DEFAULTS[providerId] : undefined;
|
|
355
|
+
const modelId = providerDefaults?.cheap ?? providerDefaults?.text;
|
|
356
|
+
if (providerId && modelId) {
|
|
357
|
+
return `${providerId}:${modelId}`;
|
|
358
|
+
}
|
|
359
|
+
return 'openai:gpt-4o-mini';
|
|
360
|
+
}
|
|
361
|
+
parseScores(rawText) {
|
|
362
|
+
const parsed = this.extractJsonPayload(rawText);
|
|
363
|
+
return {
|
|
364
|
+
relevance: this.normalizeScore(parsed.relevance),
|
|
365
|
+
clarity: this.normalizeScore(parsed.clarity),
|
|
366
|
+
accuracy: this.normalizeScore(parsed.accuracy),
|
|
367
|
+
helpfulness: this.normalizeScore(parsed.helpfulness),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
extractJsonPayload(rawText) {
|
|
371
|
+
try {
|
|
372
|
+
return JSON.parse(rawText);
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
const start = rawText.indexOf('{');
|
|
376
|
+
const end = rawText.lastIndexOf('}');
|
|
377
|
+
if (start >= 0 && end > start) {
|
|
378
|
+
return JSON.parse(rawText.slice(start, end + 1));
|
|
379
|
+
}
|
|
380
|
+
throw new Error('Evaluation model returned non-JSON output.');
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
normalizeScore(value) {
|
|
384
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1
|
|
385
|
+
? value
|
|
386
|
+
: 0.5;
|
|
387
|
+
}
|
|
388
|
+
isPersonalityTrait(param) {
|
|
389
|
+
return typeof param === 'string' && VALID_TRAITS.includes(param);
|
|
390
|
+
}
|
|
391
|
+
async delegatePersonalityAdjustment(trait, delta, reasoning, context) {
|
|
392
|
+
if (!this.deps.adaptPersonality) {
|
|
393
|
+
return {
|
|
394
|
+
success: false,
|
|
395
|
+
error: 'Personality adjustment requires AdaptPersonalityTool but none was provided.',
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const personalityResult = await this.deps.adaptPersonality.execute({ trait, delta, reasoning }, context);
|
|
399
|
+
if (personalityResult.success && personalityResult.output) {
|
|
400
|
+
this.adjustments.push({
|
|
401
|
+
param: trait,
|
|
402
|
+
prev: personalityResult.output.previousValue,
|
|
403
|
+
new: personalityResult.output.newValue,
|
|
404
|
+
timestamp: new Date().toISOString(),
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return personalityResult;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=SelfEvaluateTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelfEvaluateTool.js","sourceRoot":"","sources":["../../src/emergent/SelfEvaluateTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,YAAY,EAA+C,MAAM,2BAA2B,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ACrF,CAAC;QACJ,CAAC;QAED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAChE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,EAC3B,OAAO,CACR,CAAC;QAEF,IAAI,iBAAiB,CAAC,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,CAAC;YAC1D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;gBACpB,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,aAAa;gBAC5C,GAAG,EAAE,iBAAiB,CAAC,MAAM,CAAC,QAAQ;gBACtC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Configuration types and defaults for the self-improving
|
|
3
|
+
* agent system: personality mutation, skill management, workflow composition,
|
|
4
|
+
* and self-evaluation.
|
|
5
|
+
*
|
|
6
|
+
* All sub-systems are opt-in and bounded by configurable limits to prevent
|
|
7
|
+
* runaway self-modification. The {@link DEFAULT_SELF_IMPROVEMENT_CONFIG}
|
|
8
|
+
* constant provides sensible defaults with self-improvement disabled.
|
|
9
|
+
*
|
|
10
|
+
* @module @framers/agentos/emergent/SelfImprovementConfig
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for bounded autonomous self-improvement.
|
|
14
|
+
*
|
|
15
|
+
* Controls four self-improvement capabilities:
|
|
16
|
+
* - **Personality**: HEXACO trait mutation with per-session budgets and decay.
|
|
17
|
+
* - **Skills**: Runtime skill enable/disable with allowlist gating.
|
|
18
|
+
* - **Workflows**: Tool composition with step limits and tool allowlists.
|
|
19
|
+
* - **Self-evaluation**: LLM-based self-scoring with parameter adjustment.
|
|
20
|
+
*
|
|
21
|
+
* All capabilities require `enabled: true` as a master switch. Individual
|
|
22
|
+
* sub-system settings provide additional fine-grained control.
|
|
23
|
+
*/
|
|
24
|
+
export interface SelfImprovementConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Master switch for all self-improvement tools.
|
|
27
|
+
* When `false`, no self-improvement tools are registered with the engine.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for bounded personality trait mutation.
|
|
33
|
+
*
|
|
34
|
+
* Personality mutations modify HEXACO dimensions at runtime, subject to
|
|
35
|
+
* per-session delta budgets and Ebbinghaus-style decay toward baseline
|
|
36
|
+
* values during consolidation cycles.
|
|
37
|
+
*/
|
|
38
|
+
personality: {
|
|
39
|
+
/**
|
|
40
|
+
* Maximum absolute delta per trait per session.
|
|
41
|
+
*
|
|
42
|
+
* Limits how far any single HEXACO dimension can shift in a single
|
|
43
|
+
* agent session. Deltas exceeding this budget are clamped.
|
|
44
|
+
* @default 0.15
|
|
45
|
+
*/
|
|
46
|
+
maxDeltaPerSession: number;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to persist mutations across sessions with strength decay.
|
|
49
|
+
*
|
|
50
|
+
* When `true`, mutations are written to the PersonalityMutationStore
|
|
51
|
+
* and gradually decay toward baseline via the ConsolidationLoop.
|
|
52
|
+
* When `false`, mutations are session-scoped only.
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
persistWithDecay: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Decay rate toward baseline per consolidation cycle.
|
|
58
|
+
*
|
|
59
|
+
* Each consolidation cycle reduces every mutation's strength by this
|
|
60
|
+
* amount. Mutations whose strength falls below 0.1 are pruned.
|
|
61
|
+
* @default 0.05
|
|
62
|
+
*/
|
|
63
|
+
decayRate: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for runtime skill management.
|
|
67
|
+
*
|
|
68
|
+
* Controls which skills the agent can enable/disable at runtime and
|
|
69
|
+
* whether human-in-the-loop approval is required for new skill categories.
|
|
70
|
+
*/
|
|
71
|
+
skills: {
|
|
72
|
+
/**
|
|
73
|
+
* Skill IDs or patterns the agent is allowed to enable.
|
|
74
|
+
*
|
|
75
|
+
* Supports three matching modes:
|
|
76
|
+
* - `['*']` — All skills are allowed (default).
|
|
77
|
+
* - `['category:X']` — Skills in category `X` are allowed.
|
|
78
|
+
* - `['skillId']` — Exact skill ID match.
|
|
79
|
+
*
|
|
80
|
+
* @default ['*']
|
|
81
|
+
*/
|
|
82
|
+
allowlist: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Whether to require HITL approval for skills in new categories.
|
|
85
|
+
*
|
|
86
|
+
* When `true`, enabling a skill whose category is not yet represented
|
|
87
|
+
* among active skills returns a `requires_approval` status instead of
|
|
88
|
+
* enabling immediately.
|
|
89
|
+
* @default true
|
|
90
|
+
*/
|
|
91
|
+
requireApprovalForNewCategories: boolean;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Configuration for runtime workflow composition.
|
|
95
|
+
*
|
|
96
|
+
* Workflows are multi-step tool pipelines created by the agent at runtime.
|
|
97
|
+
* Steps execute sequentially with reference resolution (`$input`, `$prev`,
|
|
98
|
+
* `$steps[N]`) between them.
|
|
99
|
+
*/
|
|
100
|
+
workflows: {
|
|
101
|
+
/**
|
|
102
|
+
* Maximum number of steps per composed workflow.
|
|
103
|
+
*
|
|
104
|
+
* Prevents unbounded pipeline creation. Workflows exceeding this
|
|
105
|
+
* limit are rejected at creation time.
|
|
106
|
+
* @default 10
|
|
107
|
+
*/
|
|
108
|
+
maxSteps: number;
|
|
109
|
+
/**
|
|
110
|
+
* Tool names or patterns the agent may compose into workflows.
|
|
111
|
+
*
|
|
112
|
+
* - `['*']` — All registered tools are allowed (default).
|
|
113
|
+
* - `['toolName']` — Only the listed tools may appear as workflow steps.
|
|
114
|
+
*
|
|
115
|
+
* The `create_workflow` tool is always excluded to prevent recursion.
|
|
116
|
+
* @default ['*']
|
|
117
|
+
*/
|
|
118
|
+
allowedTools: string[];
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Configuration for self-evaluation and strategy adjustment.
|
|
122
|
+
*
|
|
123
|
+
* The agent can evaluate its own responses, score them on multiple
|
|
124
|
+
* criteria, and adjust operational parameters (temperature, verbosity,
|
|
125
|
+
* personality) based on the evaluation results.
|
|
126
|
+
*/
|
|
127
|
+
selfEval: {
|
|
128
|
+
/**
|
|
129
|
+
* Whether to auto-apply suggested adjustments after evaluation.
|
|
130
|
+
*
|
|
131
|
+
* When `true`, the self-evaluate tool applies parameter adjustments
|
|
132
|
+
* immediately. When `false`, adjustments are returned as suggestions
|
|
133
|
+
* only and require explicit confirmation.
|
|
134
|
+
* @default true
|
|
135
|
+
*/
|
|
136
|
+
autoAdjust: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Parameters the agent is permitted to adjust via self-evaluation.
|
|
139
|
+
*
|
|
140
|
+
* Common adjustable parameters:
|
|
141
|
+
* - `'temperature'` — LLM sampling temperature.
|
|
142
|
+
* - `'verbosity'` — Response length preference.
|
|
143
|
+
* - `'personality'` — Any HEXACO trait delta via a `{ trait, delta }` payload.
|
|
144
|
+
* - explicit trait names such as `'openness'` or `'agreeableness'`.
|
|
145
|
+
*
|
|
146
|
+
* @default ['temperature', 'verbosity', 'personality']
|
|
147
|
+
*/
|
|
148
|
+
adjustableParams: string[];
|
|
149
|
+
/**
|
|
150
|
+
* Maximum number of self-evaluations allowed per session.
|
|
151
|
+
*
|
|
152
|
+
* Prevents excessive LLM calls for self-scoring. Further evaluation
|
|
153
|
+
* requests beyond this limit are rejected.
|
|
154
|
+
* @default 10
|
|
155
|
+
*/
|
|
156
|
+
maxEvaluationsPerSession: number;
|
|
157
|
+
/**
|
|
158
|
+
* Optional model override for the evaluation judge.
|
|
159
|
+
*
|
|
160
|
+
* When omitted, the tool auto-detects the current text runtime and uses
|
|
161
|
+
* its cheapest configured text model when available, falling back to
|
|
162
|
+
* `openai:gpt-4o-mini`.
|
|
163
|
+
*
|
|
164
|
+
* @default auto-detected cheap text model
|
|
165
|
+
*/
|
|
166
|
+
evaluationModel?: string;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sensible defaults for self-improvement configuration.
|
|
171
|
+
*
|
|
172
|
+
* Self-improvement is **disabled** by default (`enabled: false`). When opted
|
|
173
|
+
* in, all skills are available, workflows are bounded to 10 steps, and
|
|
174
|
+
* personality mutations decay at 5% per consolidation cycle.
|
|
175
|
+
*/
|
|
176
|
+
export declare const DEFAULT_SELF_IMPROVEMENT_CONFIG: Readonly<SelfImprovementConfig>;
|
|
177
|
+
//# sourceMappingURL=SelfImprovementConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelfImprovementConfig.d.ts","sourceRoot":"","sources":["../../src/emergent/SelfImprovementConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;;;OAMG;IACH,WAAW,EAAE;QACX;;;;;;WAMG;QACH,kBAAkB,EAAE,MAAM,CAAC;QAE3B;;;;;;;WAOG;QACH,gBAAgB,EAAE,OAAO,CAAC;QAE1B;;;;;;WAMG;QACH,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF;;;;;OAKG;IACH,MAAM,EAAE;QACN;;;;;;;;;WASG;QACH,SAAS,EAAE,MAAM,EAAE,CAAC;QAEpB;;;;;;;WAOG;QACH,+BAA+B,EAAE,OAAO,CAAC;KAC1C,CAAC;IAEF;;;;;;OAMG;IACH,SAAS,EAAE;QACT;;;;;;WAMG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;WAQG;QACH,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,CAAC;IAEF;;;;;;OAMG;IACH,QAAQ,EAAE;QACR;;;;;;;WAOG;QACH,UAAU,EAAE,OAAO,CAAC;QAEpB;;;;;;;;;;WAUG;QACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAE3B;;;;;;WAMG;QACH,wBAAwB,EAAE,MAAM,CAAC;QAEjC;;;;;;;;WAQG;QACH,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,qBAAqB,CAoBlE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Configuration types and defaults for the self-improving
|
|
3
|
+
* agent system: personality mutation, skill management, workflow composition,
|
|
4
|
+
* and self-evaluation.
|
|
5
|
+
*
|
|
6
|
+
* All sub-systems are opt-in and bounded by configurable limits to prevent
|
|
7
|
+
* runaway self-modification. The {@link DEFAULT_SELF_IMPROVEMENT_CONFIG}
|
|
8
|
+
* constant provides sensible defaults with self-improvement disabled.
|
|
9
|
+
*
|
|
10
|
+
* @module @framers/agentos/emergent/SelfImprovementConfig
|
|
11
|
+
*/
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// DEFAULT CONFIGURATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Sensible defaults for self-improvement configuration.
|
|
17
|
+
*
|
|
18
|
+
* Self-improvement is **disabled** by default (`enabled: false`). When opted
|
|
19
|
+
* in, all skills are available, workflows are bounded to 10 steps, and
|
|
20
|
+
* personality mutations decay at 5% per consolidation cycle.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_SELF_IMPROVEMENT_CONFIG = {
|
|
23
|
+
enabled: false,
|
|
24
|
+
personality: {
|
|
25
|
+
maxDeltaPerSession: 0.15,
|
|
26
|
+
persistWithDecay: true,
|
|
27
|
+
decayRate: 0.05,
|
|
28
|
+
},
|
|
29
|
+
skills: {
|
|
30
|
+
allowlist: ['*'],
|
|
31
|
+
requireApprovalForNewCategories: true,
|
|
32
|
+
},
|
|
33
|
+
workflows: {
|
|
34
|
+
maxSteps: 10,
|
|
35
|
+
allowedTools: ['*'],
|
|
36
|
+
},
|
|
37
|
+
selfEval: {
|
|
38
|
+
autoAdjust: true,
|
|
39
|
+
adjustableParams: ['temperature', 'verbosity', 'personality'],
|
|
40
|
+
maxEvaluationsPerSession: 10,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=SelfImprovementConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelfImprovementConfig.js","sourceRoot":"","sources":["../../src/emergent/SelfImprovementConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA+KH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAoC;IAC9E,OAAO,EAAE,KAAK;IACd,WAAW,EAAE;QACX,kBAAkB,EAAE,IAAI;QACxB,gBAAgB,EAAE,IAAI;QACtB,SAAS,EAAE,IAAI;KAChB;IACD,MAAM,EAAE;QACN,SAAS,EAAE,CAAC,GAAG,CAAC;QAChB,+BAA+B,EAAE,IAAI;KACtC;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,YAAY,EAAE,CAAC,GAAG,CAAC;KACpB;IACD,QAAQ,EAAE;QACR,UAAU,EAAE,IAAI;QAChB,gBAAgB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,aAAa,CAAC;QAC7D,wBAAwB,EAAE,EAAE;KAC7B;CACO,CAAC"}
|
package/dist/emergent/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
export * from './types.js';
|
|
14
|
+
export { type SelfImprovementConfig, DEFAULT_SELF_IMPROVEMENT_CONFIG } from './SelfImprovementConfig.js';
|
|
14
15
|
export { ComposableToolBuilder } from './ComposableToolBuilder.js';
|
|
15
16
|
export { SandboxedToolForge } from './SandboxedToolForge.js';
|
|
16
17
|
export type { SandboxedToolForgeConfig } from './SandboxedToolForge.js';
|
|
@@ -25,4 +26,11 @@ export type { EmergentCapabilityEngineDeps } from './EmergentCapabilityEngine.js
|
|
|
25
26
|
export { ForgeToolMetaTool } from './ForgeToolMetaTool.js';
|
|
26
27
|
export type { ForgeToolInput } from './ForgeToolMetaTool.js';
|
|
27
28
|
export { exportToolAsSkill, buildCapabilityYaml, writeSkillFile, exportToolAsSkillPack, } from './SkillExporter.js';
|
|
29
|
+
export { AdaptPersonalityTool } from './AdaptPersonalityTool.js';
|
|
30
|
+
export { ManageSkillsTool } from './ManageSkillsTool.js';
|
|
31
|
+
export { CreateWorkflowTool } from './CreateWorkflowTool.js';
|
|
32
|
+
export { SelfEvaluateTool } from './SelfEvaluateTool.js';
|
|
33
|
+
export { PersonalityMutationStore } from './PersonalityMutationStore.js';
|
|
34
|
+
export type { PersonalityMutation, RecordMutationInput, DecayResult } from './PersonalityMutationStore.js';
|
|
35
|
+
export type { SelfImprovementToolDeps } from './EmergentCapabilityEngine.js';
|
|
28
36
|
//# sourceMappingURL=index.d.ts.map
|