@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.44
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/CHANGELOG.md +126 -0
- package/README.md +221 -31
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-sources.js +25 -5
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +203 -87
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +516 -134
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// hands on them (runTools), the gate from the store's tool settings, the system prompt (environment line, instructions
|
|
15
15
|
// with what the agent learned and its skills, effort guidance), the first message, the end's metrics and the release.
|
|
16
16
|
import { mkdir, readdir, rm, rmdir } from "node:fs/promises";
|
|
17
|
+
import { stopRunWith } from "../paid-calls.js";
|
|
17
18
|
import { dirname, join } from "node:path";
|
|
18
19
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
19
20
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
@@ -54,7 +55,7 @@ import { isWebHostTool } from "../tool-list.js";
|
|
|
54
55
|
import { hostToolOf } from "../host-tools.js";
|
|
55
56
|
import { ASK_TOOL, askPerson } from "../tools.js";
|
|
56
57
|
import { fakedPlane } from "../web-fake.js";
|
|
57
|
-
import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, tierModelKeys,
|
|
58
|
+
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
58
59
|
import { mcpForClaim } from "./mcp-run.js";
|
|
59
60
|
import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
60
61
|
import { decisionProvidersIn } from "../decisions.js";
|
|
@@ -65,6 +66,7 @@ import { journalEntries } from "./journal-reader.js";
|
|
|
65
66
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
66
67
|
import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
|
|
67
68
|
import { pathMetrics, workflowFirstOf } from "./workflow-first.js";
|
|
69
|
+
import { AUDIT_PARKED, settleAudits, withAudit } from "./audit.js";
|
|
68
70
|
import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
|
|
69
71
|
import { specBuilt } from "./spec-holds.js";
|
|
70
72
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
@@ -138,8 +140,9 @@ export async function cliCapModel(entry, env, ref) {
|
|
|
138
140
|
* run whose plane resolves it to native gets the harness's own search (#2458), this run's alone; whatever the runner's
|
|
139
141
|
* own environment says of a plane is never the run's. Whether each search runs is the tool's setting at that search
|
|
140
142
|
* (SessionIO.permission, the gate), never this plane, which is frozen when the run is made. */
|
|
141
|
-
export function cliRunEnv(env, data, claimed = {}, plane) {
|
|
142
|
-
|
|
143
|
+
export function cliRunEnv(env, data, claimed = {}, plane, runKey) {
|
|
144
|
+
// A run with its own model key: that key alone, in the variables its route sends (claimModelEnv, never enumerable).
|
|
145
|
+
const out = claimModelEnv(env ?? {}, claimed, runKey);
|
|
143
146
|
Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
|
|
144
147
|
delete out[TOOL_PLANE_ENV];
|
|
145
148
|
if (plane && Object.keys(plane).length)
|
|
@@ -269,7 +272,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
269
272
|
// test runner; anywhere else it is the built-ins), and the runner's record mode for it.
|
|
270
273
|
const name = launch.harness ?? body.harness;
|
|
271
274
|
const entry = harnessOf(deps.env, name);
|
|
272
|
-
const runner = name === undefined ? undefined : resolveHarness(name);
|
|
275
|
+
const runner = name === undefined ? undefined : resolveHarness(name, deps.env);
|
|
273
276
|
if (!name || !entry?.facts || !entry.adapter || !runner)
|
|
274
277
|
throw new Error(`run ${claim.runId}: ${JSON.stringify(name)} is not a CLI harness this runner runs`);
|
|
275
278
|
const facts = entry.facts;
|
|
@@ -382,7 +385,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
382
385
|
// Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
|
|
383
386
|
// spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount). Its
|
|
384
387
|
// screen's recording (computer.record) goes in the run's recordings folder, as the pi spec's does.
|
|
385
|
-
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
388
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
386
389
|
holds.hold({ computer });
|
|
387
390
|
const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
|
|
388
391
|
const heldComputer = heldSpecOf(launch, loopComputer);
|
|
@@ -428,9 +431,19 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
428
431
|
// to the model choice and the adapter's provider (withModelKeys, never enumerable), so a key saved in
|
|
429
432
|
// Settings → Model keys runs the next run with no restart, as one set where AgentRun starts does.
|
|
430
433
|
const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
|
|
431
|
-
|
|
434
|
+
// The run's own model key, when its caller handed one (model_key): opened at every claim, held by the redactors, read by
|
|
435
|
+
// its model route alone; the CLI's process and its tools never carry it, nor any other model key then.
|
|
436
|
+
// A run that starts on the server's key holds the claim's key holder too: a message's first key reaches its next request.
|
|
437
|
+
const runKey = await claimModelKey({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, claim.runId);
|
|
438
|
+
const keyed = keyedAtClaim(runKey);
|
|
439
|
+
if (keyed)
|
|
440
|
+
withoutModelKeys(claimed);
|
|
441
|
+
for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut]) {
|
|
432
442
|
holdClaimed(redact, claimed);
|
|
433
|
-
|
|
443
|
+
if (runKey)
|
|
444
|
+
holdRunKey(redact, runKey);
|
|
445
|
+
}
|
|
446
|
+
const env = cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey);
|
|
434
447
|
const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
|
|
435
448
|
await planBeforeRun(env, chosen.model);
|
|
436
449
|
// The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
|
|
@@ -503,7 +516,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
503
516
|
const tierRoute = tierRoutes.get(by);
|
|
504
517
|
return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
|
|
505
518
|
},
|
|
506
|
-
// What its learning runs' grades took beside it, read by every gate with its own sessions
|
|
519
|
+
// What its learning runs' grades and its audit's shadow took beside it, read by every gate with its own sessions
|
|
520
|
+
// (none: it queues none).
|
|
507
521
|
...(besideOf ? { beside: besideOf } : {}),
|
|
508
522
|
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
|
|
509
523
|
freeRequests: freeModelRequestsOf(deps.env),
|
|
@@ -547,15 +561,22 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
547
561
|
// The keys the claim hands the run (its web tools and its learned workflow's call nodes run on them): never learned
|
|
548
562
|
// (learningEndOfRun).
|
|
549
563
|
let handedKeys = [];
|
|
550
|
-
// A replay run lays the workflow it replays
|
|
564
|
+
// A replay run lays only the workflow it replays (runner/promotion.ts replayLaid).
|
|
551
565
|
const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
|
|
552
566
|
// The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
|
|
553
567
|
// chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
|
|
554
568
|
// serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
|
|
555
569
|
// five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
|
|
556
570
|
// (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
|
|
571
|
+
// The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
|
|
572
|
+
// Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit, a replay check and
|
|
573
|
+
// the learning run's grade are skipped, in words, where the run brought its own key or the server holds none.
|
|
574
|
+
const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
|
|
575
|
+
const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
|
|
576
|
+
if (launch.learning && !launch.replay && !launch.audit)
|
|
577
|
+
await settleAudits(audits);
|
|
557
578
|
const promotion = claimPromotion({
|
|
558
|
-
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
|
|
579
|
+
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff,
|
|
559
580
|
});
|
|
560
581
|
const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
|
|
561
582
|
// A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
|
|
@@ -595,10 +616,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
595
616
|
// keys, pi's wires, since pi-ai's client sends these, never the CLI); one refused fails its node in its words.
|
|
596
617
|
// Their models' keys (tierModelKeys: a saved one too, which claimSecrets opened only for the run's own model), held by
|
|
597
618
|
// the redactors, on the tiers' route env alone (withModelKeys, never enumerable), never on the tools' (toolEnv).
|
|
598
|
-
|
|
619
|
+
// A run with its own model key: these tiers carry that key too, and no saved key is read.
|
|
620
|
+
const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
599
621
|
for (const redact of new Set([held, cut]))
|
|
600
622
|
holdClaimed(redact, tierKeys);
|
|
601
|
-
const modelEnv =
|
|
623
|
+
const modelEnv = claimModelEnv(deps.env, { ...claimed, ...tierKeys }, runKey);
|
|
602
624
|
const tiers = new Map();
|
|
603
625
|
for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
|
|
604
626
|
if ("why" in routed)
|
|
@@ -633,10 +655,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
633
655
|
// The run's end-of-run step, when it learns, the same as the pi spec's: the reflect-and-propose turn over the run's
|
|
634
656
|
// store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this claim's
|
|
635
657
|
// Archil disk — so the proposal is checked against the seed in the run's own Workspace, never this machine's local path.
|
|
636
|
-
// A replay run asks nothing at its end: it is the promotion's, never the agent's to learn from.
|
|
637
|
-
|
|
658
|
+
// A replay run or an audit's shadow run asks nothing at its end: it is the promotion's, never the agent's to learn from.
|
|
659
|
+
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
660
|
+
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
661
|
+
const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
|
|
638
662
|
store: deps.store,
|
|
639
663
|
data: deps.data,
|
|
664
|
+
spendOff,
|
|
640
665
|
...(deps.env ? { env: deps.env } : {}),
|
|
641
666
|
// What the run must never learn beside the runner's secrets: the keys its claim handed it, every secret the server
|
|
642
667
|
// keeps sealed (storeSecrets: the run's redactor holds the same list), and its sign-in's pointers, read back from the
|
|
@@ -650,7 +675,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
650
675
|
learningFolder: archil === undefined
|
|
651
676
|
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
652
677
|
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
653
|
-
});
|
|
678
|
+
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
654
679
|
return {
|
|
655
680
|
adapter,
|
|
656
681
|
session,
|
|
@@ -666,6 +691,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
666
691
|
// The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
|
|
667
692
|
// the catalog tools the session mounts; absent when none.
|
|
668
693
|
...(catalog ? { mcp: catalog } : {}),
|
|
694
|
+
// The run's own model key: a command row opens it again before the next model request (a message's new key).
|
|
695
|
+
...(runKey ? { modelKey: runKey } : {}),
|
|
669
696
|
// The run's end-of-run step, when it learns (the spec's, preferred over the loop's deps': adapter-loop.ts stepOf).
|
|
670
697
|
...(endOfRun ? { endOfRun } : {}),
|
|
671
698
|
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
@@ -674,6 +701,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
674
701
|
// The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
|
|
675
702
|
...(life ? { lifecycle: life } : {}),
|
|
676
703
|
agentId: runRow.agentId,
|
|
704
|
+
// An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
|
|
705
|
+
...(launch.audit ? { neverWaits: AUDIT_PARKED } : {}),
|
|
677
706
|
// The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
|
|
678
707
|
...(loopComputer ? { computer: loopComputer } : {}),
|
|
679
708
|
// A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Command } from "./loop-contract.js";
|
|
2
|
+
import type { LaunchSealedWrite } from "../store/store.js";
|
|
2
3
|
/** stop and cancel both end the run, stopped: a cancel's end says it was cancelled, as main's cancel ends a run for good.
|
|
3
4
|
* browser_hand_back is a person's answer to the agent's browser hand-over (runner/hand-back.ts). computer_take_over and
|
|
4
5
|
* computer_hand_back are a person's turn with the run's desktop or phone (computer-commands.ts, runner/computer-journal.ts).
|
|
@@ -15,15 +16,11 @@ export interface CommandSink {
|
|
|
15
16
|
command(runId: string, command: {
|
|
16
17
|
kind: string;
|
|
17
18
|
body: Record<string, unknown>;
|
|
18
|
-
}, options?:
|
|
19
|
-
launchSealed?: Uint8Array;
|
|
20
|
-
}): Promise<Command>;
|
|
19
|
+
}, options?: LaunchSealedWrite): Promise<Command>;
|
|
21
20
|
}
|
|
22
21
|
/** Inserts a command row for a run, after checking its kind and body. Rejects RunFinal (from the store) when the run is
|
|
23
22
|
* final, and a TypeError for a kind or body no runner would take. */
|
|
24
|
-
export declare function sendCommand(store: CommandSink, runId: string, input: CommandInput, options?:
|
|
25
|
-
launchSealed?: Uint8Array;
|
|
26
|
-
}): Promise<Command>;
|
|
23
|
+
export declare function sendCommand(store: CommandSink, runId: string, input: CommandInput, options?: LaunchSealedWrite): Promise<Command>;
|
|
27
24
|
/** The reason a command still untaken when its run ended is refused with: the store's own words (the write that makes a
|
|
28
25
|
* run final refuses such rows itself). */
|
|
29
26
|
export { endedReason } from "../store/store.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Grade } from "../learn/promote.js";
|
|
2
2
|
import type { RunPath } from "../learning-cost.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
3
4
|
import { type Command, type Store } from "../store/store.js";
|
|
4
5
|
export declare const FEEDBACK_ROUNDS: readonly ["look_back"];
|
|
5
6
|
export type FeedbackRound = (typeof FEEDBACK_ROUNDS)[number];
|
|
@@ -55,9 +56,9 @@ export interface OpenedRound {
|
|
|
55
56
|
* agent (closed history: a grade of it starts no paid work), and one the store opens again (an agentic run that answered
|
|
56
57
|
* or that a person stopped). Null when the grade asks for nothing more, or the run can't be opened again (the grade is
|
|
57
58
|
* kept either way). */
|
|
58
|
-
export declare function openFeedbackRound(store: Pick<Store, "runs" | "agents">, grade: Grade, label: string | undefined): Promise<OpenedRound | null>;
|
|
59
|
+
export declare function openFeedbackRound(store: Pick<Store, "runs" | "agents">, grade: Grade, label: string | undefined, canTurn?: (launch: RunLaunch) => boolean): Promise<OpenedRound | null>;
|
|
59
60
|
/** A grade's write (PUT /runs/{id}/grade): keeps `grade` for agent `agentId` naming no round, opens its run again on the
|
|
60
61
|
* round it asks for (openFeedbackRound), and only then marks the kept grade with that round and its steer. The grade is
|
|
61
62
|
* kept first, so the round's end reads it; the round is named last, so a reopen that fails (thrown, or a run that can't
|
|
62
63
|
* be opened again) leaves a grade naming none, never one claiming a round that didn't open. The grade as kept. */
|
|
63
|
-
export declare function keepGrade(store: Pick<Store, "runs" | "agents" | "settings">, agentId: string, grade: Grade, label: string | undefined): Promise<Grade>;
|
|
64
|
+
export declare function keepGrade(store: Pick<Store, "runs" | "agents" | "settings">, agentId: string, grade: Grade, label: string | undefined, canTurn?: (launch: RunLaunch) => boolean): Promise<Grade>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// A grade's feedback round: what a run's grade (PUT /runs/{id}/grade, a person's feedback or an eval's label) asks of its
|
|
2
2
|
// learning, and how the run's next end reads it. The run's path is who wrote its final answer, so a grade never makes
|
|
3
3
|
// the agent answer the job again:
|
|
4
|
-
// - a run its learned workflow answered alone (path `workflow`), graded right or wrong: the grade is kept
|
|
5
|
-
// hold, replay and refit read it) and nothing else happens: no round, no turn, $0. One wrong answer is one sample;
|
|
6
|
-
// the graded hold reads it among the workflow's others, and a hold asks the workflow's revision (learning-end.ts
|
|
7
|
-
// compileAskOf);
|
|
4
|
+
// - a run its learned workflow answered alone (path `workflow`), graded right or wrong: the grade is kept and nothing else happens: no round, no turn, $0. One wrong answer is one sample;
|
|
8
5
|
// - a run the agent finished (path `agent` or `handed_back`) graded with words (`label`): a look-back round on them
|
|
9
6
|
// (#2579's later round, notes). The run opens again on it: the grade's words are on its record, the agent is asked no
|
|
10
7
|
// turn of the job's, and the run goes straight to its end-of-run turn, which reads the words. Its spend is learning
|
|
@@ -71,7 +68,7 @@ export function feedbackStatus(entries, command) {
|
|
|
71
68
|
* agent (closed history: a grade of it starts no paid work), and one the store opens again (an agentic run that answered
|
|
72
69
|
* or that a person stopped). Null when the grade asks for nothing more, or the run can't be opened again (the grade is
|
|
73
70
|
* kept either way). */
|
|
74
|
-
export async function openFeedbackRound(store, grade, label) {
|
|
71
|
+
export async function openFeedbackRound(store, grade, label, canTurn = () => true) {
|
|
75
72
|
const words = label?.trim() ? label.trim() : undefined;
|
|
76
73
|
const round = feedbackRoundOf(grade, words);
|
|
77
74
|
if (!round || !words)
|
|
@@ -87,6 +84,10 @@ export async function openFeedbackRound(store, grade, label) {
|
|
|
87
84
|
const learning = launch?.learning;
|
|
88
85
|
if (!learning || learning.use)
|
|
89
86
|
return null;
|
|
87
|
+
// The round is a turn of the run with no caller's model key (a grade hands none): where the server holds no key for the
|
|
88
|
+
// run's route (`canTurn` false), the grade is kept and the run is not opened again, never left to fail with no key.
|
|
89
|
+
if (launch && !canTurn(launch))
|
|
90
|
+
return null;
|
|
90
91
|
const feedback = { round, correct: grade.correct };
|
|
91
92
|
try {
|
|
92
93
|
const steer = await store.runs.reopen(grade.run, { kind: "steer", body: { text: words, feedback } });
|
|
@@ -102,8 +103,8 @@ export async function openFeedbackRound(store, grade, label) {
|
|
|
102
103
|
* round it asks for (openFeedbackRound), and only then marks the kept grade with that round and its steer. The grade is
|
|
103
104
|
* kept first, so the round's end reads it; the round is named last, so a reopen that fails (thrown, or a run that can't
|
|
104
105
|
* be opened again) leaves a grade naming none, never one claiming a round that didn't open. The grade as kept. */
|
|
105
|
-
export async function keepGrade(store, agentId, grade, label) {
|
|
106
|
+
export async function keepGrade(store, agentId, grade, label, canTurn) {
|
|
106
107
|
const kept = await putGrade(store.settings, agentId, { ...grade, feedback: null });
|
|
107
|
-
const opened = await openFeedbackRound(store, kept, label);
|
|
108
|
+
const opened = await openFeedbackRound(store, kept, label, canTurn);
|
|
108
109
|
return opened ? markGradeRound(store.settings, agentId, kept, opened) : kept;
|
|
109
110
|
}
|
|
@@ -8,17 +8,17 @@ import { nativeOf } from "../native/binding.js";
|
|
|
8
8
|
// - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
|
|
9
9
|
// harness is pi), so the revision is read here to tell it from an agentic pi run;
|
|
10
10
|
// - a built-in learning run (its launch names harness "learning") runs on the learning loop;
|
|
11
|
-
// - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch)
|
|
11
|
+
// - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch), and so does a harness a
|
|
12
|
+
// module adds with no adapter facts of its own, on its runner's adapter;
|
|
12
13
|
// - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
|
|
13
14
|
// - anything else fails the run in words (the dispatch's UnknownHarness).
|
|
15
|
+
import { harnessOf } from "../harness-table.js";
|
|
14
16
|
import { hostMemory, neverFits } from "../host.js";
|
|
15
17
|
import { resolveHarness } from "./adapters/index.js";
|
|
16
18
|
import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
|
|
17
19
|
import { createAdapterLoop } from "./adapter-loop.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { FAUX_ENV } from "../model.js";
|
|
21
|
-
import { generalThresholdOf } from "../learn/general.js";
|
|
20
|
+
import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
21
|
+
import { noServerKeyFor } from "../run-model-key.js";
|
|
22
22
|
import { createDispatchLoop } from "./dispatch.js";
|
|
23
23
|
import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
|
|
24
24
|
import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
|
|
@@ -48,7 +48,14 @@ export function resolveRunnerLoop(deps) {
|
|
|
48
48
|
if (harness !== "learning" && launch.sdk)
|
|
49
49
|
return createSdkLoop(launch, deps, async () => {
|
|
50
50
|
const base = deps.env ?? process.env;
|
|
51
|
+
// An SDK run's look-back runs after its backend reported it complete, on no run's key: on a server that holds no
|
|
52
|
+
// gateway key it is skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
51
53
|
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
54
|
+
const off = noServerKeyFor(env, "An SDK run's look-back");
|
|
55
|
+
if (off) {
|
|
56
|
+
deps.log?.(off);
|
|
57
|
+
throw new Error(off);
|
|
58
|
+
}
|
|
52
59
|
return gradeRouteFor({ model: launch.learning.gradeModel, agentId: run.agentId }, env, deps.routeOf);
|
|
53
60
|
});
|
|
54
61
|
if (harness !== "learning" && launch.native)
|
|
@@ -73,43 +80,44 @@ export function resolveRunnerLoop(deps) {
|
|
|
73
80
|
// at each grade, so a key saved with no restart grades the next learning run.
|
|
74
81
|
routeOf: async (grade) => {
|
|
75
82
|
const base = deps.env ?? process.env;
|
|
83
|
+
// A learning run grades after its source run's turn ended, on no run's key (a run that brought its own queues no
|
|
84
|
+
// grade: learning-end.ts spendOff): on a server that holds no gateway key it is skipped in words
|
|
85
|
+
// (run-model-key.ts noServerKeyFor). Nothing is sent; the learning run ends dropped.
|
|
76
86
|
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
87
|
+
const off = noServerKeyFor(env, "A learning run's grade");
|
|
88
|
+
if (off) {
|
|
89
|
+
deps.log?.(off);
|
|
90
|
+
throw new Error(off);
|
|
91
|
+
}
|
|
77
92
|
return gradeRouteFor(grade, env, deps.routeOf);
|
|
78
93
|
},
|
|
79
94
|
...(deps.log ? { log: deps.log } : {}),
|
|
80
95
|
...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
|
|
81
|
-
// The generality pre-check (learn/general.ts) on this host's Jev, built as a learning end builds its check's
|
|
82
|
-
// decision providers (hostDecisionKeys: the runner's environment first, then the key saved in Settings), on the
|
|
83
|
-
// client and model a workflow's decision node gets when it names none. No Jev key: none asked. A faux host asks only
|
|
84
|
-
// its faux Jev (FAUX_JEV_ENV), as its grade goes only to the faux route: a key it inherited never sends a note out.
|
|
85
|
-
jev: async () => {
|
|
86
|
-
const env = deps.env ?? process.env;
|
|
87
|
-
if (env[FAUX_ENV] && !env[FAUX_JEV_ENV])
|
|
88
|
-
return undefined;
|
|
89
|
-
return (await decisionProvidersIn({ ...env, ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, [DEFAULT_DECISION_PROVIDER])) }))?.providers[DEFAULT_DECISION_PROVIDER];
|
|
90
|
-
},
|
|
91
|
-
generalThreshold: generalThresholdOf(deps.env ?? process.env),
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
|
-
// The harness's own entry decides which spec builds the run, by the entry
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
+
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
99
|
+
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
100
|
+
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
101
|
+
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
102
|
+
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
103
|
+
const env = deps.env ?? process.env;
|
|
104
|
+
const runner = resolveHarness(harness, env);
|
|
98
105
|
if (runner) {
|
|
99
106
|
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
100
107
|
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
101
108
|
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
102
109
|
// the host's memory and its OOM kill would take every run on it.
|
|
103
|
-
const tooBig = neverFits(harness, hostMemory());
|
|
110
|
+
const tooBig = neverFits(harness, hostMemory(), env);
|
|
104
111
|
if (tooBig)
|
|
105
112
|
throw new NeverFits(tooBig);
|
|
113
|
+
const entry = harnessOf(env, harness);
|
|
106
114
|
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
107
115
|
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
108
116
|
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
109
117
|
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
110
|
-
return createAdapterLoop((claim, adapterRun) =>
|
|
118
|
+
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
111
119
|
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
112
|
-
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim), deps.modelRetry ?? {});
|
|
120
|
+
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
113
121
|
}
|
|
114
122
|
return undefined;
|
|
115
123
|
};
|
|
@@ -97,13 +97,6 @@ export declare const KINDS: {
|
|
|
97
97
|
* sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
|
|
98
98
|
* call nor a message. */
|
|
99
99
|
readonly nodeModel: "agentrun.node.model";
|
|
100
|
-
/** A learning run's generality pre-check (learn/general.ts), its Jev requests about to leave: committed and made
|
|
101
|
-
* durable before they do, as a grade request's record is (learning-ask.ts bookedAsk), so a restart that finds one with
|
|
102
|
-
* no answer after it books what they spent as unknown (null) before it asks again. Paid, and Jev dedupes none. */
|
|
103
|
-
readonly learningGeneralSent: "agentrun.learning.general.sent";
|
|
104
|
-
/** That check's end, kept before the grader starts: its scores, or why it could not run (`unchecked`), and what it spent.
|
|
105
|
-
* A restart reuses it and never asks Jev again. */
|
|
106
|
-
readonly learningGeneral: "agentrun.learning.general";
|
|
107
100
|
/** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
|
|
108
101
|
readonly learningGraded: "agentrun.learning.graded";
|
|
109
102
|
/** A learning run's merge: the new main and its commit, with the run's end. */
|
|
@@ -247,6 +240,11 @@ export interface MessageData {
|
|
|
247
240
|
* answer's output tokens when known. The loop reads it as pi's stopReason (loop.ts cutLast). */
|
|
248
241
|
readonly stopReason?: "length";
|
|
249
242
|
readonly outputTokens?: number;
|
|
243
|
+
/** The limit it was cut at was the run's cap's (turn_end's capCut): the cap, and the least cap that finishes it. */
|
|
244
|
+
readonly capCut?: {
|
|
245
|
+
readonly capUsd: number;
|
|
246
|
+
readonly raiseToUsd: number;
|
|
247
|
+
};
|
|
250
248
|
/** When it was written (ms, the loop's clock): the Timeline dates the message's row by it. */
|
|
251
249
|
readonly at?: number;
|
|
252
250
|
}
|
|
@@ -97,13 +97,6 @@ export const KINDS = {
|
|
|
97
97
|
* sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
|
|
98
98
|
* call nor a message. */
|
|
99
99
|
nodeModel: "agentrun.node.model",
|
|
100
|
-
/** A learning run's generality pre-check (learn/general.ts), its Jev requests about to leave: committed and made
|
|
101
|
-
* durable before they do, as a grade request's record is (learning-ask.ts bookedAsk), so a restart that finds one with
|
|
102
|
-
* no answer after it books what they spent as unknown (null) before it asks again. Paid, and Jev dedupes none. */
|
|
103
|
-
learningGeneralSent: "agentrun.learning.general.sent",
|
|
104
|
-
/** That check's end, kept before the grader starts: its scores, or why it could not run (`unchecked`), and what it spent.
|
|
105
|
-
* A restart reuses it and never asks Jev again. */
|
|
106
|
-
learningGeneral: "agentrun.learning.general",
|
|
107
100
|
/** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
|
|
108
101
|
learningGraded: "agentrun.learning.graded",
|
|
109
102
|
/** A learning run's merge: the new main and its commit, with the run's end. */
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { BeforeRequest } from "@parcha/agentrun-kernel";
|
|
2
|
-
import type { DecisionProvider } from "@parcha/agentrun-dsl";
|
|
3
|
-
import { type GeneralSource } from "../learn/general.js";
|
|
4
|
-
import type { NoteText } from "../learn/grade.js";
|
|
5
2
|
import { type GraderRoute } from "./learning-ask.js";
|
|
6
3
|
import type { LoopFactory } from "./loop-contract.js";
|
|
7
4
|
import type { Store } from "../store/store.js";
|
|
@@ -27,11 +24,6 @@ export interface LearningDispatchDeps {
|
|
|
27
24
|
readonly now?: () => number;
|
|
28
25
|
/** For tests: the grade's bound, as a signal. Default: GRADE_TIMEOUT_MS from the ask. */
|
|
29
26
|
readonly gradeBound?: () => AbortSignal;
|
|
30
|
-
/** This host's Jev, for the generality pre-check (learn/general.ts): undefined when it has no Jev key, read at each
|
|
31
|
-
* learning run so a key saved in Settings with no restart is used by the next one. */
|
|
32
|
-
readonly jev?: () => Promise<DecisionProvider | undefined>;
|
|
33
|
-
/** The bar a note's Jev score must reach to be graded (learn/general.ts generalThresholdOf). */
|
|
34
|
-
readonly generalThreshold?: number;
|
|
35
27
|
}
|
|
36
28
|
/** The grade's route for `model` (the grade model the server names; undefined, the agent's own), from the runner's one
|
|
37
29
|
* route (`routeOf`), but where this host reaches the model's vendor only through OpenRouter (provider.ts
|
|
@@ -49,13 +41,5 @@ export declare function gradeRouteOf(model: string | undefined, env: NodeJS.Proc
|
|
|
49
41
|
* output bound as the least it may be sent with, so a grade never runs on a cut answer. Another model than the route's is
|
|
50
42
|
* priced by nothing here: refused. */
|
|
51
43
|
export declare function gradeCap(capUsd: number, route: GraderRoute): BeforeRequest;
|
|
52
|
-
/** The worst case of the generality check's requests to `jev` (learn/general.ts generalRequest, one a note), each held as a
|
|
53
|
-
* workflow's decision is under its run's cap (decision-cap.ts holdOf); unpriced when any one's price is not known
|
|
54
|
-
* here. */
|
|
55
|
-
export declare function generalHeld(jev: DecisionProvider, notes: readonly NoteText[], source: GeneralSource): Promise<{
|
|
56
|
-
usd: number;
|
|
57
|
-
} | {
|
|
58
|
-
unpriced: string;
|
|
59
|
-
}>;
|
|
60
44
|
/** The loop for a launch of harness "learning": the runner's dispatch calls it for each such run it claims. */
|
|
61
45
|
export declare function learningLoopOf(deps: LearningDispatchDeps): LoopFactory;
|
|
@@ -7,23 +7,15 @@
|
|
|
7
7
|
// learning-end.ts gradeCapOf), and each grader call is judged against it before it leaves by the kernel's one rule
|
|
8
8
|
// (beforeRequestOf, over the learning run's one booking) at its worst case: its input uncached and its whole output bound
|
|
9
9
|
// (GRADE_MAX_TOKENS), never cut down to fit, so a verdict is never lost to a short answer. A call that doesn't fit is
|
|
10
|
-
// never sent, and the grade is skipped, said so (learning-loop.ts GradeOverCap).
|
|
11
|
-
// are the grade's spend too: before they leave, their worst case (decision-cap.ts holdOf: the rule a workflow's
|
|
12
|
-
// decision is held at under its run's cap) is judged against the same cap, less what an earlier attempt's cut check may
|
|
13
|
-
// have spent; a check that doesn't fit is never sent, and is skipped, said so (learning-loop.ts GeneralOverCap), the
|
|
14
|
-
// grader then judged on its own. What the check spent is outside the grade's records, so each grader call's room is the
|
|
15
|
-
// cap less it (the ask's `beside`: its kept dollars, else its worst case). An uncapped run's grade is capped by nothing. A
|
|
10
|
+
// never sent, and the grade is skipped, said so (learning-loop.ts GradeOverCap). An uncapped run's grade is capped by nothing. A
|
|
16
11
|
// grader that never answers is cut at the grade's bound, and what it spent is unknown (null).
|
|
17
12
|
import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
|
-
import { money } from "../cap.js";
|
|
19
|
-
import { holdOf } from "../decision-cap.js";
|
|
20
|
-
import { generalRequest, generalScores } from "../learn/general.js";
|
|
21
13
|
import { FAUX_ENV } from "../model.js";
|
|
22
14
|
import { anthropicModelId, openRouterOnly, providerFor } from "../provider.js";
|
|
23
15
|
import { capModelOf } from "./adapter-run-spec.js";
|
|
24
16
|
import { bookedAsk } from "./learning-ask.js";
|
|
25
17
|
import { learningLoopFactory } from "./learning-factory.js";
|
|
26
|
-
import {
|
|
18
|
+
import { GRADE_TIMEOUT_MS } from "./learning-loop.js";
|
|
27
19
|
/** The model a grade runs on, main's order: the grade model the server names, else the agent's own (the model its
|
|
28
20
|
* revision names), else none (the host's default, which the route picks). */
|
|
29
21
|
export const gradeModelFor = (grade) => grade.model ?? grade.own;
|
|
@@ -81,19 +73,6 @@ export function gradeCap(capUsd, route) {
|
|
|
81
73
|
const judge = beforeRequestOf({ capUsd: () => capUsd, modelOf: (id) => (id === route.model ? model : undefined) });
|
|
82
74
|
return (request) => judge({ ...request, ...(request.outputTokensAsked !== undefined ? { outputTokensLeast: request.outputTokensAsked } : {}) });
|
|
83
75
|
}
|
|
84
|
-
/** The worst case of the generality check's requests to `jev` (learn/general.ts generalRequest, one a note), each held as a
|
|
85
|
-
* workflow's decision is under its run's cap (decision-cap.ts holdOf); unpriced when any one's price is not known
|
|
86
|
-
* here. */
|
|
87
|
-
export async function generalHeld(jev, notes, source) {
|
|
88
|
-
let usd = 0;
|
|
89
|
-
for (const note of notes) {
|
|
90
|
-
const hold = await holdOf(jev, generalRequest(note, source));
|
|
91
|
-
if ("unpriced" in hold)
|
|
92
|
-
return hold;
|
|
93
|
-
usd += hold.usd;
|
|
94
|
-
}
|
|
95
|
-
return { usd };
|
|
96
|
-
}
|
|
97
76
|
/** The loop for a launch of harness "learning": the runner's dispatch calls it for each such run it claims. */
|
|
98
77
|
export function learningLoopOf(deps) {
|
|
99
78
|
return (loopDeps) => {
|
|
@@ -105,31 +84,9 @@ export function learningLoopOf(deps) {
|
|
|
105
84
|
const route = await deps.routeOf(grade.route);
|
|
106
85
|
// The loop's own signal (a stop, a lost claim, its bound) and the grade's bound, both: whichever ends first cuts it.
|
|
107
86
|
const bound = deps.gradeBound ? deps.gradeBound() : AbortSignal.timeout(GRADE_TIMEOUT_MS);
|
|
108
|
-
|
|
109
|
-
// records is counted.
|
|
110
|
-
const capUsd = grade.capUsd === undefined ? undefined : Math.max(0, grade.capUsd - (request.beside ?? 0));
|
|
111
|
-
return bookedAsk({ ...route, ...(capUsd !== undefined ? { beforeRequest: gradeCap(capUsd, route) } : {}) })(request, AbortSignal.any([signal, bound]), run);
|
|
112
|
-
};
|
|
113
|
-
// The generality pre-check on this host's Jev; none set up here, none asked. Under a cap, its requests' worst case
|
|
114
|
-
// is judged against what the cap leaves (less `before`, an earlier attempt's cut check's) before any leaves.
|
|
115
|
-
const general = async (notes, source, signal, run, sending, before) => {
|
|
116
|
-
const jev = await deps.jev?.();
|
|
117
|
-
if (!jev)
|
|
118
|
-
return undefined;
|
|
119
|
-
if (claimed === undefined)
|
|
120
|
-
throw new Error("the learning run's generality check was asked before its claim");
|
|
121
|
-
const { capUsd } = await gradeOf(deps.store, claimed);
|
|
122
|
-
if (capUsd === undefined)
|
|
123
|
-
return generalScores(jev, notes, source, signal, run, sending && (() => sending()));
|
|
124
|
-
const held = await generalHeld(jev, notes, source);
|
|
125
|
-
const room = Math.max(0, capUsd - (before ?? 0));
|
|
126
|
-
if ("unpriced" in held)
|
|
127
|
-
throw new GeneralOverCap(held.unpriced, true);
|
|
128
|
-
if (held.usd > room)
|
|
129
|
-
throw new GeneralOverCap(`its worst case of ${money(held.usd)} is over the ${money(room)} the cap leaves`, false);
|
|
130
|
-
return generalScores(jev, notes, source, signal, run, sending && (() => sending(held.usd)));
|
|
87
|
+
return bookedAsk({ ...route, ...(grade.capUsd !== undefined ? { beforeRequest: gradeCap(grade.capUsd, route) } : {}) })(request, AbortSignal.any([signal, bound]), run);
|
|
131
88
|
};
|
|
132
|
-
const loop = learningLoopFactory({ store: deps.store, data: deps.data, ask, ...(deps.sourceInstructions ? { sourceInstructions: deps.sourceInstructions } : {}), ...(deps.
|
|
89
|
+
const loop = learningLoopFactory({ store: deps.store, data: deps.data, ask, ...(deps.sourceInstructions ? { sourceInstructions: deps.sourceInstructions } : {}), ...(deps.log ? { log: deps.log } : {}), ...(deps.now ? { now: deps.now } : {}) })(loopDeps);
|
|
133
90
|
return {
|
|
134
91
|
start: (claim) => {
|
|
135
92
|
claimed = claim.runId;
|