@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.43
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 +21 -0
- package/README.md +8 -7
- package/dist/console/assets/index-BrcDSBD8.css +1 -0
- package/dist/console/assets/{index-DYJ_wj27.js → index-Bz6IWncl.js} +186 -186
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/import-sources.js +25 -5
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +86 -200
- package/dist/learn/promote.js +57 -183
- 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.js +2 -4
- package/dist/learn/workflow-nodes.d.ts +1 -2
- package/dist/learn/workflow-nodes.js +2 -3
- 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 +11 -4
- package/dist/learning-cost.js +4 -2
- package/dist/learning-routes.js +1 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/openapi.js +95 -55
- 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/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +17 -2
- package/dist/runner/adapter-run-spec.js +16 -5
- package/dist/runner/audit.d.ts +64 -0
- package/dist/runner/audit.js +338 -0
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +15 -5
- package/dist/runner/feedback-round.js +1 -4
- package/dist/runner/harness-loops.js +1 -15
- package/dist/runner/journal-kinds.d.ts +0 -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 +52 -13
- package/dist/runner/learning-end.js +124 -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/main.js +1 -1
- package/dist/runner/promotion.d.ts +50 -54
- package/dist/runner/promotion.js +191 -583
- package/dist/runner/reflect-hook.d.ts +10 -0
- package/dist/runner/reflect-hook.js +6 -0
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/server.js +61 -16
- package/dist/store/sqlite/store.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/learning.d.ts +17 -6
- package/dist/store-reads/learning.js +36 -23
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-view.js +12 -2
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +9 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- 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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord/context";
|
|
2
|
+
import { type AuditLoop } from "../learning-setting.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
4
|
+
import { type RunRow, type Store } from "../store/store.js";
|
|
5
|
+
import { type LearningFolder } from "../learn/folder.js";
|
|
6
|
+
import type { Shown } from "../learning.js";
|
|
7
|
+
import type { EndOfRunTurn } from "./loop-contract.js";
|
|
8
|
+
import { type WorkflowFirst } from "./workflow-first.js";
|
|
9
|
+
/** What the audit reads and writes at a claim (or the server's grade): the agent, the run claimed (none for a grade),
|
|
10
|
+
* its revision (whose definition holds the numbers) and launch, the agent's learning folder, the host's secrets as a
|
|
11
|
+
* hold's texts are cut of them (`shown`, as a check's are), the seal key (a shadow is handed the per_run MCP
|
|
12
|
+
* credentials its served run was). */
|
|
13
|
+
export type AuditDeps = {
|
|
14
|
+
readonly store: Store;
|
|
15
|
+
readonly agentId: string;
|
|
16
|
+
readonly revisionId: string;
|
|
17
|
+
readonly context: Context;
|
|
18
|
+
readonly folder: () => LearningFolder;
|
|
19
|
+
readonly shown: () => Promise<Pick<Shown, "text">>;
|
|
20
|
+
readonly log: (line: string) => void;
|
|
21
|
+
readonly sealKey?: Buffer;
|
|
22
|
+
readonly now?: () => number;
|
|
23
|
+
};
|
|
24
|
+
/** The words a second hold within stop_window leaves on its record: what the owner reads. */
|
|
25
|
+
export declare const STOPPED_TWICE = "stopped: the workflow disagreed with the agent twice";
|
|
26
|
+
/** The audit numbers of revision `revisionId`'s definition (each one it leaves out at its default). */
|
|
27
|
+
export declare function auditLoopOfRevision(store: Pick<Store, "agents">, revisionId: string): Promise<AuditLoop>;
|
|
28
|
+
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
29
|
+
* started them): what the promotions read counts beside the audit line. */
|
|
30
|
+
export declare function notAuditableOf(store: Pick<Store, "runs">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
|
31
|
+
/** The words a shadow run ends failed with where it would wait on a person (AdapterRunSpec.neverWaits: an approval, a
|
|
32
|
+
* raise of its cap, which is what its served run's cap left, a question), what it would wait on after them: its row is
|
|
33
|
+
* `parked`, with no verdict. */
|
|
34
|
+
export declare const AUDIT_PARKED = "the audit ended where it would wait on a person";
|
|
35
|
+
/** The served run's end-of-run step `step` (none for a run that only uses what its agent learned), its audit started
|
|
36
|
+
* after it (startAudit) on an end the run reached on its own (a cut run starts none): the learned workflow that served
|
|
37
|
+
* it, read from its journal whatever claim it served on (servedOf), and, for a capped run, what its cap leaves once this
|
|
38
|
+
* end is counted (auditRoomOf: its job, its look-back, the grades beside it and the one this end queues). A run that
|
|
39
|
+
* could never be audited (no learning start, or not auditableLaunch) keeps `step` as it is. */
|
|
40
|
+
export declare function withAudit(step: EndOfRunTurn | undefined, deps: AuditDeps & {
|
|
41
|
+
readonly launch: RunLaunch;
|
|
42
|
+
}): EndOfRunTurn | undefined;
|
|
43
|
+
/** Starts the shadow of run `runId`, at its end, when the learned workflow `serve` served it first and its id is drawn:
|
|
44
|
+
* never for a replay or a shadow, a run that does not learn, one not auditable (auditableLaunch: a trigger started it,
|
|
45
|
+
* or it was handed files), nor a run of an agent that can call a tool that writes (auditWriterOf). A capped run's shadow
|
|
46
|
+
* is capped at what its cap leaves (`room`, read now: the served run spent all it will under it), so the two never
|
|
47
|
+
* spend past the served run's cap; with less than a run's smallest cap left (or a spend not known), no shadow is started
|
|
48
|
+
* and its row says `skipped: "no allowance"`. Its started line is appended first: a shadow is created only once the
|
|
49
|
+
* ledger names it (settlement finds it there, never in a window of runs), and one whose line could not be written is
|
|
50
|
+
* never created. Idempotent: one line and one shadow per run. */
|
|
51
|
+
export declare function startAudit(deps: AuditDeps & {
|
|
52
|
+
readonly runId: string;
|
|
53
|
+
readonly launch: RunLaunch;
|
|
54
|
+
readonly room?: () => Promise<number | null>;
|
|
55
|
+
}, serve: Pick<WorkflowFirst, "name" | "digest" | "replay"> | undefined): Promise<void>;
|
|
56
|
+
/** Writes the row of each open audit (a started line with no row yet) whose two runs, read by id, ended, the batch
|
|
57
|
+
* oldest served run first (the ledger's tail is its newest); a run that is gone (its shadow never created, say) ends it
|
|
58
|
+
* with no verdict. Then applies the hold rule over the ledger as it is now, rows added or not: the hold is a function of
|
|
59
|
+
* the ledger, so one a crash or a failed write lost after the rows were committed is made at the next claim. */
|
|
60
|
+
export declare function settleAudits(deps: AuditDeps): Promise<void>;
|
|
61
|
+
/** The row an owner's grade of served run `run` writes (source grade, agreed = the grade, counted for the digest's
|
|
62
|
+
* promotion now), then the hold rule: only for a run the workflow answered alone (its answer is the workflow's).
|
|
63
|
+
* Nothing else: no round, no compile by itself. */
|
|
64
|
+
export declare function gradeRow(deps: AuditDeps, run: RunRow, correct: boolean): Promise<void>;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// The shadow audit of a serving learned workflow, at a run's claim and its end (learn/audit.ts keeps the ledger).
|
|
2
|
+
// startAudit (withAudit: at the served run's end, before the end commits): a run the promoted workflow served first is
|
|
3
|
+
// drawn at 1 in k (auditDrawn, from its id), and a drawn one appends a `started` line to audits.jsonl (with the
|
|
4
|
+
// promotion serving it and the answer it audits, `turn`: the id of the run's newest answer row now), then starts its
|
|
5
|
+
// shadow run: the same agent and revision on the same input with learning off (no seed, no look-back), marked as the
|
|
6
|
+
// audit of the served run (launch.audit), no row of the run list, billed to the agent as learning cost. Its cap is
|
|
7
|
+
// what the served run's cap left (the two together never pass it; the served run's later gates count it beside them,
|
|
8
|
+
// learning-end.ts besideOf); none left, no shadow (`skipped: "no allowance"`). A shadow never waits on a person: where
|
|
9
|
+
// it would park (an approval its owner's setting asks, a raise of that cap, a question) it ends at once in
|
|
10
|
+
// AUDIT_PARKED's words (AdapterRunSpec.neverWaits, the gate untouched: nothing is let through, no one is asked to
|
|
11
|
+
// answer), and its row is `parked`. Only a run started over the API (no trigger: its context is never rebuilt for a
|
|
12
|
+
// shadow) of an agent every tool of which only reads (learn/audit.ts auditWriterOf, the replay's readOnlyHint rule): a
|
|
13
|
+
// shadow never writes again.
|
|
14
|
+
// settleAudits: each open started line (no result row yet) whose two runs, read by id, ended writes its row (agreed:
|
|
15
|
+
// the audited answer, its `turn`'s, and the shadow's say the same, learn/promote.ts sameAnswer; a follow-up's answer
|
|
16
|
+
// since is never read), oldest served run first; then, rows added or not, the hold rule reads the serving revisions'
|
|
17
|
+
// rows: a hold is a function of the ledger alone.
|
|
18
|
+
// applyHold: at least hold_disagree disagreements in the newest hold_window rows of the digest's current promotion
|
|
19
|
+
// hold the workflow (a promotion hold carrying `audit`, with those rows, each text cut of the host's secrets before
|
|
20
|
+
// it is shortened, learn/secrets.ts excerptShown): the agent's next run asks one recompile with them as data
|
|
21
|
+
// (runner/learning-end.ts compileAskOf), which S3a's check decides on its inputs plus the disagreeing ones. A second
|
|
22
|
+
// hold within stop_window served runs of the first stops it: no compile, the stop said on the record.
|
|
23
|
+
// gradeRow: an owner's grade on a run the workflow answered alone is a row too (source grade, agreed = the grade).
|
|
24
|
+
// Every number is the agent definition's (learning-setting.ts auditLoopOf). Nothing here fails a claim: a failure is logged.
|
|
25
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
26
|
+
import { overCapMessage } from "@parcha/agentrun-kernel/kernel/cap";
|
|
27
|
+
import { auditLoopOf } from "../learning-setting.js";
|
|
28
|
+
import { RUN_CAP_MIN_USD } from "../learning-batch.js";
|
|
29
|
+
import { SERVED_PATHS } from "../learning-cost.js";
|
|
30
|
+
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
31
|
+
import { runEntries } from "../store-reads/journal.js";
|
|
32
|
+
import { FINAL_STATES, StoreConstraint } from "../store/store.js";
|
|
33
|
+
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
34
|
+
import { isObject } from "../validate.js";
|
|
35
|
+
import { auditableLaunch, auditChange, auditEveryOf, auditDrawn, auditsOffWords, auditWriterOf, holdOf, ledgerOf, lineKey, openAudits, rowsOf, shadowRunId } from "../learn/audit.js";
|
|
36
|
+
import { lastRunsOf } from "../learn/compile.js";
|
|
37
|
+
import { readLearning, writeLearning } from "../learn/folder.js";
|
|
38
|
+
import { CHECK_TEXT_MAX, promotionOf, promotionsOf, promotionStartOf, recordPromotion, sameAnswer, servingOf } from "../learn/promote.js";
|
|
39
|
+
import { excerptShown } from "../learn/secrets.js";
|
|
40
|
+
import { auditRoomOf } from "./learning-end.js";
|
|
41
|
+
import { answerOf, answerRowOf } from "./promotion.js";
|
|
42
|
+
import { servedOf } from "./workflow-first.js";
|
|
43
|
+
/** The words a second hold within stop_window leaves on its record: what the owner reads. */
|
|
44
|
+
export const STOPPED_TWICE = "stopped: the workflow disagreed with the agent twice";
|
|
45
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
46
|
+
const ended = (row) => row !== undefined && FINAL_STATES.includes(row.state) && row.runner === null;
|
|
47
|
+
const inputText = (input) => (typeof input === "string" ? input : JSON.stringify(input) ?? "");
|
|
48
|
+
const metricsOf = (row) => (isObject(row?.metrics) ? row.metrics : {});
|
|
49
|
+
const served = (row) => SERVED_PATHS.includes(metricsOf(row).path);
|
|
50
|
+
/** A line's `turn` (AuditRow.turn): the answer row's id, none when the run had no answer. */
|
|
51
|
+
const turnOf = (id) => (id === undefined ? {} : { turn: id });
|
|
52
|
+
/** The answer an audit row is of: its `turn`'s, read from the run by that row's id; none when it names none. */
|
|
53
|
+
const auditedAnswer = (deps, row) => (row.turn === undefined ? Promise.resolve(null) : answerOf(deps.store, row.run, deps.context, row.turn));
|
|
54
|
+
/** The audit numbers of revision `revisionId`'s definition (each one it leaves out at its default). */
|
|
55
|
+
export async function auditLoopOfRevision(store, revisionId) {
|
|
56
|
+
try {
|
|
57
|
+
return auditLoopOf((await store.agents.revision(revisionId))?.body?.learning);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return auditLoopOf(undefined);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The served runs of `workflow` (at `digest` when given) that `keep` keeps too, the newest `n` of them (lastRunsOf: the
|
|
64
|
+
* shadows and the agent's own runs among them never push one out of the read). */
|
|
65
|
+
const servedRuns = (store, agentId, n, workflow, digest, keep = () => true) => lastRunsOf(store, agentId, n, (row) => served(row) && metricsOf(row).workflow === workflow && (digest === undefined || metricsOf(row).workflow_digest === digest) && keep(row));
|
|
66
|
+
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
67
|
+
* started them): what the promotions read counts beside the audit line. */
|
|
68
|
+
export async function notAuditableOf(store, agentId, workflow, digest, loop) {
|
|
69
|
+
return (await servedRuns(store, agentId, loop.stop_window, workflow, digest)).filter((row) => metricsOf(row).not_auditable === true).length;
|
|
70
|
+
}
|
|
71
|
+
/** The words a shadow run ends failed with where it would wait on a person (AdapterRunSpec.neverWaits: an approval, a
|
|
72
|
+
* raise of its cap, which is what its served run's cap left, a question), what it would wait on after them: its row is
|
|
73
|
+
* `parked`, with no verdict. */
|
|
74
|
+
export const AUDIT_PARKED = "the audit ended where it would wait on a person";
|
|
75
|
+
/** The served run's end-of-run step `step` (none for a run that only uses what its agent learned), its audit started
|
|
76
|
+
* after it (startAudit) on an end the run reached on its own (a cut run starts none): the learned workflow that served
|
|
77
|
+
* it, read from its journal whatever claim it served on (servedOf), and, for a capped run, what its cap leaves once this
|
|
78
|
+
* end is counted (auditRoomOf: its job, its look-back, the grades beside it and the one this end queues). A run that
|
|
79
|
+
* could never be audited (no learning start, or not auditableLaunch) keeps `step` as it is. */
|
|
80
|
+
export function withAudit(step, deps) {
|
|
81
|
+
if (!deps.launch.learning || !auditableLaunch(deps.launch))
|
|
82
|
+
return step;
|
|
83
|
+
return async (input) => {
|
|
84
|
+
const rows = step ? await step(input) : undefined;
|
|
85
|
+
if (input.cut === undefined)
|
|
86
|
+
await auditAtEnd(deps, input.runId, rows?.also ?? []);
|
|
87
|
+
return rows;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function auditAtEnd(deps, runId, queued) {
|
|
91
|
+
try {
|
|
92
|
+
const entries = await runEntries(deps.store, runId, BACKGROUND_CONTEXT);
|
|
93
|
+
const served = servedOf(entries);
|
|
94
|
+
if (!served?.digest)
|
|
95
|
+
return;
|
|
96
|
+
const capUsd = deps.launch.maxCostUsd;
|
|
97
|
+
await startAudit({ ...deps, runId, ...(capUsd !== undefined ? { room: () => auditRoomOf(deps.store, runId, capUsd, entries, queued) } : {}) }, { name: served.workflow, digest: served.digest });
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
deps.log(`workflow-first: the audit of this run did not start (${error?.message ?? error})`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Starts the shadow of run `runId`, at its end, when the learned workflow `serve` served it first and its id is drawn:
|
|
104
|
+
* never for a replay or a shadow, a run that does not learn, one not auditable (auditableLaunch: a trigger started it,
|
|
105
|
+
* or it was handed files), nor a run of an agent that can call a tool that writes (auditWriterOf). A capped run's shadow
|
|
106
|
+
* is capped at what its cap leaves (`room`, read now: the served run spent all it will under it), so the two never
|
|
107
|
+
* spend past the served run's cap; with less than a run's smallest cap left (or a spend not known), no shadow is started
|
|
108
|
+
* and its row says `skipped: "no allowance"`. Its started line is appended first: a shadow is created only once the
|
|
109
|
+
* ledger names it (settlement finds it there, never in a window of runs), and one whose line could not be written is
|
|
110
|
+
* never created. Idempotent: one line and one shadow per run. */
|
|
111
|
+
export async function startAudit(deps, serve) {
|
|
112
|
+
const { store, agentId, runId, launch, log } = deps;
|
|
113
|
+
if (!serve || serve.replay || launch.replay || launch.audit || !launch.learning || !auditableLaunch(launch))
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
// Read after the claim pinned the revision's MCP tools (mcp-claim.ts pinFirst): the pin a revision saved without one
|
|
117
|
+
// takes at its first run is what its tools are classed by.
|
|
118
|
+
const revision = await store.agents.revision(deps.revisionId);
|
|
119
|
+
const writer = auditWriterOf(revision);
|
|
120
|
+
if (writer !== undefined) {
|
|
121
|
+
log(`workflow-first: ${serve.name} at ${serve.digest} serves this run, never audited: ${auditsOffWords(writer)}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const loop = auditLoopOf(revision?.body?.learning);
|
|
125
|
+
const before = (await servedRuns(store, agentId, loop.audit_later_after, serve.name, serve.digest, (row) => row.id !== runId)).length;
|
|
126
|
+
const k = auditEveryOf(loop, before);
|
|
127
|
+
if (!auditDrawn(runId, k))
|
|
128
|
+
return;
|
|
129
|
+
const id = shadowRunId(runId);
|
|
130
|
+
// Once per run: an end after a follow-up finds its shadow made, or its row written (skipped, or settled). A started
|
|
131
|
+
// line with no shadow (a crash between the two) is made now.
|
|
132
|
+
if (await store.runs.get(id))
|
|
133
|
+
return;
|
|
134
|
+
if ((await readLedger(deps)).some((line) => line.run === runId && line.source === "shadow"))
|
|
135
|
+
return;
|
|
136
|
+
const promoted = promotionStartOf(await promotionsOf(store.settings, agentId), serve.name, serve.digest);
|
|
137
|
+
// The answer audited: the run's newest answer now, at the end that drew it, kept by its row's id so a follow-up's
|
|
138
|
+
// answer since is never the one compared.
|
|
139
|
+
const turn = turnOf((await answerRowOf(store, runId, deps.context))?.id);
|
|
140
|
+
// What the served run's cap leaves its shadow (none for an uncapped run), to a millionth, never above it.
|
|
141
|
+
const room = deps.room ? await deps.room() : undefined;
|
|
142
|
+
const allowance = room === undefined || room === null ? room : Math.floor(room * 1e6 + 1e-6) / 1e6;
|
|
143
|
+
if (allowance === null || (allowance !== undefined && allowance < RUN_CAP_MIN_USD)) {
|
|
144
|
+
const skipped = { run: runId, shadow_run: null, workflow: serve.name, digest: serve.digest, promoted_at: promoted?.at ?? null, source: "shadow", agreed: null, served_cost: null, shadow_cost: null, ...turn, skipped: "no allowance", at: iso((deps.now ?? Date.now)()) };
|
|
145
|
+
await addLines(deps, [skipped]);
|
|
146
|
+
log(`workflow-first: ${serve.name} at ${serve.digest} served this run, drawn for its audit (1 in ${k}); no shadow: ${allowance === null ? "what it spent under its cap is not known" : `its cap leaves $${allowance}, under a run's smallest cap`} (no allowance)`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const shadow = {
|
|
150
|
+
input: launch.input,
|
|
151
|
+
title: `Audit of ${launch.title}`.slice(0, 200),
|
|
152
|
+
place: launch.place,
|
|
153
|
+
...(launch.repo !== undefined ? { repo: launch.repo } : {}),
|
|
154
|
+
...(launch.harness !== undefined ? { harness: launch.harness } : {}),
|
|
155
|
+
...(launch.model ? { model: launch.model } : {}),
|
|
156
|
+
...(launch.effort !== undefined ? { effort: launch.effort } : {}),
|
|
157
|
+
...(allowance !== undefined ? { maxCostUsd: allowance } : {}),
|
|
158
|
+
...(launch.plane ? { plane: launch.plane } : {}),
|
|
159
|
+
...(launch.approvers !== undefined ? { approvers: launch.approvers } : {}),
|
|
160
|
+
...(launch.documents !== undefined ? { documents: launch.documents } : {}),
|
|
161
|
+
...(launch.boxAllow !== undefined ? { boxAllow: launch.boxAllow } : {}),
|
|
162
|
+
...(launch.boxAllowSet ? { boxAllowSet: true } : {}),
|
|
163
|
+
...(launch.archilDisk ? { archilDisk: launch.archilDisk } : {}),
|
|
164
|
+
audit: { of: runId, workflow: serve.name, digest: serve.digest },
|
|
165
|
+
};
|
|
166
|
+
const started = { source: "started", run: runId, shadow_run: id, workflow: serve.name, digest: serve.digest, promoted_at: promoted?.at ?? null, ...turn, at: iso((deps.now ?? Date.now)()) };
|
|
167
|
+
await addLines(deps, [started]);
|
|
168
|
+
const sealed = await handedTo(deps, runId, id);
|
|
169
|
+
try {
|
|
170
|
+
await store.runs.create({ id, agentId, revisionId: deps.revisionId }, { body: launchBody(shadow), ...(sealed ? { sealed } : {}) });
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof StoreConstraint && (await store.runs.get(id)))
|
|
174
|
+
return;
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
log(`workflow-first: ${serve.name} at ${serve.digest} serves this run; drawn for its audit (1 in ${k}): its shadow run ${id} runs the agent on the same input`);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
log(`workflow-first: the audit of this run did not start (${error?.message ?? error})`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** The per_run MCP credentials run `from` was handed, sealed for shadow run `id` alone (as a replay run's are). */
|
|
184
|
+
async function handedTo(deps, from, id) {
|
|
185
|
+
if (!deps.sealKey)
|
|
186
|
+
return undefined;
|
|
187
|
+
const sealed = await deps.store.runs.launch(from).then((one) => one.sealed ?? null, () => null);
|
|
188
|
+
const handed = sealed === null ? undefined : openRunMcpAuth(deps.sealKey, from, sealed);
|
|
189
|
+
return handed && Object.keys(handed).length ? sealRunMcpAuth(deps.sealKey, id, handed) : undefined;
|
|
190
|
+
}
|
|
191
|
+
/** Writes the row of each open audit (a started line with no row yet) whose two runs, read by id, ended, the batch
|
|
192
|
+
* oldest served run first (the ledger's tail is its newest); a run that is gone (its shadow never created, say) ends it
|
|
193
|
+
* with no verdict. Then applies the hold rule over the ledger as it is now, rows added or not: the hold is a function of
|
|
194
|
+
* the ledger, so one a crash or a failed write lost after the rows were committed is made at the next claim. */
|
|
195
|
+
export async function settleAudits(deps) {
|
|
196
|
+
const { store, log } = deps;
|
|
197
|
+
try {
|
|
198
|
+
// An agent with no promotion record never served a learned workflow: it has no ledger to read.
|
|
199
|
+
if (!(await promotionsOf(store.settings, deps.agentId)).length)
|
|
200
|
+
return;
|
|
201
|
+
const lines = await readLedger(deps);
|
|
202
|
+
const now = (deps.now ?? Date.now)();
|
|
203
|
+
const rows = [];
|
|
204
|
+
for (const open of openAudits(lines)) {
|
|
205
|
+
const [servedRow, shadow] = [await store.runs.get(open.run), await store.runs.get(open.shadow_run)];
|
|
206
|
+
// Its shadow is created after its line, at the served run's claim: one missing once the served run ended never ran.
|
|
207
|
+
if ((servedRow && !ended(servedRow)) || (shadow && !ended(shadow)))
|
|
208
|
+
continue;
|
|
209
|
+
// One that ended where it would wait on a person (AUDIT_PARKED: an approval, a raise of its cap, a question), or
|
|
210
|
+
// once its cost passed its cap (the kernel's overCapEnd: it would wait on a raise), has no answer: `parked`.
|
|
211
|
+
const parked = shadow?.state === "failed" && ((shadow.summary ?? "").startsWith(AUDIT_PARKED) || overCapMessage(shadow.summary) !== undefined);
|
|
212
|
+
rows.push({ at: servedRow?.startedAt ?? 0, row: { run: open.run, shadow_run: open.shadow_run, workflow: open.workflow, digest: open.digest, promoted_at: open.promoted_at, source: "shadow", agreed: null, served_cost: servedRow?.costUsd ?? null, shadow_cost: shadow?.costUsd ?? null, ...turnOf(open.turn), ...(parked ? { parked: true } : {}), at: iso(now) } });
|
|
213
|
+
}
|
|
214
|
+
rows.sort((a, b) => a.at - b.at || (a.row.run < b.row.run ? -1 : a.row.run > b.row.run ? 1 : 0));
|
|
215
|
+
const { all, added } = rows.length ? await addLines(deps, rows.map(({ row }) => row), async (row) => {
|
|
216
|
+
const shadow = await store.runs.get(row.shadow_run);
|
|
217
|
+
if (shadow?.state !== "ended" || !(await store.runs.get(row.run)))
|
|
218
|
+
return null;
|
|
219
|
+
// The audited answer (the row's turn), never the run's newest: a follow-up since may have answered again.
|
|
220
|
+
const [a, b] = [await auditedAnswer(deps, row), await answerOf(store, row.shadow_run, deps.context)];
|
|
221
|
+
return a === null || b === null ? null : sameAnswer(a, b);
|
|
222
|
+
}) : { all: lines, added: [] };
|
|
223
|
+
const written = rowsOf(added);
|
|
224
|
+
if (written.length)
|
|
225
|
+
log(`workflow-first: ${written.length} audit row${written.length === 1 ? "" : "s"} written (${written.filter((row) => row.agreed === false).length} disagreeing)`);
|
|
226
|
+
await holdByLedger(deps, rowsOf(all));
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
log(`workflow-first: the audits were not settled (${error?.message ?? error}); a later claim settles them`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** The row an owner's grade of served run `run` writes (source grade, agreed = the grade, counted for the digest's
|
|
233
|
+
* promotion now), then the hold rule: only for a run the workflow answered alone (its answer is the workflow's).
|
|
234
|
+
* Nothing else: no round, no compile by itself. */
|
|
235
|
+
export async function gradeRow(deps, run, correct) {
|
|
236
|
+
const m = metricsOf(run);
|
|
237
|
+
if (m.path !== "workflow" || typeof m.workflow !== "string" || typeof m.workflow_digest !== "string")
|
|
238
|
+
return;
|
|
239
|
+
const promoted = promotionStartOf(await promotionsOf(deps.store.settings, deps.agentId), m.workflow, m.workflow_digest);
|
|
240
|
+
// The answer graded: the run's newest now, kept by its row's id (as a shadow's audit keeps its turn).
|
|
241
|
+
const turn = turnOf((await answerRowOf(deps.store, run.id, deps.context))?.id);
|
|
242
|
+
const row = { run: run.id, shadow_run: null, workflow: m.workflow, digest: m.workflow_digest, promoted_at: promoted?.at ?? null, source: "grade", agreed: correct, served_cost: run.costUsd, shadow_cost: null, ...turn, at: iso((deps.now ?? Date.now)()) };
|
|
243
|
+
const { all } = await addLines(deps, [row], async () => correct, true);
|
|
244
|
+
await holdByLedger(deps, rowsOf(all));
|
|
245
|
+
}
|
|
246
|
+
/** The ledger's lines on the agent's learning folder's main. */
|
|
247
|
+
async function readLedger(deps) {
|
|
248
|
+
const folder = deps.folder();
|
|
249
|
+
try {
|
|
250
|
+
return await readLearning(folder.workspace, ledgerOf);
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
await folder.end().catch(() => undefined);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** Appends `lines` (each not in the ledger yet, lineKey; a row's verdict read by `agreed` once it is known to be new) in
|
|
257
|
+
* their order, and answers the ledger after (`all`) with the lines it appended. A grade's row (`again`) replaces an
|
|
258
|
+
* earlier grade of the same run. */
|
|
259
|
+
async function addLines(deps, lines, agreed, again = false) {
|
|
260
|
+
const folder = deps.folder();
|
|
261
|
+
try {
|
|
262
|
+
const verdicts = new Map();
|
|
263
|
+
const done = await writeLearning(folder.workspace, async (read) => {
|
|
264
|
+
const before = (await ledgerOf(read)).filter((one) => !again || !lines.some((line) => lineKey(line) === lineKey(one)));
|
|
265
|
+
const known = new Set(before.map(lineKey));
|
|
266
|
+
const fresh = [];
|
|
267
|
+
for (const line of lines) {
|
|
268
|
+
const key = lineKey(line);
|
|
269
|
+
if (known.has(key))
|
|
270
|
+
continue;
|
|
271
|
+
if (line.source === "started" || !agreed) {
|
|
272
|
+
fresh.push(line);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (!verdicts.has(key))
|
|
276
|
+
verdicts.set(key, await agreed(line));
|
|
277
|
+
fresh.push({ ...line, agreed: verdicts.get(key) });
|
|
278
|
+
}
|
|
279
|
+
const change = auditChange(before, fresh);
|
|
280
|
+
return { result: { all: [...before, ...change.added], added: change.added }, ...(change.change ? { change: change.change } : {}) };
|
|
281
|
+
});
|
|
282
|
+
return done.result;
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
await folder.end().catch(() => undefined);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** The hold rule over the ledger's rows `all` for each workflow that serves now (its champion's digest), whether or not
|
|
289
|
+
* a row was just added: idempotent (applyHold holds only a digest whose newest record still promotes it). */
|
|
290
|
+
async function holdByLedger(deps, all) {
|
|
291
|
+
if (!all.length)
|
|
292
|
+
return;
|
|
293
|
+
const loop = await auditLoopOfRevision(deps.store, deps.revisionId);
|
|
294
|
+
for (const { workflow, digest } of servingOf(await promotionsOf(deps.store.settings, deps.agentId))) {
|
|
295
|
+
if (digest !== null)
|
|
296
|
+
await applyHold(deps, all, loop, workflow, digest);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** The hold rule on `workflow` at `digest` over the ledger `rows`, when it serves now (its newest record promotes it),
|
|
300
|
+
* on the rows of its current promotion alone (promotionStartOf: a digest its owner's replay promoted again after a hold
|
|
301
|
+
* starts on none): a hold carrying `audit` with the disagreeing rows, or a stop when an earlier audit hold of the
|
|
302
|
+
* workflow is within stop_window served runs. Kept only while the record it read is still the digest's (of two claims,
|
|
303
|
+
* one holds). */
|
|
304
|
+
async function applyHold(deps, rows, loop, workflow, digest) {
|
|
305
|
+
const { store, agentId, log } = deps;
|
|
306
|
+
const records = await promotionsOf(store.settings, agentId);
|
|
307
|
+
const current = promotionOf(records, workflow, digest);
|
|
308
|
+
if (current?.decided !== "promote")
|
|
309
|
+
return;
|
|
310
|
+
const hold = holdOf(rows, workflow, digest, promotionStartOf(records, workflow, digest)?.at ?? null, loop);
|
|
311
|
+
if (!hold)
|
|
312
|
+
return;
|
|
313
|
+
const first = records.findLast((one) => one.workflow === workflow && one.decided === "hold" && one.audit !== undefined);
|
|
314
|
+
const since = first ? Date.parse(first.at) : undefined;
|
|
315
|
+
const servedSince = since === undefined ? 0 : (await servedRuns(store, agentId, loop.stop_window, workflow, undefined, (row) => row.startedAt >= since)).length;
|
|
316
|
+
const stopped = first !== undefined && servedSince < loop.stop_window;
|
|
317
|
+
// Each text cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown), as a check's are.
|
|
318
|
+
const shown = await deps.shown();
|
|
319
|
+
const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
|
|
320
|
+
const disagreements = [];
|
|
321
|
+
for (const row of hold.disagreed) {
|
|
322
|
+
const input = await store.runs.launch(row.run).then((one) => inputText(readLaunchBody(one.body)?.input ?? null), () => "");
|
|
323
|
+
// The answer the row compared (its turn's), as the verdict read it: never a follow-up's since.
|
|
324
|
+
const draft = await auditedAnswer(deps, row);
|
|
325
|
+
const agent = row.shadow_run ? await answerOf(store, row.shadow_run, deps.context) : null;
|
|
326
|
+
disagreements.push({ run: row.shadow_run ?? row.run, served: row.run, input: cut(input), agent: agent === null ? null : cut(agent), draft: draft === null ? null : cut(draft), ...(row.source === "grade" ? { graded: true } : {}) });
|
|
327
|
+
}
|
|
328
|
+
const said = `it disagreed with the agent's own answer on ${hold.disagreed.length} of its last ${hold.rows.length} audited runs (the bar: ${loop.hold_disagree} of ${loop.hold_window})`;
|
|
329
|
+
const reason = stopped ? STOPPED_TWICE : `held: ${said}; the agent's next run recompiles it once with them`;
|
|
330
|
+
const record = {
|
|
331
|
+
workflow, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason,
|
|
332
|
+
audit: { window: loop.hold_window, disagree: loop.hold_disagree, rows: hold.rows.length, disagreements, ...(stopped ? { stopped: true } : {}) },
|
|
333
|
+
...(current.commit ? { commit: current.commit } : {}),
|
|
334
|
+
};
|
|
335
|
+
const kept = await recordPromotion(store.settings, agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
|
|
336
|
+
if (kept.won)
|
|
337
|
+
log(`workflow-first: ${workflow} at ${digest} ${stopped ? `stopped (${said}, a second hold within ${loop.stop_window} served runs)` : reason}`);
|
|
338
|
+
}
|
package/dist/runner/beside.js
CHANGED
|
@@ -64,7 +64,7 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub,
|
|
|
64
64
|
const computers = runnerComputers(store, runs, seal.key, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(hub ? { hub } : {}), ...(dial ? { dial } : {}) });
|
|
65
65
|
// `mcpLoopback`: the server beside it is a local install (Serve.localInstall), so its runs may reach an MCP server on
|
|
66
66
|
// loopback; a runner in its own process does only as its own environment says (main.ts runnerLoopback). `mcpOwn`: that server's own addresses (Serve.own), whose ports a run's
|
|
67
|
-
// loopback read never goes to. A run's log lines (a
|
|
67
|
+
// loopback read never goes to. A run's log lines (a sweep that failed) go to
|
|
68
68
|
// stderr with the runner's other lines. `evalFakes`: the template eval's fakes (EvalFakes: a case's web, now, monid and
|
|
69
69
|
// email), by the agent each of its runs is of; only the eval, in its own process, hands them. `harnessInstall`: what a
|
|
70
70
|
// claim's first-use install installs with (the eval's sharedInstaller, which the server beside it takes too).
|
|
@@ -65,6 +65,7 @@ import { journalEntries } from "./journal-reader.js";
|
|
|
65
65
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
66
66
|
import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
|
|
67
67
|
import { pathMetrics, workflowFirstOf } from "./workflow-first.js";
|
|
68
|
+
import { AUDIT_PARKED, settleAudits, withAudit } from "./audit.js";
|
|
68
69
|
import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
|
|
69
70
|
import { specBuilt } from "./spec-holds.js";
|
|
70
71
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
@@ -503,7 +504,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
503
504
|
const tierRoute = tierRoutes.get(by);
|
|
504
505
|
return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
|
|
505
506
|
},
|
|
506
|
-
// What its learning runs' grades took beside it, read by every gate with its own sessions
|
|
507
|
+
// What its learning runs' grades and its audit's shadow took beside it, read by every gate with its own sessions
|
|
508
|
+
// (none: it queues none).
|
|
507
509
|
...(besideOf ? { beside: besideOf } : {}),
|
|
508
510
|
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
|
|
509
511
|
freeRequests: freeModelRequestsOf(deps.env),
|
|
@@ -547,13 +549,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
547
549
|
// The keys the claim hands the run (its web tools and its learned workflow's call nodes run on them): never learned
|
|
548
550
|
// (learningEndOfRun).
|
|
549
551
|
let handedKeys = [];
|
|
550
|
-
// A replay run lays the workflow it replays
|
|
552
|
+
// A replay run lays only the workflow it replays (runner/promotion.ts replayLaid).
|
|
551
553
|
const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
|
|
552
554
|
// The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
|
|
553
555
|
// chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
|
|
554
556
|
// serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
|
|
555
557
|
// five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
|
|
556
558
|
// (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
|
|
559
|
+
// The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
|
|
560
|
+
const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey };
|
|
561
|
+
if (launch.learning && !launch.replay && !launch.audit)
|
|
562
|
+
await settleAudits(audits);
|
|
557
563
|
const promotion = claimPromotion({
|
|
558
564
|
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
|
|
559
565
|
});
|
|
@@ -633,8 +639,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
633
639
|
// 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
640
|
// store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this claim's
|
|
635
641
|
// 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
|
-
|
|
642
|
+
// 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.
|
|
643
|
+
// A run the promoted workflow served first starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
644
|
+
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
645
|
+
const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
|
|
638
646
|
store: deps.store,
|
|
639
647
|
data: deps.data,
|
|
640
648
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -650,7 +658,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
650
658
|
learningFolder: archil === undefined
|
|
651
659
|
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
652
660
|
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
653
|
-
});
|
|
661
|
+
}), { ...audits, launch });
|
|
654
662
|
return {
|
|
655
663
|
adapter,
|
|
656
664
|
session,
|
|
@@ -674,6 +682,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
674
682
|
// The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
|
|
675
683
|
...(life ? { lifecycle: life } : {}),
|
|
676
684
|
agentId: runRow.agentId,
|
|
685
|
+
// An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
|
|
686
|
+
...(launch.audit ? { neverWaits: AUDIT_PARKED } : {}),
|
|
677
687
|
// 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
688
|
...(loopComputer ? { computer: loopComputer } : {}),
|
|
679
689
|
// A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
|
|
@@ -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
|
|
@@ -15,10 +15,7 @@ import { hostMemory, neverFits } from "../host.js";
|
|
|
15
15
|
import { resolveHarness } from "./adapters/index.js";
|
|
16
16
|
import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
|
|
17
17
|
import { createAdapterLoop } from "./adapter-loop.js";
|
|
18
|
-
import {
|
|
19
|
-
import { decisionProvidersIn, DEFAULT_DECISION_PROVIDER, FAUX_JEV_ENV } from "../decisions.js";
|
|
20
|
-
import { FAUX_ENV } from "../model.js";
|
|
21
|
-
import { generalThresholdOf } from "../learn/general.js";
|
|
18
|
+
import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
22
19
|
import { createDispatchLoop } from "./dispatch.js";
|
|
23
20
|
import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
|
|
24
21
|
import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
|
|
@@ -78,17 +75,6 @@ export function resolveRunnerLoop(deps) {
|
|
|
78
75
|
},
|
|
79
76
|
...(deps.log ? { log: deps.log } : {}),
|
|
80
77
|
...(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
78
|
});
|
|
93
79
|
}
|
|
94
80
|
// The harness's own entry decides which spec builds the run, by the entry's facts and never the harness's name: an entry
|
|
@@ -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. */
|
|
@@ -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;
|