@crewhaus/runtime-core 0.2.1 → 0.2.2
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/index.d.ts +3 -0
- package/dist/index.js +37 -3
- package/package.json +40 -40
package/dist/index.d.ts
CHANGED
|
@@ -535,6 +535,9 @@ export type RunChatLoopOptions = {
|
|
|
535
535
|
readonly minSamplesPerArm?: number;
|
|
536
536
|
readonly costRefUsd?: number;
|
|
537
537
|
readonly latencyRefMs?: number;
|
|
538
|
+
readonly explorationRate?: number;
|
|
539
|
+
readonly seed?: string;
|
|
540
|
+
readonly bandit?: "epsilon-greedy" | "thompson";
|
|
538
541
|
};
|
|
539
542
|
};
|
|
540
543
|
/**
|
package/dist/index.js
CHANGED
|
@@ -608,8 +608,18 @@ export async function runChatLoop(opts) {
|
|
|
608
608
|
candidates,
|
|
609
609
|
policy: pool.policy,
|
|
610
610
|
...(pool.routing !== undefined ? { routing: pool.routing } : {}),
|
|
611
|
-
...(pool.learning
|
|
612
|
-
? {
|
|
611
|
+
...(pool.learning !== undefined
|
|
612
|
+
? {
|
|
613
|
+
learning: {
|
|
614
|
+
...(pool.learning.minSamplesPerArm !== undefined
|
|
615
|
+
? { minSamplesPerArm: pool.learning.minSamplesPerArm }
|
|
616
|
+
: {}),
|
|
617
|
+
...(pool.learning.explorationRate !== undefined
|
|
618
|
+
? { explorationRate: pool.learning.explorationRate }
|
|
619
|
+
: {}),
|
|
620
|
+
...(pool.learning.bandit !== undefined ? { bandit: pool.learning.bandit } : {}),
|
|
621
|
+
},
|
|
622
|
+
}
|
|
613
623
|
: {}),
|
|
614
624
|
// The learned policy reads the live scoreboard; static/heuristic ignore it.
|
|
615
625
|
...(pool.policy === "learned" ? { score: (rk, m) => sb.score(rk, m) } : {}),
|
|
@@ -662,6 +672,12 @@ export async function runChatLoop(opts) {
|
|
|
662
672
|
// Tests that pass their own runContext rely on observing turnNumber on
|
|
663
673
|
// it after the loop returns, so we never silently swap it out.
|
|
664
674
|
const runContext = opts.runContext ?? createRunContext({ sessionId });
|
|
675
|
+
// Adaptive model routing — ε-greedy exploration seed. A spec-fixed
|
|
676
|
+
// `learning.seed` reproduces exploration across runs (tests); otherwise the
|
|
677
|
+
// sessionId seeds it, so each run explores differently yet still replays
|
|
678
|
+
// exactly from its own transcript. Constant per run; the per-turn draw mixes
|
|
679
|
+
// in turnIndex + band (see PolicyRouter.route).
|
|
680
|
+
const poolSeed = opts.modelPool?.learning?.seed ?? sessionId;
|
|
665
681
|
// Section 15 — every observability subscriber (otel, metrics, printer)
|
|
666
682
|
// hangs off this single bus. The default constructor in `createRunContext`
|
|
667
683
|
// mints a no-subscriber bus; here we attach the env-gated set so a fresh
|
|
@@ -1795,7 +1811,13 @@ export async function runChatLoop(opts) {
|
|
|
1795
1811
|
toolsInPlay: (anthropicTools?.length ?? 0) > 0,
|
|
1796
1812
|
turnIndex: Math.max(0, runContext.turnNumber - 1),
|
|
1797
1813
|
priorTurnToolUseCount,
|
|
1798
|
-
}
|
|
1814
|
+
}, poolSeed,
|
|
1815
|
+
// Monotonic exploration sequence: the transcript length keeps
|
|
1816
|
+
// advancing across `--resume` (and a channel-bot's resume-per-
|
|
1817
|
+
// message), so ε-greedy draws a fresh coin per decision instead
|
|
1818
|
+
// of freezing on the reset-to-0 turnIndex. Deterministic on
|
|
1819
|
+
// replay (the same transcript reconstructs the same length).
|
|
1820
|
+
messages.length);
|
|
1799
1821
|
const decision = escalatePool
|
|
1800
1822
|
? {
|
|
1801
1823
|
...base,
|
|
@@ -1822,6 +1844,18 @@ export async function runChatLoop(opts) {
|
|
|
1822
1844
|
...(decision.explored ? { explored: true } : {}),
|
|
1823
1845
|
...(poolPolicyVersion !== undefined ? { policyVersion: poolPolicyVersion } : {}),
|
|
1824
1846
|
});
|
|
1847
|
+
// Persist the decision so `crewhaus route explain <session>` can
|
|
1848
|
+
// replay per-turn routing after the fact. Non-conversational, so
|
|
1849
|
+
// `replayMessageHistory` ignores it and `--resume` is unaffected.
|
|
1850
|
+
await logEvent("model_route", {
|
|
1851
|
+
turnNumber: runContext.turnNumber,
|
|
1852
|
+
routeKey: decision.routeKey,
|
|
1853
|
+
model: decision.candidate.modelId,
|
|
1854
|
+
policy: decision.policy,
|
|
1855
|
+
reason: decision.reason,
|
|
1856
|
+
explored: decision.explored,
|
|
1857
|
+
...(poolPolicyVersion !== undefined ? { policyVersion: poolPolicyVersion } : {}),
|
|
1858
|
+
});
|
|
1825
1859
|
}
|
|
1826
1860
|
else if (tierRouter !== undefined) {
|
|
1827
1861
|
// Item 26 — two-tier turn-difficulty router. Pick a tier from
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/runtime-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Minimal runtime imported by generated harness bundles",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,48 +16,48 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@anthropic-ai/sdk": "^0.96.0",
|
|
19
|
-
"@crewhaus/abort-controller": "0.2.
|
|
20
|
-
"@crewhaus/adapter-anthropic": "0.2.
|
|
21
|
-
"@crewhaus/agent-context-isolation": "0.2.
|
|
22
|
-
"@crewhaus/boundary-classifier": "0.2.
|
|
23
|
-
"@crewhaus/circuit-breaker": "0.2.
|
|
24
|
-
"@crewhaus/compaction-autocompact": "0.2.
|
|
25
|
-
"@crewhaus/compaction-snip": "0.2.
|
|
26
|
-
"@crewhaus/cost-tracker": "0.2.
|
|
27
|
-
"@crewhaus/egress-classifier": "0.2.
|
|
28
|
-
"@crewhaus/errors": "0.2.
|
|
29
|
-
"@crewhaus/event-log": "0.2.
|
|
30
|
-
"@crewhaus/hooks-engine": "0.2.
|
|
31
|
-
"@crewhaus/model-router": "0.2.
|
|
32
|
-
"@crewhaus/permission-engine": "0.2.
|
|
33
|
-
"@crewhaus/prompt-cache-manager": "0.2.
|
|
34
|
-
"@crewhaus/prompt-injection-detector": "0.2.
|
|
35
|
-
"@crewhaus/rate-limiter": "0.2.
|
|
36
|
-
"@crewhaus/recovery-engine": "0.2.
|
|
37
|
-
"@crewhaus/routing-store": "0.2.
|
|
38
|
-
"@crewhaus/run-context": "0.2.
|
|
39
|
-
"@crewhaus/session-store": "0.2.
|
|
40
|
-
"@crewhaus/skills-registry": "0.2.
|
|
41
|
-
"@crewhaus/slash-commands": "0.2.
|
|
42
|
-
"@crewhaus/state-store": "0.2.
|
|
43
|
-
"@crewhaus/tenancy": "0.2.
|
|
44
|
-
"@crewhaus/token-budget": "0.2.
|
|
45
|
-
"@crewhaus/tool-catalog": "0.2.
|
|
46
|
-
"@crewhaus/tool-executor": "0.2.
|
|
47
|
-
"@crewhaus/tool-loop-detection": "0.2.
|
|
48
|
-
"@crewhaus/tool-orchestrator": "0.2.
|
|
49
|
-
"@crewhaus/tool-result-store": "0.2.
|
|
50
|
-
"@crewhaus/streaming-tool-executor": "0.2.
|
|
51
|
-
"@crewhaus/turn-state-machine": "0.2.
|
|
52
|
-
"@crewhaus/trace-event-bus": "0.2.
|
|
53
|
-
"@crewhaus/structured-event-printer": "0.2.
|
|
54
|
-
"@crewhaus/metrics-collector": "0.2.
|
|
55
|
-
"@crewhaus/otel-exporter": "0.2.
|
|
19
|
+
"@crewhaus/abort-controller": "0.2.2",
|
|
20
|
+
"@crewhaus/adapter-anthropic": "0.2.2",
|
|
21
|
+
"@crewhaus/agent-context-isolation": "0.2.2",
|
|
22
|
+
"@crewhaus/boundary-classifier": "0.2.2",
|
|
23
|
+
"@crewhaus/circuit-breaker": "0.2.2",
|
|
24
|
+
"@crewhaus/compaction-autocompact": "0.2.2",
|
|
25
|
+
"@crewhaus/compaction-snip": "0.2.2",
|
|
26
|
+
"@crewhaus/cost-tracker": "0.2.2",
|
|
27
|
+
"@crewhaus/egress-classifier": "0.2.2",
|
|
28
|
+
"@crewhaus/errors": "0.2.2",
|
|
29
|
+
"@crewhaus/event-log": "0.2.2",
|
|
30
|
+
"@crewhaus/hooks-engine": "0.2.2",
|
|
31
|
+
"@crewhaus/model-router": "0.2.2",
|
|
32
|
+
"@crewhaus/permission-engine": "0.2.2",
|
|
33
|
+
"@crewhaus/prompt-cache-manager": "0.2.2",
|
|
34
|
+
"@crewhaus/prompt-injection-detector": "0.2.2",
|
|
35
|
+
"@crewhaus/rate-limiter": "0.2.2",
|
|
36
|
+
"@crewhaus/recovery-engine": "0.2.2",
|
|
37
|
+
"@crewhaus/routing-store": "0.2.2",
|
|
38
|
+
"@crewhaus/run-context": "0.2.2",
|
|
39
|
+
"@crewhaus/session-store": "0.2.2",
|
|
40
|
+
"@crewhaus/skills-registry": "0.2.2",
|
|
41
|
+
"@crewhaus/slash-commands": "0.2.2",
|
|
42
|
+
"@crewhaus/state-store": "0.2.2",
|
|
43
|
+
"@crewhaus/tenancy": "0.2.2",
|
|
44
|
+
"@crewhaus/token-budget": "0.2.2",
|
|
45
|
+
"@crewhaus/tool-catalog": "0.2.2",
|
|
46
|
+
"@crewhaus/tool-executor": "0.2.2",
|
|
47
|
+
"@crewhaus/tool-loop-detection": "0.2.2",
|
|
48
|
+
"@crewhaus/tool-orchestrator": "0.2.2",
|
|
49
|
+
"@crewhaus/tool-result-store": "0.2.2",
|
|
50
|
+
"@crewhaus/streaming-tool-executor": "0.2.2",
|
|
51
|
+
"@crewhaus/turn-state-machine": "0.2.2",
|
|
52
|
+
"@crewhaus/trace-event-bus": "0.2.2",
|
|
53
|
+
"@crewhaus/structured-event-printer": "0.2.2",
|
|
54
|
+
"@crewhaus/metrics-collector": "0.2.2",
|
|
55
|
+
"@crewhaus/otel-exporter": "0.2.2",
|
|
56
56
|
"zod-to-json-schema": "^3.23.5"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@crewhaus/logging": "0.2.
|
|
60
|
-
"@crewhaus/tool-builder": "0.2.
|
|
59
|
+
"@crewhaus/logging": "0.2.2",
|
|
60
|
+
"@crewhaus/tool-builder": "0.2.2",
|
|
61
61
|
"zod": "^3.23.8"
|
|
62
62
|
},
|
|
63
63
|
"license": "Apache-2.0",
|