@hmharness/agent 0.23.2 → 0.23.4
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.
|
@@ -7,7 +7,14 @@ export declare class CognitiveRunRecorder {
|
|
|
7
7
|
private seq;
|
|
8
8
|
private failures;
|
|
9
9
|
private successes;
|
|
10
|
+
/** per-action-type success EMA seeded from history — lets EVERY regular
|
|
11
|
+
* task step carry a prediction, feeding the calibration dimension (the
|
|
12
|
+
* §26-proven value) from 115/3043 steps toward full coverage */
|
|
13
|
+
private beliefs;
|
|
10
14
|
constructor(home: string, task: string, sessionId: string, cwd: string);
|
|
15
|
+
private seedBeliefs;
|
|
16
|
+
private predict;
|
|
17
|
+
private learn;
|
|
11
18
|
/** loop onToolCall: open a step for this tool invocation */
|
|
12
19
|
call(toolName: string, args: Record<string, unknown>): void;
|
|
13
20
|
/** loop onToolResult: close the matching step (same tool, FIFO) */
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* environment/session — MEM-007). Everything here is best-effort: cognitive
|
|
10
10
|
* recording must never break a task run.
|
|
11
11
|
*/
|
|
12
|
-
import { TrajectoryStore, TrajectoryRecorder, CognitiveMemory } from '@hmharness/cognitive';
|
|
12
|
+
import { TrajectoryStore, TrajectoryRecorder, CognitiveMemory, loadTrajectories } from '@hmharness/cognitive';
|
|
13
13
|
export class CognitiveRunRecorder {
|
|
14
14
|
home;
|
|
15
15
|
cwd;
|
|
@@ -19,11 +19,44 @@ export class CognitiveRunRecorder {
|
|
|
19
19
|
seq = 0;
|
|
20
20
|
failures = 0;
|
|
21
21
|
successes = 0;
|
|
22
|
+
/** per-action-type success EMA seeded from history — lets EVERY regular
|
|
23
|
+
* task step carry a prediction, feeding the calibration dimension (the
|
|
24
|
+
* §26-proven value) from 115/3043 steps toward full coverage */
|
|
25
|
+
beliefs = new Map();
|
|
22
26
|
constructor(home, task, sessionId, cwd) {
|
|
23
27
|
this.home = home;
|
|
24
28
|
this.cwd = cwd;
|
|
25
29
|
this.store = new TrajectoryStore(home);
|
|
26
30
|
this.rec = new TrajectoryRecorder(`trj-${sessionId}-${Date.now().toString(36)}`, sessionId, { id: 'terminal', version: '1.0.0' }, { id: `goal-${sessionId}`, description: task });
|
|
31
|
+
// seed beliefs from recent history (best-effort, never blocks a task)
|
|
32
|
+
void this.seedBeliefs().catch(() => undefined);
|
|
33
|
+
}
|
|
34
|
+
async seedBeliefs() {
|
|
35
|
+
const trajectories = await loadTrajectories(this.home, 200);
|
|
36
|
+
const table = new Map();
|
|
37
|
+
for (const traj of trajectories) {
|
|
38
|
+
for (const s of traj.steps) {
|
|
39
|
+
const t = s.action.type;
|
|
40
|
+
const agg = table.get(t) ?? { sum: 0, n: 0 };
|
|
41
|
+
agg.sum += s.outcome === 'success' ? 1 : 0;
|
|
42
|
+
agg.n += 1;
|
|
43
|
+
table.set(t, agg);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const [t, v] of table)
|
|
47
|
+
this.beliefs.set(t, { rate: v.sum / v.n, n: v.n });
|
|
48
|
+
}
|
|
49
|
+
predict(type) {
|
|
50
|
+
const b = this.beliefs.get(type);
|
|
51
|
+
if (!b)
|
|
52
|
+
return undefined; // unseen tool: no prediction beats a fake one
|
|
53
|
+
return { claim: `${type} succeeds ~${Math.round(b.rate * 100)}% (n=${b.n})`, confidence: Number(b.rate.toFixed(3)) };
|
|
54
|
+
}
|
|
55
|
+
learn(type, success) {
|
|
56
|
+
const b = this.beliefs.get(type) ?? { rate: success ? 1 : 0, n: 0 };
|
|
57
|
+
b.rate = (b.rate * b.n + (success ? 1 : 0)) / (b.n + 1);
|
|
58
|
+
b.n += 1;
|
|
59
|
+
this.beliefs.set(type, b);
|
|
27
60
|
}
|
|
28
61
|
/** loop onToolCall: open a step for this tool invocation */
|
|
29
62
|
call(toolName, args) {
|
|
@@ -31,6 +64,7 @@ export class CognitiveRunRecorder {
|
|
|
31
64
|
this.open.set(key, {
|
|
32
65
|
action: { id: key, type: toolName, args: clip(args), reason: 'agent loop tool call' },
|
|
33
66
|
startedAt: Date.now(),
|
|
67
|
+
prediction: this.predict(toolName),
|
|
34
68
|
});
|
|
35
69
|
}
|
|
36
70
|
/** loop onToolResult: close the matching step (same tool, FIFO) */
|
|
@@ -39,14 +73,17 @@ export class CognitiveRunRecorder {
|
|
|
39
73
|
if (!key.startsWith(`${toolName}#`))
|
|
40
74
|
continue;
|
|
41
75
|
this.open.delete(key);
|
|
76
|
+
const success = !isError;
|
|
42
77
|
if (isError)
|
|
43
78
|
this.failures += 1;
|
|
44
79
|
else
|
|
45
80
|
this.successes += 1;
|
|
81
|
+
this.learn(toolName, success);
|
|
46
82
|
this.rec.record({
|
|
47
83
|
action: open.action,
|
|
48
84
|
outcome: isError ? 'failure' : 'success',
|
|
49
85
|
evidence: [],
|
|
86
|
+
prediction: open.prediction,
|
|
50
87
|
durationMs: Date.now() - open.startedAt,
|
|
51
88
|
});
|
|
52
89
|
return;
|
|
@@ -57,6 +94,7 @@ export class CognitiveRunRecorder {
|
|
|
57
94
|
action: { id: `${toolName}#${++this.seq}`, type: toolName, args: {}, reason: 'tool result without recorded call' },
|
|
58
95
|
outcome: isError ? 'failure' : 'success',
|
|
59
96
|
evidence: [],
|
|
97
|
+
prediction: this.predict(toolName),
|
|
60
98
|
});
|
|
61
99
|
}
|
|
62
100
|
/** task end: persist trajectory + episodic memory index entry */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/agent",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
4
4
|
"description": "hmharness agent execution layer: base tools, system prompt, sub-agent spawn, and the shared task runner that frontends (cli, web) drive.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"build": "tsc -p tsconfig.build.json"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@hmharness/cognitive": "0.23.
|
|
19
|
-
"@hmharness/domain-harmony": "0.23.
|
|
20
|
-
"@hmharness/domain-ops": "0.23.
|
|
21
|
-
"@hmharness/evolution": "0.23.
|
|
22
|
-
"@hmharness/kernel": "0.23.
|
|
23
|
-
"@hmharness/observability": "0.23.
|
|
24
|
-
"@hmharness/sandbox": "0.23.
|
|
18
|
+
"@hmharness/cognitive": "0.23.4",
|
|
19
|
+
"@hmharness/domain-harmony": "0.23.4",
|
|
20
|
+
"@hmharness/domain-ops": "0.23.4",
|
|
21
|
+
"@hmharness/evolution": "0.23.4",
|
|
22
|
+
"@hmharness/kernel": "0.23.4",
|
|
23
|
+
"@hmharness/observability": "0.23.4",
|
|
24
|
+
"@hmharness/sandbox": "0.23.4"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|