@parcha/agentrun-serve 0.1.0-beta.41 → 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 +74 -0
- package/NOTICE +2 -0
- package/README.md +85 -19
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +3 -1
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.js +2 -14
- package/dist/console/assets/index-BrcDSBD8.css +1 -0
- package/dist/console/assets/index-Bz6IWncl.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/eval-feed.d.ts +2 -2
- package/dist/eval-feed.js +9 -5
- package/dist/feed/parse.d.ts +3 -2
- package/dist/feed/parse.js +9 -18
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- 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/check.d.ts +14 -0
- package/dist/learn/check.js +194 -14
- package/dist/learn/compile.d.ts +75 -78
- package/dist/learn/compile.js +175 -176
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +138 -196
- package/dist/learn/promote.js +68 -184
- 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 +38 -0
- package/dist/learning-setting.js +83 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +8 -0
- package/dist/mcp-oauth.js +7 -0
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +195 -59
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/runner/adapter-loop.d.ts +5 -1
- package/dist/runner/adapter-loop.js +20 -8
- package/dist/runner/adapter-run-spec.d.ts +16 -1
- package/dist/runner/adapter-run-spec.js +36 -11
- package/dist/runner/audit.d.ts +64 -0
- package/dist/runner/audit.js +338 -0
- package/dist/runner/beside.js +2 -2
- package/dist/runner/cli-run-spec.js +25 -12
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +19 -40
- 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 +62 -13
- package/dist/runner/learning-end.js +180 -74
- 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.d.ts +11 -0
- package/dist/runner/main.js +30 -3
- package/dist/runner/mcp-run.d.ts +2 -2
- package/dist/runner/promotion.d.ts +78 -50
- package/dist/runner/promotion.js +371 -503
- package/dist/runner/reflect-hook.d.ts +15 -0
- package/dist/runner/reflect-hook.js +28 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +24 -25
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/sdk/runs.js +2 -1
- package/dist/secrets.js +2 -2
- package/dist/server.d.ts +4 -3
- package/dist/server.js +132 -26
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/sqlite/store.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/learning.d.ts +18 -7
- package/dist/store-reads/learning.js +36 -23
- package/dist/store-reads/loop.d.ts +5 -39
- package/dist/store-reads/loop.js +21 -80
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +16 -2
- package/dist/template-eval.d.ts +7 -0
- package/dist/template-eval.js +54 -6
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +14 -1
- package/dist/timeline/computer.js +2 -1
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-feed.js +67 -18
- package/dist/validate.js +7 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +3 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/launcher/agentrun-serve +31 -24
- package/package.json +10 -9
- package/templates/README.md +11 -2
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-COGhx_2Z.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
|
@@ -43,6 +43,11 @@ export interface ReflectDeps {
|
|
|
43
43
|
* asked its end-of-run turn (no model request, nothing spent looking back), and its learning is dropped `empty` in
|
|
44
44
|
* said.onlyWorkflow's words. Absent, or a read that throws: every run is asked. */
|
|
45
45
|
readonly nothingNew?: (runId: string) => Promise<boolean>;
|
|
46
|
+
/** For a job that compiles workflows: whether the run carries its owner's feedback (learning-end.ts ownerSaid: a grade's
|
|
47
|
+
* words, or a message after its first). A run without it is not asked its look-back (no model request, $0 looking
|
|
48
|
+
* back), and its compile turn, when one is due, is asked alone; with nothing due its learning is dropped `empty` in
|
|
49
|
+
* said.noFeedback's words. Absent (a notes job), or a read that throws: the run is asked its look-back. */
|
|
50
|
+
readonly ownerSaid?: (runId: string) => Promise<boolean>;
|
|
46
51
|
/** The run's facts for reflectSkip: whether it learns, a person's cancel, its cap reached, its cap, its cost so far as a
|
|
47
52
|
* person is shown it (`costUsd`, kept as the job's), and under a cap its spend as the cap's gates read it (`spentUsd`,
|
|
48
53
|
* learning-end.ts capSpendOf: a request with no price of its own at its held figure; null: unknown). */
|
|
@@ -70,6 +75,16 @@ export interface ReflectDeps {
|
|
|
70
75
|
outcome: "completed" | "failed";
|
|
71
76
|
refuse: readonly string[];
|
|
72
77
|
}) => Promise<CompileAsk | undefined>;
|
|
78
|
+
/** Compile once: a compile turn whose drafts all failed their checks (one answered, none passed) is the compile's
|
|
79
|
+
* attempt, kept on a promotion record (learning-end.ts recordDraftFailed) that compileFacts reads. Its `workflow` and
|
|
80
|
+
* `errors` come cut of `refuse`. Absent: none kept. */
|
|
81
|
+
readonly compileFailed?: (input: {
|
|
82
|
+
runId: string;
|
|
83
|
+
agentId: string;
|
|
84
|
+
compile: CompileAsk;
|
|
85
|
+
workflow: string;
|
|
86
|
+
errors: readonly string[];
|
|
87
|
+
}) => Promise<void>;
|
|
73
88
|
/** The compile turn's deadline, every attempt in it. Default learn/compile.ts COMPILE_TIMEOUT_MS. */
|
|
74
89
|
readonly compileDeadlineMs?: number;
|
|
75
90
|
/** What the person said in the run, and a trigger's input, as the checks and the grader read them. */
|
|
@@ -86,18 +86,26 @@ export function createReflectHook(deps) {
|
|
|
86
86
|
// its workflow, asked while its champion serves) looking back cost nothing, $0 whether or not the job's own cost is
|
|
87
87
|
// known. Its words are the server's own.
|
|
88
88
|
const workflowOnly = input.outcome === "completed" && deps.nothingNew !== undefined && (await deps.nothingNew(input.runId).catch(() => false));
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// A run of a job that compiles workflows with no word from its owner is not asked its look-back either (ownerSaid):
|
|
90
|
+
// its job's trace is what a compile reads, and a look-back on every agent run cost more than the run. The same way:
|
|
91
|
+
// its compile turn, when due, asked alone, else $0 looking back.
|
|
92
|
+
const unheard = !workflowOnly && deps.ownerSaid !== undefined && !(await deps.ownerSaid(input.runId).catch(() => true));
|
|
93
|
+
const alone = workflowOnly || unheard;
|
|
94
|
+
const notAsked = workflowOnly ? said.onlyWorkflow : said.noFeedback;
|
|
95
|
+
const onlyWorkflow = () => ({ also: [droppedRow(null, "empty", notAsked, { answered_at: answeredAt, job_cost_usd: job, look_back_usd: 0, ...followUp() })] });
|
|
96
|
+
if (alone && !deps.compileFacts)
|
|
91
97
|
return onlyWorkflow();
|
|
92
98
|
// What the run must never learn, read once, before it is asked anything: a run whose list can't be read learns
|
|
93
99
|
// nothing, never over a shorter one.
|
|
94
100
|
const read = deps.refuse ? await deps.refuse(input.runId).catch(() => "unreadable") : [];
|
|
95
101
|
const refuse = read === "unreadable" ? [] : read;
|
|
96
|
-
// The compile turn's facts (learn/compile.ts), read once: a
|
|
102
|
+
// The compile turn's facts (learn/compile.ts), read once: a run not looked back on with none due ends here, as above.
|
|
97
103
|
const compileOf = async () => (deps.compileFacts && read !== "unreadable" ? await deps.compileFacts({ runId: input.runId, agentId: input.agentId, outcome: input.outcome, refuse }).catch(() => undefined) : undefined);
|
|
98
|
-
const early =
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
const early = alone ? await compileOf() : undefined;
|
|
105
|
+
// None due now, but a compile request this run already asked and kept (a crash cut it, another run merged a workflow
|
|
106
|
+
// since) was paid: its cost stays the look-back's, as every other cut's does (`begun`), never the task's.
|
|
107
|
+
if (alone && !early)
|
|
108
|
+
return begun ? unasked(droppedRow(null, "empty", notAsked)) : onlyWorkflow();
|
|
101
109
|
// Every end from here closes through this one function: looked's timings first, then the cut LAST, over every
|
|
102
110
|
// string the kept rows hold, whatever looked adds now or later.
|
|
103
111
|
const close = async (rows) => ({ also: (await looked({ also: rows })).also.map((row) => cutRow(row, refuse)) });
|
|
@@ -116,11 +124,11 @@ export function createReflectHook(deps) {
|
|
|
116
124
|
return undefined;
|
|
117
125
|
}
|
|
118
126
|
};
|
|
119
|
-
// The look-back: asked of every run but a workflow-only one
|
|
120
|
-
//
|
|
127
|
+
// The look-back: asked of every run but a workflow-only one or one its owner said nothing on, whose compile turn is
|
|
128
|
+
// asked alone, from no answer of its own: nothing the look-back kept goes with its draft.
|
|
121
129
|
let turn = null;
|
|
122
130
|
let checked = { state: "dropped", reason: "empty" };
|
|
123
|
-
if (
|
|
131
|
+
if (alone)
|
|
124
132
|
heard = await deps.asked(input.runId);
|
|
125
133
|
else {
|
|
126
134
|
const { active } = await deps.promptFacts(input.runId, input.agentId);
|
|
@@ -172,10 +180,10 @@ export function createReflectHook(deps) {
|
|
|
172
180
|
// The compile turn (learn/compile.ts): the job as a learned workflow, or a revision of one, checked as a draft is,
|
|
173
181
|
// its refusals sent back up to COMPILE_RETRIES times. A draft that passed goes in the proposal beside the notes; one
|
|
174
182
|
// that never did is never silent: its errors go with the learning, and its problems to its end.
|
|
175
|
-
const compile =
|
|
183
|
+
const compile = alone ? early : await compileOf();
|
|
176
184
|
let compiled;
|
|
177
185
|
if (compile) {
|
|
178
|
-
// A compile turn asked alone (
|
|
186
|
+
// A compile turn asked alone (no look-back) is the round's first ask: it keeps the job's figures
|
|
179
187
|
// with its prompt as the look-back's does, and a turn an earlier claim asked first answers with that ask's (`kept`),
|
|
180
188
|
// so a restart mid compile never moves what the earlier attempt spent compiling into the job's. Each attempt keeps
|
|
181
189
|
// the figures as they stand once the attempts before it answered (an earlier claim's, when it asked first).
|
|
@@ -189,11 +197,11 @@ export function createReflectHook(deps) {
|
|
|
189
197
|
let capped = false;
|
|
190
198
|
const result = await compileTurn({
|
|
191
199
|
ask: async (prompt, attempt, left) => {
|
|
192
|
-
const keep = { ...(
|
|
200
|
+
const keep = { ...(alone ? { answered_at: answeredAt, job_cost_usd: job } : {}), ...(revised ? { compile_base: revised.base } : {}) };
|
|
193
201
|
const said_ = await input.ask(prompt, { ...ask, deadlineMs: left, step: `compile-${attempt}`, ...(Object.keys(keep).length ? { keep } : {}) });
|
|
194
202
|
if ("failed" in said_ && CAP_REFUSAL.test(said_.failed.message))
|
|
195
203
|
capped = true;
|
|
196
|
-
if (
|
|
204
|
+
if (alone)
|
|
197
205
|
firstAsk(said_.kept);
|
|
198
206
|
const base = said_.kept?.compile_base;
|
|
199
207
|
if (revised && typeof base === "string")
|
|
@@ -229,11 +237,17 @@ export function createReflectHook(deps) {
|
|
|
229
237
|
: checked.reason === "checker" ? { ...checked, problems: [...checked.problems, ...problems] }
|
|
230
238
|
: checked;
|
|
231
239
|
compiled = { record: result.record, draft_errors: result.draftErrors };
|
|
240
|
+
// Compile once: its failed drafts are the compile's attempt, on record before the learning closes. The draft's
|
|
241
|
+
// name and errors are the model's words: cut of `refuse` as the proposal row is (cutRow) before they are saved
|
|
242
|
+
// on the promotion record or logged, whose reads cut only the server's secrets, never this run's.
|
|
243
|
+
const cut = (text) => redactSecrets(text, refuse, Number.POSITIVE_INFINITY);
|
|
244
|
+
if (result.drafted && deps.compileFailed)
|
|
245
|
+
await deps.compileFailed({ runId: input.runId, agentId: input.agentId, compile, workflow: cut(result.record.workflow), errors: result.draftErrors.map(cut) }).catch(() => undefined);
|
|
232
246
|
}
|
|
233
247
|
}
|
|
234
248
|
const compiledFields = compiled ? { compiled: compiled.record, ...(compiled.draft_errors?.length ? { draft_errors: compiled.draft_errors } : {}) } : {};
|
|
235
249
|
if (checked.state === "dropped") {
|
|
236
|
-
const detail = checked.reason === "empty" ? (
|
|
250
|
+
const detail = checked.reason === "empty" ? (alone ? notAsked : said.empty) : checked.reason === "unparsed" ? said.unparsed : said.checker(checked.problems);
|
|
237
251
|
return close([droppedRow(turn, checked.reason, detail, { ...checked, ...compiledFields })]);
|
|
238
252
|
}
|
|
239
253
|
// The learning run's cap: what the run's cap leaves now its look-back is spent, read after the checks. A spend under
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
// (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
|
|
13
13
|
// is left out: the store never holds one in the clear, and nothing of this runner can be handed it.
|
|
14
14
|
import { CHATGPT_PLAN_ROW } from "../chatgpt-plan.js";
|
|
15
|
+
import { calendarRowSecrets } from "../calendar/address.js";
|
|
16
|
+
import { CALENDAR_ROW } from "../calendar/names.js";
|
|
15
17
|
import { accountRowSecrets, EMAIL_ACCOUNT_ROW } from "../email/account.js";
|
|
16
18
|
import { unseal } from "../sealing.js";
|
|
17
19
|
import { besideTheStore, ServerSecrets } from "../server-secrets.js";
|
|
@@ -98,7 +100,7 @@ function secretsOf(row, plain, adapters) {
|
|
|
98
100
|
case "run_launch":
|
|
99
101
|
return { listed: plain.trimStart().startsWith("{") ? launchSecrets(plain) : [plain], whole: [] };
|
|
100
102
|
case "sealed_keys":
|
|
101
|
-
return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : [plain], whole: [] };
|
|
103
|
+
return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : row.where.name === CALENDAR_ROW ? calendarRowSecrets(plain) : [plain], whole: [] };
|
|
102
104
|
default:
|
|
103
105
|
return { listed: [plain], whole: [] };
|
|
104
106
|
}
|
|
@@ -2,7 +2,7 @@ import { type LearnedWorkflow } from "../learning.js";
|
|
|
2
2
|
import type { RunLaunch } from "../run-launch.js";
|
|
3
3
|
import { COST_WINDOW, type RunPath } from "../learning-cost.js";
|
|
4
4
|
export { COST_WINDOW };
|
|
5
|
-
import { type
|
|
5
|
+
import { type LoopRow } from "../learned-nodes.js";
|
|
6
6
|
import type { Skipped } from "../learn/replay-calls.js";
|
|
7
7
|
/** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
|
|
8
8
|
* revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
|
|
@@ -159,18 +159,12 @@ export declare function servedOf(entries: readonly {
|
|
|
159
159
|
digest?: string;
|
|
160
160
|
promotion?: number;
|
|
161
161
|
} | undefined;
|
|
162
|
-
/** Why a run's learned workflow did not run first, from its root entries: the money rule's WORKFLOW_FIRST entry
|
|
163
|
-
* (outcome needs_revision) with its two numbers; undefined when there is none. */
|
|
164
|
-
export declare function reviseOf(entries: readonly {
|
|
165
|
-
readonly kind: string;
|
|
166
|
-
readonly data?: unknown;
|
|
167
|
-
}[]): Revise | undefined;
|
|
168
162
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
169
163
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
170
164
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
171
|
-
* which its grade keeps)
|
|
172
|
-
*
|
|
173
|
-
*
|
|
165
|
+
* which its grade keeps), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
166
|
+
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
167
|
+
* and workflow from here. None for a run that does not learn. */
|
|
174
168
|
export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
175
169
|
path: RunPath;
|
|
176
170
|
workflow: string | null;
|
|
@@ -185,9 +179,10 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
|
185
179
|
workflow?: string;
|
|
186
180
|
workflow_digest?: string;
|
|
187
181
|
workflow_promotion?: number;
|
|
188
|
-
|
|
182
|
+
not_auditable?: true;
|
|
189
183
|
loops?: LoopRow[];
|
|
190
184
|
replay?: ReplayMetrics;
|
|
185
|
+
audit?: NonNullable<RunLaunch["audit"]>;
|
|
191
186
|
};
|
|
192
187
|
/** A replay run's record (metrics.replay): the graded run it replayed and how its workflow ended there. */
|
|
193
188
|
export type ReplayMetrics = {
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
// workflow-first: a run of an agent whose learned revision holds one active workflow fitting the run's input starts on
|
|
2
2
|
// that workflow, with no turn of the agent's model (a JIT's compiled path: the agent is the interpreter, the workflow is
|
|
3
|
-
// the code it compiled, its escalate nodes
|
|
3
|
+
// the code it compiled, its escalate nodes hand a case back). The workflow answering is the run's answer; the workflow handing
|
|
4
4
|
// the job back (it escalated, a node failed, its output failed its schema) is a deopt: the same run goes on as an
|
|
5
5
|
// agentic run, the agent handed the workflow's trace, and the handback feeds the agent's next revision.
|
|
6
6
|
//
|
|
7
7
|
// The choice here is structural, never semantic: a workflow fits when its input schema has at least one required field
|
|
8
8
|
// and the run's input passes it at the top level (validate.ts inputIssues, the check a run's input gets at start). Whether
|
|
9
|
-
// the workflow can do the job is its own
|
|
9
|
+
// the workflow can do the job is its own escalate nodes' call, never the engine's. Exactly one fitting active workflow serves;
|
|
10
10
|
// none, or more than one (said in one log line), leaves the run to the agent. A launch's `workflowFirst: false` (RunCreate
|
|
11
|
-
// `workflow_first`) forces the agent path. A handback is an escalation, never a failure: it asks
|
|
12
|
-
//
|
|
11
|
+
// `workflow_first`) forces the agent path. A handback is an escalation, never a failure: it asks for no revision (one run
|
|
12
|
+
// is one sample; a revision is asked only of a workflow its promotion holds), and never keeps the workflow from serving.
|
|
13
|
+
// One money rule does (costLineOf): a workflow
|
|
13
14
|
// serves while its all-in cost a run over its last COST_WINDOW served runs at its digest stays under the agent's by-hand
|
|
14
15
|
// cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first). Both sides read one all-in
|
|
15
16
|
// cost a run, the cost page's (store-reads/learning.ts allInOf): its booked cost (the workflow and any handback's agent
|
|
16
17
|
// work together) and every learning round booked for it (its look-backs, its grades, a follow-up's rounds). A run whose
|
|
17
18
|
// all-in is unknown anywhere is left out of its side's mean and counted, never read as 0. Over that line it stops running
|
|
18
|
-
// first: the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
|
|
19
|
-
// agent's cost per run shows it
|
|
19
|
+
// first: the agent takes the run, the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
|
|
20
|
+
// needs_revision), and the agent's cost per run shows it stopped. The stop asks for no compile. A new revision of it (a
|
|
21
|
+
// new digest: one its hold asked, or its owner's) serves again from zero. Fewer than
|
|
20
22
|
// COST_WINDOW served runs, or no by-hand cost at all (said in the log): it serves. Every input is the run record's path
|
|
21
23
|
// (metrics.path, one classifier: store-reads/learning.ts runPathOverStore). The rule catches a workflow that costs more
|
|
22
24
|
// than doing the job by hand; it does not catch one that answers wrong with confidence. The spec builders
|
|
@@ -24,11 +26,12 @@
|
|
|
24
26
|
// the first input), through the run's own learned_workflow tool, gate, record and ledger.
|
|
25
27
|
import { createHash } from "node:crypto";
|
|
26
28
|
import { LEARNING_LABEL } from "../learning.js";
|
|
27
|
-
import { COST_WINDOW } from "../learning-cost.js";
|
|
29
|
+
import { COST_WINDOW, SERVED_PATHS } from "../learning-cost.js";
|
|
30
|
+
import { auditableLaunch } from "../learn/audit.js";
|
|
28
31
|
export { COST_WINDOW };
|
|
29
32
|
import { KINDS } from "./journal-kinds.js";
|
|
30
33
|
import { inputIssues, isObject } from "../validate.js";
|
|
31
|
-
import { endedIn,
|
|
34
|
+
import { endedIn, loopsOf, replaySkippedIn } from "../learned-nodes.js";
|
|
32
35
|
import { sameAnswer } from "../learn/promote.js";
|
|
33
36
|
/** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
|
|
34
37
|
* revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
|
|
@@ -63,7 +66,7 @@ export function costLineOf(past, name, digest) {
|
|
|
63
66
|
}
|
|
64
67
|
const agent = newest.filter((run) => pathFields(run.metrics).path === "agent");
|
|
65
68
|
const first = Math.min(...newest.filter(ran).map((run) => run.startedAt));
|
|
66
|
-
const hand = agent.some(known) ? agent : newest.filter((run) => run.startedAt < first && !SERVED.includes(pathFields(run.metrics).path) && pathFields(run.metrics).path !== "replay");
|
|
69
|
+
const hand = agent.some(known) ? agent : newest.filter((run) => run.startedAt < first && !SERVED.includes(pathFields(run.metrics).path) && pathFields(run.metrics).path !== "replay" && pathFields(run.metrics).path !== "audit");
|
|
67
70
|
const byHand = hand.filter(known).map((run) => run.allInUsd);
|
|
68
71
|
return { served: meanOf(served) ?? { runs: 0, mean_usd: null }, by_hand: meanOf(byHand), unknown_runs: servedUnknown + hand.length - byHand.length };
|
|
69
72
|
}
|
|
@@ -205,7 +208,7 @@ export async function workflowFirstOf(kind, workflows, launch, log, past, promot
|
|
|
205
208
|
return serve;
|
|
206
209
|
const revise = { workflow: chosen.name, digest, served_usd: line.served.mean_usd, by_hand_usd: line.by_hand.mean_usd, runs: line.served.runs, revision: launch.learning.seed, ...(outputSchema !== undefined ? { outputSchema } : {}) };
|
|
207
210
|
const unknown = line.unknown_runs ? ` (${line.unknown_runs} run${line.unknown_runs === 1 ? "" : "s"} of unknown cost left out)` : "";
|
|
208
|
-
log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand, both all-in${unknown}; it does not run first until a new revision of it
|
|
211
|
+
log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand, both all-in${unknown}; it does not run first until a new revision of it; the agent takes this run`);
|
|
209
212
|
return { ...champion, revise };
|
|
210
213
|
}
|
|
211
214
|
/** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
|
|
@@ -217,32 +220,26 @@ export function servedOf(entries) {
|
|
|
217
220
|
return undefined;
|
|
218
221
|
return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}) };
|
|
219
222
|
}
|
|
220
|
-
/** Why a run's learned workflow did not run first, from its root entries: the money rule's WORKFLOW_FIRST entry
|
|
221
|
-
* (outcome needs_revision) with its two numbers; undefined when there is none. */
|
|
222
|
-
export function reviseOf(entries) {
|
|
223
|
-
const kept = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && entry.data?.outcome === "needs_revision")?.data;
|
|
224
|
-
if (!kept || typeof kept.workflow !== "string" || typeof kept.digest !== "string" || typeof kept.served_usd !== "number" || typeof kept.by_hand_usd !== "number" || typeof kept.runs !== "number")
|
|
225
|
-
return undefined;
|
|
226
|
-
return { workflow: kept.workflow, digest: kept.digest, served_usd: kept.served_usd, by_hand_usd: kept.by_hand_usd, runs: kept.runs };
|
|
227
|
-
}
|
|
228
223
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
229
224
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
230
225
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
231
|
-
* which its grade keeps)
|
|
232
|
-
*
|
|
233
|
-
*
|
|
226
|
+
* which its grade keeps), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
227
|
+
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
228
|
+
* and workflow from here. None for a run that does not learn. */
|
|
234
229
|
export function pathMetrics(launch, classified, entries = []) {
|
|
230
|
+
// A shadow run (runner/audit.ts): path `audit` and the run it audits, whatever it did: no learning, no money rule.
|
|
231
|
+
if (launch.audit)
|
|
232
|
+
return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } };
|
|
235
233
|
if (!launch.learning)
|
|
236
234
|
return {};
|
|
237
235
|
const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
|
|
238
|
-
const guards = guardsOf(entries);
|
|
239
236
|
const loops = loopsOf(entries);
|
|
240
|
-
const rows =
|
|
237
|
+
const rows = loops.length ? { loops } : {};
|
|
241
238
|
if (launch.replay) {
|
|
242
239
|
// A replay run (runner/promotion.ts): path `replay`, whatever its workflow did, so the money rule and the agent's
|
|
243
240
|
// by-hand cost never read it; how its workflow ended, for the replay's score (learn/promote.ts ReplayRow).
|
|
244
241
|
const { of, workflow: name, digest: at } = launch.replay;
|
|
245
|
-
// Handed back when the workflow ended escalated (an escalate node
|
|
242
|
+
// Handed back when the workflow ended escalated (an escalate node: the workflow knowing its limits), however
|
|
246
243
|
// many of its nodes failed on the way and were recovered (a map's collected item); a workflow that itself ended failed
|
|
247
244
|
// (a credential or tool the replay ran without, a step's output off its schema), or was refused, is failed: no
|
|
248
245
|
// evidence. Skipped when a write it needed is not in the graded run's recording (learn/replay-calls.ts): never run.
|
|
@@ -250,7 +247,9 @@ export function pathMetrics(launch, classified, entries = []) {
|
|
|
250
247
|
const outcome = skipped ? "skipped_write" : path === "workflow" && workflow === name ? "answered" : path === "handed_back" && workflow === name && endedIn(entries, name) === "escalated" ? "handed_back" : "failed";
|
|
251
248
|
return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, replay: { of, outcome, ...(skipped ? { skipped } : {}) } };
|
|
252
249
|
}
|
|
253
|
-
|
|
250
|
+
// A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
|
|
251
|
+
const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
|
|
252
|
+
return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...rows };
|
|
254
253
|
}
|
|
255
254
|
/** What run `entries` (its root's) say its learned workflow answered alone: the workflow and its answer (the model's
|
|
256
255
|
* message written just before the WORKFLOW_FIRST entry, in its commit); undefined for a run it did not answer. A follow-up that opens such a
|
|
@@ -94,7 +94,7 @@ type StartBody = {
|
|
|
94
94
|
readonly maxCostUsd?: number;
|
|
95
95
|
readonly place?: unknown;
|
|
96
96
|
readonly tools?: readonly unknown[];
|
|
97
|
-
readonly learning?:
|
|
97
|
+
readonly learning?: import("./learning-setting.js").LearningSetting;
|
|
98
98
|
readonly thinking?: unknown;
|
|
99
99
|
};
|
|
100
100
|
/** The pieces a start needs that live in the server's request layer, not here: the leaf validators (the create body's field
|
package/dist/sdk/runs.js
CHANGED
|
@@ -7,6 +7,7 @@ import { canonical, isObject } from "../store/agent-body.js";
|
|
|
7
7
|
import { uuidv7 } from "../agents-store.js";
|
|
8
8
|
import { launchBody } from "../run-launch.js";
|
|
9
9
|
import { learningStartFor } from "../runs-over-store.js";
|
|
10
|
+
import { learnsWorkflowsOf } from "../learning-setting.js";
|
|
10
11
|
import { chooseWorkflows, chooseSkills, learningFolderOf, readerOf, seedFrom, secretsShown } from "../learning.js";
|
|
11
12
|
import { NATIVE_GRADE_INSTRUCTION_BYTES } from "../learn/grade.js";
|
|
12
13
|
import { secretRedactor } from "../runner/redact.js";
|
|
@@ -185,7 +186,7 @@ export class SdkRuns {
|
|
|
185
186
|
const revisionBody = entry.revision.body;
|
|
186
187
|
if (revisionBody.maxCostUsd !== undefined)
|
|
187
188
|
throw new ApiError("agent_not_runnable", "AgentRun cannot enforce a spend cap on an external SDK. Configure the budget in the backend SDK and remove this managed run cap.");
|
|
188
|
-
const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && revisionBody.learning
|
|
189
|
+
const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && learnsWorkflowsOf(revisionBody.learning) ? { learning: "notes" } : {}) }, { content: cleanedInput });
|
|
189
190
|
if (learning) {
|
|
190
191
|
if (Buffer.byteLength(instructions) > NATIVE_GRADE_INSTRUCTION_BYTES)
|
|
191
192
|
refuse("Original SDK instructions exceed the 64 KiB grading evidence limit. Keep learning off or provide a complete policy within that limit.");
|
package/dist/secrets.js
CHANGED
|
@@ -50,8 +50,8 @@ function decode(bytes) {
|
|
|
50
50
|
signIn = pair.slice(at + 1);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
/** Exactly `length` bytes of `fd
|
|
54
|
-
*
|
|
53
|
+
/** Exactly `length` bytes of `fd`, read as the launcher's writer writes them: the end of file before then is a writer
|
|
54
|
+
* gone short, and refused. */
|
|
55
55
|
function readExactly(fd, length) {
|
|
56
56
|
const bytes = Buffer.alloc(length);
|
|
57
57
|
for (let read = 0; read < length;) {
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ModelNeeds } from "./model.js";
|
|
2
2
|
import { type HarnessCapability } from "./harness.js";
|
|
3
3
|
import { type HarnessInstaller } from "./harness-install.js";
|
|
4
|
+
import { DEFAULT_PORT } from "./host.js";
|
|
4
5
|
import { type LearningMode } from "./learning.js";
|
|
5
6
|
import { type Place } from "./place.js";
|
|
6
7
|
import { type ApiToken } from "./api-token.js";
|
|
@@ -13,7 +14,7 @@ import { type TriggerClock } from "./triggers.js";
|
|
|
13
14
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
14
15
|
import { AttachHub, type HostedDial } from "@parcha/agentrun-computer";
|
|
15
16
|
export declare const CONTRACT = "agentrun.v2/0";
|
|
16
|
-
export
|
|
17
|
+
export { DEFAULT_PORT };
|
|
17
18
|
export type ServeOptions = {
|
|
18
19
|
/** The data directory: the agent store (`store.sqlite`) and its runs (`runs/<id>/`). */
|
|
19
20
|
data: string;
|
|
@@ -239,7 +240,8 @@ export type Serve = {
|
|
|
239
240
|
dial: HostedDial;
|
|
240
241
|
/** Whether this server is a local install (listening on loopback, reached at no address off it): the one kind whose own
|
|
241
242
|
* runner beside it may reach an MCP server's URL on loopback (runner/beside.ts mcpLoopback). Only that runner is told:
|
|
242
|
-
* it is this process's finding, never a store's, so another
|
|
243
|
+
* it is this process's finding, never a store's, so another runner on a shared store never inherits it. A runner in
|
|
244
|
+
* its own process takes its own operator's opt-in from its own environment (runner/main.ts runnerLoopback). */
|
|
243
245
|
localInstall: boolean;
|
|
244
246
|
/** This server's own addresses (McpServersOverStore.own): where it listens, and its public address when that is on
|
|
245
247
|
* loopback. The runner beside it is told them with localInstall (runner/beside.ts mcpOwn), so its runs' loopback reads
|
|
@@ -907,4 +909,3 @@ export declare function forCaller<T extends {
|
|
|
907
909
|
learning: LearningCaps;
|
|
908
910
|
}>(caps: T, ownerSession: boolean): T;
|
|
909
911
|
export declare function startServe(options: ServeOptions): Promise<Serve>;
|
|
910
|
-
export {};
|