@cogitator-ai/self-modifying 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -50
- package/dist/architecture-evolution/capability-analyzer.d.ts.map +1 -1
- package/dist/architecture-evolution/capability-analyzer.js +105 -19
- package/dist/architecture-evolution/capability-analyzer.js.map +1 -1
- package/dist/architecture-evolution/evolution-strategy.d.ts.map +1 -1
- package/dist/architecture-evolution/evolution-strategy.js +2 -6
- package/dist/architecture-evolution/evolution-strategy.js.map +1 -1
- package/dist/architecture-evolution/index.d.ts +1 -1
- package/dist/architecture-evolution/index.d.ts.map +1 -1
- package/dist/architecture-evolution/index.js +1 -1
- package/dist/architecture-evolution/index.js.map +1 -1
- package/dist/architecture-evolution/parameter-optimizer.d.ts.map +1 -1
- package/dist/architecture-evolution/parameter-optimizer.js.map +1 -1
- package/dist/architecture-evolution/prompts.d.ts.map +1 -1
- package/dist/architecture-evolution/prompts.js.map +1 -1
- package/dist/constraints/index.d.ts +1 -1
- package/dist/constraints/index.d.ts.map +1 -1
- package/dist/constraints/index.js +1 -1
- package/dist/constraints/index.js.map +1 -1
- package/dist/constraints/modification-validator.d.ts.map +1 -1
- package/dist/constraints/modification-validator.js +1 -2
- package/dist/constraints/modification-validator.js.map +1 -1
- package/dist/constraints/rollback-manager.d.ts.map +1 -1
- package/dist/constraints/rollback-manager.js.map +1 -1
- package/dist/constraints/safety-constraints.d.ts.map +1 -1
- package/dist/constraints/safety-constraints.js +1 -3
- package/dist/constraints/safety-constraints.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/meta-reasoning/meta-reasoner.d.ts.map +1 -1
- package/dist/meta-reasoning/meta-reasoner.js +5 -10
- package/dist/meta-reasoning/meta-reasoner.js.map +1 -1
- package/dist/meta-reasoning/observation-collector.d.ts.map +1 -1
- package/dist/meta-reasoning/observation-collector.js +1 -3
- package/dist/meta-reasoning/observation-collector.js.map +1 -1
- package/dist/meta-reasoning/prompts.d.ts.map +1 -1
- package/dist/meta-reasoning/prompts.js +4 -2
- package/dist/meta-reasoning/prompts.js.map +1 -1
- package/dist/meta-reasoning/strategy-selector.d.ts.map +1 -1
- package/dist/meta-reasoning/strategy-selector.js +3 -1
- package/dist/meta-reasoning/strategy-selector.js.map +1 -1
- package/dist/self-modifying-agent.d.ts.map +1 -1
- package/dist/self-modifying-agent.js +14 -6
- package/dist/self-modifying-agent.js.map +1 -1
- package/dist/tool-generation/gap-analyzer.d.ts.map +1 -1
- package/dist/tool-generation/gap-analyzer.js +4 -1
- package/dist/tool-generation/gap-analyzer.js.map +1 -1
- package/dist/tool-generation/generated-tool-store.d.ts.map +1 -1
- package/dist/tool-generation/generated-tool-store.js.map +1 -1
- package/dist/tool-generation/prompts.d.ts.map +1 -1
- package/dist/tool-generation/prompts.js +5 -15
- package/dist/tool-generation/prompts.js.map +1 -1
- package/dist/tool-generation/tool-generator.d.ts.map +1 -1
- package/dist/tool-generation/tool-generator.js.map +1 -1
- package/dist/tool-generation/tool-sandbox.d.ts.map +1 -1
- package/dist/tool-generation/tool-sandbox.js +1 -3
- package/dist/tool-generation/tool-sandbox.js.map +1 -1
- package/dist/tool-generation/tool-validator.d.ts.map +1 -1
- package/dist/tool-generation/tool-validator.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/architecture-evolution.test.ts +131 -30
- package/src/__tests__/constraints.test.ts +61 -46
- package/src/__tests__/index.test.ts +4 -17
- package/src/__tests__/meta-reasoning.test.ts +246 -155
- package/src/__tests__/tool-generation.test.ts +26 -7
- package/src/architecture-evolution/capability-analyzer.ts +113 -31
- package/src/architecture-evolution/evolution-strategy.ts +20 -13
- package/src/architecture-evolution/index.ts +1 -4
- package/src/architecture-evolution/parameter-optimizer.ts +42 -23
- package/src/architecture-evolution/prompts.ts +14 -15
- package/src/constraints/index.ts +1 -4
- package/src/constraints/modification-validator.ts +5 -18
- package/src/constraints/rollback-manager.ts +1 -3
- package/src/constraints/safety-constraints.ts +1 -3
- package/src/index.ts +6 -5
- package/src/meta-reasoning/meta-reasoner.ts +9 -16
- package/src/meta-reasoning/observation-collector.ts +3 -12
- package/src/meta-reasoning/prompts.ts +9 -9
- package/src/meta-reasoning/strategy-selector.ts +5 -1
- package/src/self-modifying-agent.ts +25 -28
- package/src/tool-generation/gap-analyzer.ts +18 -14
- package/src/tool-generation/generated-tool-store.ts +5 -8
- package/src/tool-generation/prompts.ts +5 -15
- package/src/tool-generation/tool-generator.ts +15 -11
- package/src/tool-generation/tool-sandbox.ts +4 -15
- package/src/tool-generation/tool-validator.ts +17 -13
|
@@ -4,8 +4,6 @@ import {
|
|
|
4
4
|
RollbackManager,
|
|
5
5
|
InMemoryCheckpointStore,
|
|
6
6
|
DEFAULT_SAFETY_CONSTRAINTS,
|
|
7
|
-
DEFAULT_CAPABILITY_CONSTRAINTS,
|
|
8
|
-
DEFAULT_RESOURCE_CONSTRAINTS,
|
|
9
7
|
mergeSafetyConstraints,
|
|
10
8
|
} from '../constraints';
|
|
11
9
|
|
|
@@ -13,11 +11,7 @@ describe('ModificationValidator', () => {
|
|
|
13
11
|
let validator: ModificationValidator;
|
|
14
12
|
|
|
15
13
|
beforeEach(() => {
|
|
16
|
-
validator = new ModificationValidator(
|
|
17
|
-
safetyConstraints: DEFAULT_SAFETY_CONSTRAINTS,
|
|
18
|
-
capabilityConstraints: DEFAULT_CAPABILITY_CONSTRAINTS,
|
|
19
|
-
resourceConstraints: DEFAULT_RESOURCE_CONSTRAINTS,
|
|
20
|
-
});
|
|
14
|
+
validator = new ModificationValidator();
|
|
21
15
|
});
|
|
22
16
|
|
|
23
17
|
it('validates safe modifications', async () => {
|
|
@@ -26,15 +20,15 @@ describe('ModificationValidator', () => {
|
|
|
26
20
|
target: 'temperature',
|
|
27
21
|
changes: { temperature: 0.7 },
|
|
28
22
|
reason: 'Adjust for creativity',
|
|
29
|
-
|
|
23
|
+
payload: {
|
|
30
24
|
sandboxExecution: true,
|
|
31
25
|
linesOfCode: 50,
|
|
32
26
|
modificationDepth: 1,
|
|
33
27
|
},
|
|
34
28
|
});
|
|
35
29
|
|
|
36
|
-
expect(result.
|
|
37
|
-
expect(result.
|
|
30
|
+
expect(result.valid).toBe(true);
|
|
31
|
+
expect(result.errors).toHaveLength(0);
|
|
38
32
|
});
|
|
39
33
|
|
|
40
34
|
it('rejects modifications violating safety constraints', async () => {
|
|
@@ -43,29 +37,31 @@ describe('ModificationValidator', () => {
|
|
|
43
37
|
target: 'new_tool',
|
|
44
38
|
changes: { code: 'eval("malicious")' },
|
|
45
39
|
reason: 'Create tool',
|
|
46
|
-
|
|
40
|
+
payload: {
|
|
47
41
|
sandboxExecution: false,
|
|
48
42
|
linesOfCode: 50,
|
|
49
43
|
modificationDepth: 1,
|
|
50
44
|
},
|
|
51
45
|
});
|
|
52
46
|
|
|
53
|
-
expect(result.
|
|
54
|
-
expect(result.
|
|
47
|
+
expect(result.valid).toBe(false);
|
|
48
|
+
expect(result.errors!.length).toBeGreaterThan(0);
|
|
55
49
|
});
|
|
56
50
|
|
|
57
51
|
it('handles complex constraint expressions', async () => {
|
|
58
52
|
const customValidator = new ModificationValidator({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
constraints: {
|
|
54
|
+
safety: [
|
|
55
|
+
{
|
|
56
|
+
id: 'complex_rule',
|
|
57
|
+
rule: 'temperature <= 1.5 AND maxTokens <= 8000',
|
|
58
|
+
severity: 'error',
|
|
59
|
+
description: 'Complex constraint',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
capability: [],
|
|
63
|
+
resource: [],
|
|
64
|
+
},
|
|
69
65
|
});
|
|
70
66
|
|
|
71
67
|
const validResult = await customValidator.validate({
|
|
@@ -73,26 +69,38 @@ describe('ModificationValidator', () => {
|
|
|
73
69
|
target: 'config',
|
|
74
70
|
changes: {},
|
|
75
71
|
reason: 'Test',
|
|
76
|
-
|
|
72
|
+
payload: {
|
|
73
|
+
temperature: 1.0,
|
|
74
|
+
maxTokens: 4000,
|
|
75
|
+
sandboxExecution: true,
|
|
76
|
+
linesOfCode: 50,
|
|
77
|
+
modificationDepth: 1,
|
|
78
|
+
},
|
|
77
79
|
});
|
|
78
80
|
|
|
79
|
-
expect(validResult.
|
|
81
|
+
expect(validResult.valid).toBe(true);
|
|
80
82
|
|
|
81
83
|
const invalidResult = await customValidator.validate({
|
|
82
84
|
type: 'config_change',
|
|
83
85
|
target: 'config',
|
|
84
86
|
changes: {},
|
|
85
87
|
reason: 'Test',
|
|
86
|
-
|
|
88
|
+
payload: {
|
|
89
|
+
temperature: 2.0,
|
|
90
|
+
maxTokens: 4000,
|
|
91
|
+
sandboxExecution: true,
|
|
92
|
+
linesOfCode: 50,
|
|
93
|
+
modificationDepth: 1,
|
|
94
|
+
},
|
|
87
95
|
});
|
|
88
96
|
|
|
89
|
-
expect(invalidResult.
|
|
97
|
+
expect(invalidResult.valid).toBe(false);
|
|
90
98
|
});
|
|
91
99
|
|
|
92
100
|
it('adds custom constraints', async () => {
|
|
93
101
|
validator.addSafetyConstraint({
|
|
94
102
|
id: 'custom_test',
|
|
95
|
-
rule: 'customValue
|
|
103
|
+
rule: 'customValue = true',
|
|
96
104
|
severity: 'error',
|
|
97
105
|
description: 'Custom test constraint',
|
|
98
106
|
});
|
|
@@ -102,10 +110,15 @@ describe('ModificationValidator', () => {
|
|
|
102
110
|
target: 'test',
|
|
103
111
|
changes: {},
|
|
104
112
|
reason: 'Test',
|
|
105
|
-
|
|
113
|
+
payload: {
|
|
114
|
+
customValue: false,
|
|
115
|
+
sandboxExecution: true,
|
|
116
|
+
linesOfCode: 50,
|
|
117
|
+
modificationDepth: 1,
|
|
118
|
+
},
|
|
106
119
|
});
|
|
107
120
|
|
|
108
|
-
expect(result.
|
|
121
|
+
expect(result.valid).toBe(false);
|
|
109
122
|
});
|
|
110
123
|
});
|
|
111
124
|
|
|
@@ -113,7 +126,7 @@ describe('RollbackManager', () => {
|
|
|
113
126
|
let manager: RollbackManager;
|
|
114
127
|
|
|
115
128
|
beforeEach(() => {
|
|
116
|
-
manager = new RollbackManager();
|
|
129
|
+
manager = new RollbackManager({ maxCheckpoints: 10 });
|
|
117
130
|
});
|
|
118
131
|
|
|
119
132
|
it('creates checkpoints', async () => {
|
|
@@ -133,7 +146,14 @@ describe('RollbackManager', () => {
|
|
|
133
146
|
const checkpoint = await manager.createCheckpoint(
|
|
134
147
|
'agent-1',
|
|
135
148
|
{ model: 'gpt-4', temperature: 0.7 },
|
|
136
|
-
[
|
|
149
|
+
[
|
|
150
|
+
{
|
|
151
|
+
name: 'original_tool',
|
|
152
|
+
description: 'Original',
|
|
153
|
+
parameters: {},
|
|
154
|
+
execute: async () => null,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
137
157
|
[]
|
|
138
158
|
);
|
|
139
159
|
|
|
@@ -163,27 +183,22 @@ describe('RollbackManager', () => {
|
|
|
163
183
|
[]
|
|
164
184
|
);
|
|
165
185
|
|
|
166
|
-
const diff = manager.compareCheckpoints(cp1
|
|
186
|
+
const diff = manager.compareCheckpoints(cp1, cp2);
|
|
167
187
|
|
|
168
188
|
expect(diff).not.toBeNull();
|
|
169
|
-
expect(diff
|
|
170
|
-
expect(diff
|
|
171
|
-
expect(diff
|
|
189
|
+
expect(diff.configChanges.map((c) => c.key)).toContain('model');
|
|
190
|
+
expect(diff.configChanges.map((c) => c.key)).toContain('temperature');
|
|
191
|
+
expect(diff.toolsAdded).toContain('tool2');
|
|
172
192
|
});
|
|
173
193
|
|
|
174
194
|
it('maintains checkpoint limit', async () => {
|
|
175
195
|
const customManager = new RollbackManager({ maxCheckpoints: 3 });
|
|
176
196
|
|
|
177
197
|
for (let i = 0; i < 5; i++) {
|
|
178
|
-
await customManager.createCheckpoint(
|
|
179
|
-
'agent-1',
|
|
180
|
-
{ iteration: i },
|
|
181
|
-
[],
|
|
182
|
-
[]
|
|
183
|
-
);
|
|
198
|
+
await customManager.createCheckpoint('agent-1', { iteration: i }, [], []);
|
|
184
199
|
}
|
|
185
200
|
|
|
186
|
-
const checkpoints = customManager.listCheckpoints('agent-1');
|
|
201
|
+
const checkpoints = await customManager.listCheckpoints('agent-1');
|
|
187
202
|
expect(checkpoints.length).toBeLessThanOrEqual(3);
|
|
188
203
|
});
|
|
189
204
|
});
|
|
@@ -230,7 +245,7 @@ describe('InMemoryCheckpointStore', () => {
|
|
|
230
245
|
modifications: [],
|
|
231
246
|
});
|
|
232
247
|
|
|
233
|
-
const agent1Checkpoints = await store.
|
|
248
|
+
const agent1Checkpoints = await store.list('agent-1');
|
|
234
249
|
expect(agent1Checkpoints).toHaveLength(1);
|
|
235
250
|
expect(agent1Checkpoints[0].id).toBe('cp-1');
|
|
236
251
|
});
|
|
@@ -255,10 +270,10 @@ describe('InMemoryCheckpointStore', () => {
|
|
|
255
270
|
describe('Constraint merging', () => {
|
|
256
271
|
it('merges safety constraints', () => {
|
|
257
272
|
const custom = [
|
|
258
|
-
{ id: 'custom', rule: 'x
|
|
273
|
+
{ id: 'custom', rule: 'x = 1', severity: 'error' as const, description: 'Custom' },
|
|
259
274
|
];
|
|
260
275
|
|
|
261
|
-
const merged = mergeSafetyConstraints(custom);
|
|
276
|
+
const merged = mergeSafetyConstraints(DEFAULT_SAFETY_CONSTRAINTS, custom);
|
|
262
277
|
|
|
263
278
|
expect(merged.length).toBeGreaterThan(custom.length);
|
|
264
279
|
expect(merged.find((c) => c.id === 'custom')).toBeDefined();
|
|
@@ -7,13 +7,8 @@ describe('@cogitator-ai/self-modifying', () => {
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
it('exports tool generation components', async () => {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
ToolGenerator,
|
|
13
|
-
ToolValidator,
|
|
14
|
-
ToolSandbox,
|
|
15
|
-
InMemoryGeneratedToolStore,
|
|
16
|
-
} = await import('../index');
|
|
10
|
+
const { GapAnalyzer, ToolGenerator, ToolValidator, ToolSandbox, InMemoryGeneratedToolStore } =
|
|
11
|
+
await import('../index');
|
|
17
12
|
|
|
18
13
|
expect(GapAnalyzer).toBeDefined();
|
|
19
14
|
expect(ToolGenerator).toBeDefined();
|
|
@@ -23,11 +18,7 @@ describe('@cogitator-ai/self-modifying', () => {
|
|
|
23
18
|
});
|
|
24
19
|
|
|
25
20
|
it('exports meta-reasoning components', async () => {
|
|
26
|
-
const {
|
|
27
|
-
MetaReasoner,
|
|
28
|
-
ObservationCollector,
|
|
29
|
-
StrategySelector,
|
|
30
|
-
} = await import('../index');
|
|
21
|
+
const { MetaReasoner, ObservationCollector, StrategySelector } = await import('../index');
|
|
31
22
|
|
|
32
23
|
expect(MetaReasoner).toBeDefined();
|
|
33
24
|
expect(ObservationCollector).toBeDefined();
|
|
@@ -35,11 +26,7 @@ describe('@cogitator-ai/self-modifying', () => {
|
|
|
35
26
|
});
|
|
36
27
|
|
|
37
28
|
it('exports architecture evolution components', async () => {
|
|
38
|
-
const {
|
|
39
|
-
CapabilityAnalyzer,
|
|
40
|
-
EvolutionStrategy,
|
|
41
|
-
ParameterOptimizer,
|
|
42
|
-
} = await import('../index');
|
|
29
|
+
const { CapabilityAnalyzer, EvolutionStrategy, ParameterOptimizer } = await import('../index');
|
|
43
30
|
|
|
44
31
|
expect(CapabilityAnalyzer).toBeDefined();
|
|
45
32
|
expect(EvolutionStrategy).toBeDefined();
|