@nylorun/harness 0.37.3-beta → 0.38.0-beta
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 +67 -41
- package/HOST_CONTRACT.md +9 -10
- package/dist/api/executors.d.ts +4 -4
- package/dist/api/harness.d.ts +3 -3
- package/dist/api/harness.js +1 -1
- package/dist/api/host.d.ts +0 -18
- package/dist/api/host.js +8 -4
- package/dist/api/run.d.ts +1 -9
- package/dist/api/run.js +17 -14
- package/dist/flow/engine.d.ts +1 -1
- package/dist/flow/engine.js +1 -1
- package/dist/flow/limits.d.ts +1 -1
- package/dist/flow/limits.js +1 -1
- package/dist/flow/paths.d.ts +2 -2
- package/dist/flow/paths.js +2 -2
- package/dist/loop/compaction/config.d.ts +2 -2
- package/dist/loop/compaction/config.js +1 -1
- package/dist/loop/compaction/index.d.ts +2 -2
- package/dist/loop/compaction/index.js +2 -2
- package/dist/loop/delegation.d.ts +3 -3
- package/dist/loop/delegation.js +1 -1
- package/dist/loop/model/files.d.ts +3 -3
- package/dist/loop/model/files.js +4 -4
- package/dist/loop/model/project.d.ts +1 -1
- package/dist/loop/model/project.js +2 -2
- package/dist/loop/options.js +1 -1
- package/dist/loop/run.js +4 -4
- package/dist/loop/step/canonicalize.d.ts +2 -2
- package/dist/loop/step/canonicalize.js +2 -2
- package/dist/loop/step/step-context.d.ts +1 -1
- package/dist/loop/step/step-context.js +1 -1
- package/dist/loop/tool-result.js +2 -2
- package/dist/loop/transcript.js +1 -1
- package/dist/run/durable.d.ts +4 -4
- package/dist/run/durable.js +6 -6
- package/dist/tools/ask.d.ts +6 -6
- package/dist/tools/ask.js +1 -1
- package/dist/tools/engine-tools.d.ts +5 -5
- package/dist/tools/mcp.d.ts +1 -1
- package/dist/tools/mcp.js +1 -1
- package/dist/tools/memory.d.ts +3 -3
- package/dist/tools/outputs.js +1 -1
- package/dist/tools/person-started.d.ts +12 -0
- package/dist/tools/person-started.js +31 -0
- package/dist/tools/read-media.js +1 -1
- package/dist/tools/results.d.ts +1 -1
- package/dist/tools/results.js +3 -3
- package/dist/tools/sandbox.d.ts +1 -1
- package/dist/tools/sandbox.js +1 -1
- package/dist/tools/skills.d.ts +9 -4
- package/dist/tools/skills.js +32 -6
- package/dist/tools/tool-search.js +1 -1
- package/dist/tools/wake.js +1 -1
- package/dist/types/execution.d.ts +4 -4
- package/package.json +2 -2
package/dist/api/harness.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const DEFAULT_TRANSCRIPT_CACHE_MB = 256;
|
|
|
17
17
|
/** How soon a `lease` request that failed is sent again, by default. */
|
|
18
18
|
export declare const DEFAULT_LEASE_RETRY_MS = 100;
|
|
19
19
|
/**
|
|
20
|
-
* The waits before each resend of a tool call whose gate hop lost its answer
|
|
20
|
+
* The waits before each resend of a tool call whose gate hop lost its answer, by default;
|
|
21
21
|
* the last repeats.
|
|
22
22
|
*/
|
|
23
23
|
export declare const DEFAULT_RESEND_DELAYS_MS: readonly number[];
|
|
@@ -35,12 +35,12 @@ export interface HarnessOptions {
|
|
|
35
35
|
/** How soon a `lease` request that failed is sent again. Default `DEFAULT_LEASE_RETRY_MS` (100 ms). */
|
|
36
36
|
readonly leaseRetryMs?: number;
|
|
37
37
|
/**
|
|
38
|
-
* The waits before each resend of a tool call whose gate hop lost its answer
|
|
38
|
+
* The waits before each resend of a tool call whose gate hop lost its answer; the last
|
|
39
39
|
* repeats. Default `DEFAULT_RESEND_DELAYS_MS` (1, 2, then 4 s).
|
|
40
40
|
*/
|
|
41
41
|
readonly resendDelaysMs?: readonly number[];
|
|
42
42
|
/**
|
|
43
|
-
* Compaction
|
|
43
|
+
* Compaction: the kept tail, the reply's reserve, the estimate. Each left out
|
|
44
44
|
* is its default (`DEFAULT_COMPACTION_CONFIG`).
|
|
45
45
|
*/
|
|
46
46
|
readonly compaction?: Partial<CompactionConfig>;
|
package/dist/api/harness.js
CHANGED
|
@@ -21,7 +21,7 @@ export const DEFAULT_TRANSCRIPT_CACHE_MB = 256;
|
|
|
21
21
|
/** How soon a `lease` request that failed is sent again, by default. */
|
|
22
22
|
export const DEFAULT_LEASE_RETRY_MS = 100;
|
|
23
23
|
/**
|
|
24
|
-
* The waits before each resend of a tool call whose gate hop lost its answer
|
|
24
|
+
* The waits before each resend of a tool call whose gate hop lost its answer, by default;
|
|
25
25
|
* the last repeats.
|
|
26
26
|
*/
|
|
27
27
|
export const DEFAULT_RESEND_DELAYS_MS = Object.freeze([1_000, 2_000, 4_000]);
|
package/dist/api/host.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The engine's `DurableHost` over the Harness API. An effect whose outcome came with the run
|
|
3
|
-
* (same id, same request hash) resolves here; any other becomes an `effect.intent`. A model
|
|
4
|
-
* intent carries no prompt: core stores its hash. When core answers `execute`, the harness runs
|
|
5
|
-
* the call and reports its outcome: a `harness` tool (ours) here, over the Harness API's seams,
|
|
6
|
-
* and anything else through the executors. Before a `sandbox` call our engine mounts the skill
|
|
7
|
-
* folders of the turn's tree (`mountSkills`); the host only writes them.
|
|
8
|
-
*
|
|
9
|
-
* Every tool outcome is shaped before it is reported (`shapeToolOutcome`, protocol 15): the
|
|
10
|
-
* record refuses an entry past `limits.recordEntryBytes`, so a large or binary MCP or HTTP result,
|
|
11
|
-
* or a sandbox result past what its step has left, is stored with `artifact.write` (keyed by the
|
|
12
|
-
* effect) and the outcome carries a preview. One step's results share a budget (`StepBudget`),
|
|
13
|
-
* which replayed outcomes count toward. A cancel skips the shaping: its outcome is discarded.
|
|
14
|
-
*
|
|
15
|
-
* A tool call whose gate hop lost its answer (`executors.resends`) is sent again with the same
|
|
16
|
-
* key (R5.3): the harness waits a moment and asks core again with the same intent, and core
|
|
17
|
-
* counts the send, answering `execute` again or the call's outcome once it reached its cap.
|
|
18
|
-
*/
|
|
19
1
|
import { type HarnessChannel } from "@nylorun/core/harness-api";
|
|
20
2
|
import type { DurableHost } from "../run/durable.js";
|
|
21
3
|
import type { EngineToolOptions } from "../tools/engine-tools.js";
|
package/dist/api/host.js
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* which replayed outcomes count toward. A cancel skips the shaping: its outcome is discarded.
|
|
14
14
|
*
|
|
15
15
|
* A tool call whose gate hop lost its answer (`executors.resends`) is sent again with the same
|
|
16
|
-
* key
|
|
16
|
+
* key: the harness waits a moment and asks core again with the same intent, and core
|
|
17
17
|
* counts the send, answering `execute` again or the call's outcome once it reached its cap.
|
|
18
18
|
*/
|
|
19
|
+
import { startedSkillsOf, withPersonStartedSkills } from "../tools/person-started.js";
|
|
19
20
|
import { HarnessApiError, effectRequestHash, writeArtifactBytes, } from "@nylorun/core/harness-api";
|
|
20
21
|
import { delegatesOf } from "@nylorun/core/define";
|
|
21
22
|
import { engineFeaturesOf } from "@nylorun/core/engine";
|
|
@@ -81,7 +82,7 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
81
82
|
// The call goes on at its gate: the next run re-sends it and collects its outcome.
|
|
82
83
|
if (recoverable && kind === "shutdown")
|
|
83
84
|
throw error;
|
|
84
|
-
// The hop lost the answer: core counts one more send, and the call goes again
|
|
85
|
+
// The hop lost the answer: core counts one more send, and the call goes again.
|
|
85
86
|
if (!model && kind === undefined && executors.resends?.(effect, error, run)) {
|
|
86
87
|
const delays = engine.resendDelaysMs;
|
|
87
88
|
await pause(delays[Math.min(resent, delays.length - 1)], signal);
|
|
@@ -188,7 +189,7 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
188
189
|
? mountSkills(executors.files, channel, run, signal)
|
|
189
190
|
: undefined;
|
|
190
191
|
/**
|
|
191
|
-
* A sandbox `read` of a file the model reads as media
|
|
192
|
+
* A sandbox `read` of a file the model reads as media, which our engine runs over
|
|
192
193
|
* the run's sandbox files and the artifact seam: undefined for every other call.
|
|
193
194
|
*/
|
|
194
195
|
const media = async (effect) => {
|
|
@@ -219,7 +220,10 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
219
220
|
return runSkillTool(effect, {
|
|
220
221
|
channel,
|
|
221
222
|
run,
|
|
222
|
-
|
|
223
|
+
// A skill only a person starts is served for the root's turn that names it, never a subagent.
|
|
224
|
+
agent: withPersonStartedSkills(agentOf(run.start.manifest, effect), effect.agent === undefined
|
|
225
|
+
? startedSkillsOf(run.start.checkpoint.input)
|
|
226
|
+
: undefined),
|
|
223
227
|
readBytes: engine.skillReadBytes,
|
|
224
228
|
sandboxed: run.start.agent?.sandbox !== undefined,
|
|
225
229
|
signal,
|
package/dist/api/run.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One run: resume the engine from `turn.start` with the session's transcript (cached, or read
|
|
3
|
-
* once), run the segment over the API host, and report how it ended. Core settles it and
|
|
4
|
-
* answers with the record position the transcript is now at.
|
|
5
|
-
*
|
|
6
|
-
* A run core stopped for a shutdown or a lost lease is given back (`lease.release`); core
|
|
7
|
-
* settles nothing for it, as it never did for an advance it stopped.
|
|
8
|
-
*/
|
|
9
1
|
import { type HarnessChannel } from "@nylorun/core/harness-api";
|
|
10
2
|
import type { HarnessExecutors, HarnessRun } from "./executors.js";
|
|
11
3
|
import { type EngineConfig } from "./host.js";
|
|
@@ -22,7 +14,7 @@ export declare function runTurn(ctx: RunContext, run: HarnessRun): Promise<void>
|
|
|
22
14
|
/**
|
|
23
15
|
* The loop settings for this run: the Host's, with the compaction settings the Agent's version
|
|
24
16
|
* sets in `harness.loop.compaction` over them, and those of `roles[<role>]` over the Agent's for a
|
|
25
|
-
* session opened with that role
|
|
17
|
+
* session opened with that role. A setting that is not a positive integer is left out,
|
|
26
18
|
* and said once with an `engine.diagnostic`.
|
|
27
19
|
*/
|
|
28
20
|
export declare function agentLoopOf(ctx: {
|
package/dist/api/run.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* A run core stopped for a shutdown or a lost lease is given back (`lease.release`); core
|
|
7
7
|
* settles nothing for it, as it never did for an advance it stopped.
|
|
8
8
|
*/
|
|
9
|
+
import { startedSkillsOf, withPersonStartedSkills } from "../tools/person-started.js";
|
|
9
10
|
import { fromBase64, transcriptOf, transcriptUpdates, withTranscript, } from "@nylorun/core/harness-api";
|
|
10
11
|
import { runDurable } from "../run/durable.js";
|
|
11
12
|
import { runFlowDurable } from "../flow/engine.js";
|
|
@@ -43,7 +44,7 @@ export async function runTurn(ctx, run) {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
let checkpoint = start.checkpoint;
|
|
46
|
-
// The state is ours alone
|
|
47
|
+
// The state is ours alone: core never reads it. The turn's manifest is core's choice
|
|
47
48
|
// (the pin, or a variant a message named), and the state follows it.
|
|
48
49
|
if (start.engine === "agent" &&
|
|
49
50
|
checkpoint.state &&
|
|
@@ -58,7 +59,7 @@ export async function runTurn(ctx, run) {
|
|
|
58
59
|
}
|
|
59
60
|
// The session's MCP tools as our engine offers them (protocol 15): named, and laid out as our
|
|
60
61
|
// state pinned them while the facts stay the same.
|
|
61
|
-
// The Agent's memory
|
|
62
|
+
// The Agent's memory: its tool and rules for every agent of the tree, writes for
|
|
62
63
|
// the root only, and its index pinned at the head of the conversation.
|
|
63
64
|
const memory = start.engine === "agent" ? start.memory : undefined;
|
|
64
65
|
const rootId = start.manifest.id;
|
|
@@ -69,16 +70,18 @@ export async function runTurn(ctx, run) {
|
|
|
69
70
|
: undefined;
|
|
70
71
|
const plan = loop?.plan === true;
|
|
71
72
|
const connections = loop?.connections === true;
|
|
72
|
-
// `ask` (
|
|
73
|
+
// `ask` (`nylorun-interactions`): the version's `harness.loop.ask`, for the root agent.
|
|
73
74
|
const ask = loop?.ask === true;
|
|
74
|
-
// The triggers the agent sets up itself
|
|
75
|
+
// The triggers the agent sets up itself: the version declares `harness.engine.triggers`,
|
|
75
76
|
// for the root agent only.
|
|
76
77
|
const triggers = start.engine === "agent" && start.agent?.triggers === true;
|
|
77
|
-
|
|
78
|
+
// Skills only a person starts: the root's turn offers those its input names, a subagent none.
|
|
79
|
+
const started = startedSkillsOf(checkpoint.input);
|
|
80
|
+
const engineTools = (agent) => engineToolsFor(withPersonStartedSkills(agent, agent.id === rootId ? started : undefined), start.agent, ctx.engine, memory && {
|
|
78
81
|
access: memory.access,
|
|
79
82
|
...(memory.instructions === undefined ? {} : { instructions: memory.instructions }),
|
|
80
83
|
root: agent.id === rootId,
|
|
81
|
-
// No index is pinned when the version sets `harness.memory.index: false
|
|
84
|
+
// No index is pinned when the version sets `harness.memory.index: false`.
|
|
82
85
|
index: memory.index !== undefined,
|
|
83
86
|
}, plan && agent.id === rootId, connections && agent.id === rootId, triggers && agent.id === rootId, ask && agent.id === rootId);
|
|
84
87
|
const mcp = start.engine === "agent" && start.mcp
|
|
@@ -89,7 +92,7 @@ export async function runTurn(ctx, run) {
|
|
|
89
92
|
taken: (agent) => engineTools(agent).tools.map((tool) => tool.name),
|
|
90
93
|
})
|
|
91
94
|
: undefined;
|
|
92
|
-
// What the agent's declarations leave our engine to say, not choose
|
|
95
|
+
// What the agent's declarations leave our engine to say, not choose: claimed once,
|
|
93
96
|
// when the session's layout is decided.
|
|
94
97
|
for (const diagnostic of mcp?.diagnostics ?? [])
|
|
95
98
|
await ctx.channel
|
|
@@ -125,14 +128,14 @@ export async function runTurn(ctx, run) {
|
|
|
125
128
|
// Another session wrote the memory since this one's last turn: its index again.
|
|
126
129
|
...(memory?.refresh ? { refreshPinned: true } : {}),
|
|
127
130
|
...(start.options.yieldAfter ? { yieldAfter: start.options.yieldAfter } : {}),
|
|
128
|
-
// Core answers the `inputs` effect
|
|
131
|
+
// Core answers the `inputs` effect: messages steered into the turn.
|
|
129
132
|
takeInputs: true,
|
|
130
133
|
...(start.model ? { model: start.model } : {}),
|
|
131
134
|
files: filesOf(ctx, run, start, start.manifest.engine),
|
|
132
135
|
loop: await agentLoopOf(ctx, run, sessionId, start),
|
|
133
136
|
});
|
|
134
|
-
// Our engine's outputs folder
|
|
135
|
-
// a root agent that declares nothing or declares `engine.outputs
|
|
137
|
+
// Our engine's outputs folder: saved before the turn ends, while the run is held, for
|
|
138
|
+
// a root agent that declares nothing or declares `engine.outputs`.
|
|
136
139
|
if (start.engine === "agent" &&
|
|
137
140
|
result.status === "completed" &&
|
|
138
141
|
start.agent?.sandbox !== undefined &&
|
|
@@ -186,7 +189,7 @@ function filesOf(ctx, run, start, engine) {
|
|
|
186
189
|
return {
|
|
187
190
|
...(start.model ? { model: start.model } : {}),
|
|
188
191
|
limits: start.limits,
|
|
189
|
-
// Reference lines offer `read_artifact` only to an agent that has it
|
|
192
|
+
// Reference lines offer `read_artifact` only to an agent that has it.
|
|
190
193
|
...(engineFeaturesOf(engine, { computer: false }).artifactsRead
|
|
191
194
|
? {}
|
|
192
195
|
: { artifactReads: false }),
|
|
@@ -254,7 +257,7 @@ function outputOf(runId, result, start, recordEntryBytes) {
|
|
|
254
257
|
};
|
|
255
258
|
}
|
|
256
259
|
/**
|
|
257
|
-
* What the segment says of a compaction it made
|
|
260
|
+
* What the segment says of a compaction it made: its transcript starts with a summary it did
|
|
258
261
|
* not start with, written by the root's summary calls. Our engine keeps one summary, first; a
|
|
259
262
|
* segment that compacted twice names every summary call, and the facts of the last.
|
|
260
263
|
*/
|
|
@@ -272,12 +275,12 @@ function compactionOf(start, after, result) {
|
|
|
272
275
|
summaryEffectIds: [...ids],
|
|
273
276
|
};
|
|
274
277
|
}
|
|
275
|
-
/** The compaction settings an Agent's version may set in `harness.loop.compaction
|
|
278
|
+
/** The compaction settings an Agent's version may set in `harness.loop.compaction`. */
|
|
276
279
|
const AGENT_COMPACTION_KEYS = ["threshold", "keepTokens"];
|
|
277
280
|
/**
|
|
278
281
|
* The loop settings for this run: the Host's, with the compaction settings the Agent's version
|
|
279
282
|
* sets in `harness.loop.compaction` over them, and those of `roles[<role>]` over the Agent's for a
|
|
280
|
-
* session opened with that role
|
|
283
|
+
* session opened with that role. A setting that is not a positive integer is left out,
|
|
281
284
|
* and said once with an `engine.diagnostic`.
|
|
282
285
|
*/
|
|
283
286
|
export async function agentLoopOf(ctx, run, sessionId, start) {
|
package/dist/flow/engine.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flow engine for workflow manifest v3 (`flow-3`). A flow is data: every value a stage sees
|
|
3
3
|
* comes from the flow's input and the outputs of the agents and tools before it. Returns
|
|
4
|
-
* effects only
|
|
4
|
+
* effects only.
|
|
5
5
|
*
|
|
6
6
|
* - The first stage gets the flow's input; every later stage gets the previous output.
|
|
7
7
|
* - A Switch reads the previous output: a string is the case name, and so is an object's
|
package/dist/flow/engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flow engine for workflow manifest v3 (`flow-3`). A flow is data: every value a stage sees
|
|
3
3
|
* comes from the flow's input and the outputs of the agents and tools before it. Returns
|
|
4
|
-
* effects only
|
|
4
|
+
* effects only.
|
|
5
5
|
*
|
|
6
6
|
* - The first stage gets the flow's input; every later stage gets the previous output.
|
|
7
7
|
* - A Switch reads the previous output: a string is the case name, and so is an object's
|
package/dist/flow/limits.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flow ceilings for the engine
|
|
2
|
+
* Flow ceilings for the engine: the Tenant's Runtime limits `flowMapItems`
|
|
3
3
|
* and `flowLoopIterations`, which a flow's `turn.start.options.flowLimits` carries.
|
|
4
4
|
*/
|
|
5
5
|
export type FlowOperatorLimits = {
|
package/dist/flow/limits.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flow ceilings for the engine
|
|
2
|
+
* Flow ceilings for the engine: the Tenant's Runtime limits `flowMapItems`
|
|
3
3
|
* and `flowLoopIterations`, which a flow's `turn.start.options.flowLimits` carries.
|
|
4
4
|
*/
|
|
5
5
|
import { RUNTIME_LIMIT_DEFAULTS } from "@nylorun/core/contracts";
|
package/dist/flow/paths.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** Path, node key and iteration-vector helpers
|
|
1
|
+
/** Path, node key and iteration-vector helpers. */
|
|
2
2
|
/** Drop Map indices from a path to get the node key. */
|
|
3
3
|
export declare function nodeKeyOf(path: string): string;
|
|
4
4
|
/** Iteration vector string: enclosing Loop numbers outermost first, or "-" outside Loops. */
|
|
5
5
|
export declare function iterationsOf(vector: readonly number[]): string;
|
|
6
6
|
/**
|
|
7
|
-
* Effect id for a flow effect
|
|
7
|
+
* Effect id for a flow effect.
|
|
8
8
|
* `role` separates two effects of one kind on one path, e.g. a tool node's runs after it asked.
|
|
9
9
|
*/
|
|
10
10
|
export declare function flowEffectId(input: {
|
package/dist/flow/paths.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Path, node key and iteration-vector helpers
|
|
1
|
+
/** Path, node key and iteration-vector helpers. */
|
|
2
2
|
/** Drop Map indices from a path to get the node key. */
|
|
3
3
|
export function nodeKeyOf(path) {
|
|
4
4
|
return path.replace(/\[\d+]/g, "");
|
|
@@ -8,7 +8,7 @@ export function iterationsOf(vector) {
|
|
|
8
8
|
return vector.length === 0 ? "-" : vector.join(".");
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Effect id for a flow effect
|
|
11
|
+
* Effect id for a flow effect.
|
|
12
12
|
* `role` separates two effects of one kind on one path, e.g. a tool node's runs after it asked.
|
|
13
13
|
*/
|
|
14
14
|
export function flowEffectId(input) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Our engine's configuration of compaction
|
|
2
|
+
* Our engine's configuration of compaction: how much history it keeps verbatim,
|
|
3
3
|
* the room it holds back for the reply, and the estimate it makes of what a prompt takes. A
|
|
4
4
|
* harness sets any part of it (`createHarness({ compaction })`); each left out is its default.
|
|
5
5
|
*/
|
|
6
6
|
export interface CompactionConfig {
|
|
7
7
|
/**
|
|
8
8
|
* Compact before a model call whose estimate passes this many tokens, when that is lower than the
|
|
9
|
-
* model's window minus the reply reserve
|
|
9
|
+
* model's window minus the reply reserve. Absent: only the window's line.
|
|
10
10
|
*/
|
|
11
11
|
readonly threshold?: number;
|
|
12
12
|
/** The kept tail is at most this many tokens... */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Our engine's configuration of compaction
|
|
2
|
+
* Our engine's configuration of compaction: how much history it keeps verbatim,
|
|
3
3
|
* the room it holds back for the reply, and the estimate it makes of what a prompt takes. A
|
|
4
4
|
* harness sets any part of it (`createHarness({ compaction })`); each left out is its default.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Compaction
|
|
2
|
+
* Compaction: when history no longer fits the model's window, the engine
|
|
3
3
|
* asks the model to summarize the older part and keeps the rest verbatim.
|
|
4
4
|
*
|
|
5
5
|
* The cut rules and the summary format are adapted from the compaction in pi's
|
|
@@ -23,7 +23,7 @@ export interface ContextBudget {
|
|
|
23
23
|
export declare function contextBudget(transcript: readonly TranscriptEntry[], model?: Pick<ModelDescriptor, "contextWindow" | "maxOutputTokens">, config?: CompactionConfig): ContextBudget | undefined;
|
|
24
24
|
/**
|
|
25
25
|
* The estimate above which a model call compacts first: the model's window minus the reply reserve,
|
|
26
|
-
* or the configured `threshold` when it is lower
|
|
26
|
+
* or the configured `threshold` when it is lower. Undefined with neither.
|
|
27
27
|
*/
|
|
28
28
|
export declare function compactionLimit(budget: ContextBudget | undefined, config?: CompactionConfig): number | undefined;
|
|
29
29
|
/**
|
|
@@ -32,7 +32,7 @@ export function contextBudget(transcript, model, config = DEFAULT_COMPACTION_CON
|
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* The estimate above which a model call compacts first: the model's window minus the reply reserve,
|
|
35
|
-
* or the configured `threshold` when it is lower
|
|
35
|
+
* or the configured `threshold` when it is lower. Undefined with neither.
|
|
36
36
|
*/
|
|
37
37
|
export function compactionLimit(budget, config = DEFAULT_COMPACTION_CONFIG) {
|
|
38
38
|
const line = budget ? budget.contextWindow - budget.reserve : undefined;
|
|
@@ -143,7 +143,7 @@ export function findCut(transcript, keepTokens, config = DEFAULT_COMPACTION_CONF
|
|
|
143
143
|
export async function compact(input) {
|
|
144
144
|
const { transcript } = input;
|
|
145
145
|
const config = input.config ?? DEFAULT_COMPACTION_CONFIG;
|
|
146
|
-
// An agent without `read_artifact`
|
|
146
|
+
// An agent without `read_artifact` is offered it in no line, a summary's either.
|
|
147
147
|
const readable = input.files?.artifactReads !== false;
|
|
148
148
|
const tokensBefore = estimateTokens(transcript, input.turnId, input.files, config);
|
|
149
149
|
const window = input.budget?.contextWindow ?? tokensBefore;
|
|
@@ -8,7 +8,7 @@ export interface DelegationHost {
|
|
|
8
8
|
child(delegate: Delegate, ref: AgentRef): {
|
|
9
9
|
readonly definition: AgentDefinition;
|
|
10
10
|
readonly onModelCall: ModelAdapter;
|
|
11
|
-
/** Whether the child has `read_artifact
|
|
11
|
+
/** Whether the child has `read_artifact`, when it is not the parent's. */
|
|
12
12
|
readonly artifactReads?: boolean;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
@@ -31,7 +31,7 @@ export interface ExecuteInternals {
|
|
|
31
31
|
/** Set when this invocation is an agent used as a tool. */
|
|
32
32
|
readonly delegated?: AgentRef;
|
|
33
33
|
/**
|
|
34
|
-
* Segment rollover
|
|
34
|
+
* Segment rollover: end the invocation with `yielded` at the next step
|
|
35
35
|
* boundary once this many steps ran, or this much time passed, in this invocation.
|
|
36
36
|
*/
|
|
37
37
|
readonly yieldAfter?: {
|
|
@@ -41,7 +41,7 @@ export interface ExecuteInternals {
|
|
|
41
41
|
/** The loop's settings (compaction, a failed child's partial output). Default `DEFAULT_LOOP_CONFIG`. */
|
|
42
42
|
readonly loop?: LoopConfig;
|
|
43
43
|
/**
|
|
44
|
-
* The messages steered into the running turn
|
|
44
|
+
* The messages steered into the running turn, asked before every step but the turn's
|
|
45
45
|
* first: each one's input as its message gave it, which the loop reads as a user message. Set
|
|
46
46
|
* for the root invocation only; an agent used as a tool never takes them.
|
|
47
47
|
*/
|
package/dist/loop/delegation.js
CHANGED
|
@@ -53,7 +53,7 @@ export async function runDelegation(invocation, execute, call, delegate) {
|
|
|
53
53
|
onModelCall: child.onModelCall,
|
|
54
54
|
signal,
|
|
55
55
|
// A child calls the same model, and reads its files as the parent does, with
|
|
56
|
-
// `read_artifact` as it declares
|
|
56
|
+
// `read_artifact` as it declares.
|
|
57
57
|
...(options.model === undefined ? {} : { model: options.model }),
|
|
58
58
|
...(options.files === undefined
|
|
59
59
|
? {}
|
|
@@ -28,7 +28,7 @@ export type FileView =
|
|
|
28
28
|
/** What `fileView` decides from: the turn's model and the Runtime limits. */
|
|
29
29
|
export interface FileViewContext {
|
|
30
30
|
/**
|
|
31
|
-
* False when the agent has no `read_artifact` (
|
|
31
|
+
* False when the agent has no `read_artifact` (an `agent-folder/2` agent without
|
|
32
32
|
* `engine.artifacts.read`): its files' reference lines do not offer it. Default true.
|
|
33
33
|
*/
|
|
34
34
|
readonly artifactReads?: boolean;
|
|
@@ -61,7 +61,7 @@ export declare function fileNote(name: string, type: string, why: string): strin
|
|
|
61
61
|
* The line a file stands for in a prompt (protocol 12): its name, artifact id and version, and
|
|
62
62
|
* how the model reads it again. A file a tool returned names the tool. Every file is its line
|
|
63
63
|
* once its turn is over; in its own turn the line labels what follows it. `readable` false for
|
|
64
|
-
* an agent without `read_artifact
|
|
64
|
+
* an agent without `read_artifact`: the line names the file only.
|
|
65
65
|
*/
|
|
66
66
|
export declare function mediaReferenceLine(part: FilePart, origin: "uploaded" | {
|
|
67
67
|
readonly tool: string;
|
|
@@ -75,7 +75,7 @@ export interface LiveFile {
|
|
|
75
75
|
readonly origin?: "uploaded" | "tool";
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* The most files from tool results one model call carries as media
|
|
78
|
+
* The most files from tool results one model call carries as media. A file the model
|
|
79
79
|
* looked at stays in the turn's files and is sent on every later call of the turn; past these,
|
|
80
80
|
* the oldest go as a note naming them, which `read_artifact` brings back. A person's own files
|
|
81
81
|
* are never capped.
|
package/dist/loop/model/files.js
CHANGED
|
@@ -54,7 +54,7 @@ export function fileNote(name, type, why) {
|
|
|
54
54
|
* The line a file stands for in a prompt (protocol 12): its name, artifact id and version, and
|
|
55
55
|
* how the model reads it again. A file a tool returned names the tool. Every file is its line
|
|
56
56
|
* once its turn is over; in its own turn the line labels what follows it. `readable` false for
|
|
57
|
-
* an agent without `read_artifact
|
|
57
|
+
* an agent without `read_artifact`: the line names the file only.
|
|
58
58
|
*/
|
|
59
59
|
export function mediaReferenceLine(part, origin, readable = true) {
|
|
60
60
|
const reference = mediaReferenceOf(part.reference);
|
|
@@ -62,11 +62,11 @@ export function mediaReferenceLine(part, origin, readable = true) {
|
|
|
62
62
|
if (!reference)
|
|
63
63
|
return `[${what} (${part.mediaType})]`;
|
|
64
64
|
const name = JSON.stringify(reference.name ?? reference.artifactId);
|
|
65
|
-
// An agent without `read_artifact`
|
|
65
|
+
// An agent without `read_artifact` is not offered it.
|
|
66
66
|
return `[${what} ${name} · ${reference.artifactId} v${reference.version}${readable ? " · read_artifact to view" : ""}]`;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* The most files from tool results one model call carries as media
|
|
69
|
+
* The most files from tool results one model call carries as media. A file the model
|
|
70
70
|
* looked at stays in the turn's files and is sent on every later call of the turn; past these,
|
|
71
71
|
* the oldest go as a note naming them, which `read_artifact` brings back. A person's own files
|
|
72
72
|
* are never capped.
|
|
@@ -92,7 +92,7 @@ export async function representFiles(files, context, signal) {
|
|
|
92
92
|
for (const file of files)
|
|
93
93
|
if (!views.has(file.key))
|
|
94
94
|
views.set(file.key, context ? fileView(file.part, context.model, context.limits) : { kind: "media" });
|
|
95
|
-
// The newest tool files go as media; older ones past the cap, as a note
|
|
95
|
+
// The newest tool files go as media; older ones past the cap, as a note.
|
|
96
96
|
const capped = new Set();
|
|
97
97
|
if (context) {
|
|
98
98
|
let kept = 0;
|
|
@@ -7,7 +7,7 @@ import { type LiveFile } from "./files.js";
|
|
|
7
7
|
* the context, in one user message: each file's line, then what `files` (`representFiles`)
|
|
8
8
|
* made of it, a media part, a `<file>` block or a note. Without `files`, each goes as its media
|
|
9
9
|
* part. Their content reaches the model only in their own turn. `readable` false for an agent
|
|
10
|
-
* without `read_artifact
|
|
10
|
+
* without `read_artifact`: no reference line offers it. Last, when the turn's plan has
|
|
11
11
|
* fallen behind, one line reminds the model to keep it (`planReminder`).
|
|
12
12
|
*/
|
|
13
13
|
export declare function projectModelCall(request: ModelRequest, files?: ReadonlyMap<string, readonly PromptContentPart[]>, readable?: boolean): ModelCall;
|
|
@@ -10,7 +10,7 @@ import { FILES_MESSAGE_HEADER, fileKeyOf, mediaReferenceLine, } from "./files.js
|
|
|
10
10
|
* the context, in one user message: each file's line, then what `files` (`representFiles`)
|
|
11
11
|
* made of it, a media part, a `<file>` block or a note. Without `files`, each goes as its media
|
|
12
12
|
* part. Their content reaches the model only in their own turn. `readable` false for an agent
|
|
13
|
-
* without `read_artifact
|
|
13
|
+
* without `read_artifact`: no reference line offers it. Last, when the turn's plan has
|
|
14
14
|
* fallen behind, one line reminds the model to keep it (`planReminder`).
|
|
15
15
|
*/
|
|
16
16
|
export function projectModelCall(request, files, readable = true) {
|
|
@@ -201,7 +201,7 @@ function projectToolResult(result, readable) {
|
|
|
201
201
|
status: result.kind,
|
|
202
202
|
content: [
|
|
203
203
|
textPart(JSON.stringify(toolResultPayload(result))),
|
|
204
|
-
// Files the tool returned, stored by the host
|
|
204
|
+
// Files the tool returned, stored by the host: each is its reference line, and
|
|
205
205
|
// goes to the model in its own turn with the turn's files.
|
|
206
206
|
...(result.kind === "completed" && result.files
|
|
207
207
|
? result.files.map((file) => textPart(mediaReferenceLine(file, { tool: result.toolName }, readable)))
|
package/dist/loop/options.js
CHANGED
|
@@ -36,7 +36,7 @@ export function openExecution(agent, options) {
|
|
|
36
36
|
if (state.agentId !== agent.id)
|
|
37
37
|
throw new HarnessError("execution.incompatible", "Saved state requires the original compatible agent and outputSchema");
|
|
38
38
|
if (canonical(state.outputContract) !== canonical(agent.output?.schema.jsonSchema)) {
|
|
39
|
-
// Between turns, a new version of the agent
|
|
39
|
+
// Between turns, a new version of the agent may change its output schema: the next
|
|
40
40
|
// turn takes it. A turn in progress keeps the schema it started with.
|
|
41
41
|
if (state.status === "active" || state.plan !== undefined)
|
|
42
42
|
throw new HarnessError("execution.incompatible", "Saved state requires the original compatible agent and outputSchema");
|
package/dist/loop/run.js
CHANGED
|
@@ -41,7 +41,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
41
41
|
const started = Date.now();
|
|
42
42
|
/** One compaction and retry per overflow; reset once a step succeeds. */
|
|
43
43
|
let overflowCompacted = false;
|
|
44
|
-
/** Summarize older history into a compaction entry
|
|
44
|
+
/** Summarize older history into a compaction entry. */
|
|
45
45
|
const compactHistory = async (trigger, stepId) => {
|
|
46
46
|
const next = await compact({
|
|
47
47
|
transcript: invocation.state.transcript,
|
|
@@ -57,7 +57,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
57
57
|
});
|
|
58
58
|
if (!next)
|
|
59
59
|
return false;
|
|
60
|
-
// The pinned text is re-pinned fresh by the next segment (the memory index
|
|
60
|
+
// The pinned text is re-pinned fresh by the next segment (the memory index).
|
|
61
61
|
const { pinned: _pinned, ...state } = invocation.state;
|
|
62
62
|
invocation.state = { ...state, transcript: next };
|
|
63
63
|
await record();
|
|
@@ -115,7 +115,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
115
115
|
invocation.state = { ...invocation.state, turn: { turnId } };
|
|
116
116
|
return finish({ status: "yielded" });
|
|
117
117
|
}
|
|
118
|
-
// Messages steered into the running turn
|
|
118
|
+
// Messages steered into the running turn: every step but the turn's first may take
|
|
119
119
|
// them, after the tool results the model sees next, and never while a plan dispatches.
|
|
120
120
|
if (internals.takeInputs && stepNumber > 1 && !invocation.state.plan) {
|
|
121
121
|
// Each is a message's input as sent (text, or a user message with parts), as at turn start.
|
|
@@ -143,7 +143,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
143
143
|
stepsRun++;
|
|
144
144
|
const stepId = createId("step");
|
|
145
145
|
// Keep the next prompt inside the model's window, and under the Agent's threshold when it
|
|
146
|
-
// sets a lower one
|
|
146
|
+
// sets a lower one, before it is sent.
|
|
147
147
|
const budget = contextBudget(invocation.state.transcript, options.model, compaction);
|
|
148
148
|
const limit = compactionLimit(budget, compaction);
|
|
149
149
|
if (limit !== undefined &&
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ModelCandidate, ModelOutputBlock } from "@nylorun/core/define";
|
|
2
2
|
import type { JsonObject } from "@nylorun/core/define";
|
|
3
3
|
/**
|
|
4
|
-
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory
|
|
5
|
-
*
|
|
4
|
+
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory`:
|
|
5
|
+
* the `memory` tool with that command, as the conversation records it from then on.
|
|
6
6
|
* A call whose own `command` disagrees with its name stays as it was, and fails as unknown.
|
|
7
7
|
*/
|
|
8
8
|
export declare function memoryAliasCall(name: string, args: JsonObject, offered: ReadonlySet<string>): {
|
|
@@ -2,8 +2,8 @@ import { createId } from "../../utils/ids.js";
|
|
|
2
2
|
import { copyJson } from "@nylorun/core/define";
|
|
3
3
|
import { memoryAliasOf } from "@nylorun/core/contracts";
|
|
4
4
|
/**
|
|
5
|
-
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory
|
|
6
|
-
*
|
|
5
|
+
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory`:
|
|
6
|
+
* the `memory` tool with that command, as the conversation records it from then on.
|
|
7
7
|
* A call whose own `command` disagrees with its name stays as it was, and fails as unknown.
|
|
8
8
|
*/
|
|
9
9
|
export function memoryAliasCall(name, args, offered) {
|
|
@@ -6,7 +6,7 @@ import type { Tripwire } from "@nylorun/core/define";
|
|
|
6
6
|
import { type CanonicalCall } from "./canonicalize.js";
|
|
7
7
|
import { ModelConfigurationDraft } from "./model-configuration.js";
|
|
8
8
|
/**
|
|
9
|
-
* A message's context (
|
|
9
|
+
* A message's context (Host feature `message-context`): the items of the turn's latest
|
|
10
10
|
* input that carries `metadata.context`, for every model call of that turn. A later turn's calls
|
|
11
11
|
* never see them: the block is rendered after the history, not kept in it.
|
|
12
12
|
*/
|
|
@@ -6,7 +6,7 @@ const EMPTY_CONTEXT = Object.freeze({
|
|
|
6
6
|
contributors: Object.freeze([]),
|
|
7
7
|
});
|
|
8
8
|
/**
|
|
9
|
-
* A message's context (
|
|
9
|
+
* A message's context (Host feature `message-context`): the items of the turn's latest
|
|
10
10
|
* input that carries `metadata.context`, for every model call of that turn. A later turn's calls
|
|
11
11
|
* never see them: the block is rendered after the history, not kept in it.
|
|
12
12
|
*/
|
package/dist/loop/tool-result.js
CHANGED
|
@@ -3,7 +3,7 @@ import { copyJson } from "@nylorun/core/define";
|
|
|
3
3
|
export function toolResult(call, definition, outcome) {
|
|
4
4
|
const identity = { callId: call.callId, toolName: call.toolName };
|
|
5
5
|
if (outcome.kind === "completed") {
|
|
6
|
-
// A preview the Runtime made of a result too large to show is not the tool's output
|
|
6
|
+
// A preview the Runtime made of a result too large to show is not the tool's output.
|
|
7
7
|
const checked = outcome.truncated === true ? undefined : definition.outputSchema?.validate(outcome.output);
|
|
8
8
|
if (checked && !checked.ok)
|
|
9
9
|
return {
|
|
@@ -36,7 +36,7 @@ export function toolResult(call, definition, outcome) {
|
|
|
36
36
|
return copyJson({ ...identity, kind: "denied", reason: outcome.reason });
|
|
37
37
|
throw new HarnessError("tool.invalid-tool-result", "Expected a completed, failed, or denied tool result");
|
|
38
38
|
}
|
|
39
|
-
/** A file the model sees beside a tool's output
|
|
39
|
+
/** A file the model sees beside a tool's output: a media type and the host's reference. */
|
|
40
40
|
function fileOf(file) {
|
|
41
41
|
if (typeof file?.mediaType !== "string" || file.mediaType === "" || file.reference === undefined)
|
|
42
42
|
throw new HarnessError("tool.invalid-tool-result", "A tool result file needs a mediaType and a reference");
|
package/dist/loop/transcript.js
CHANGED
|
@@ -219,7 +219,7 @@ function toolResult(value, index) {
|
|
|
219
219
|
fail(`Tool result ${index} has unknown kind '${String(result.kind)}'`);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
/** A completed result's files
|
|
222
|
+
/** A completed result's files: a media type and the host's reference each. */
|
|
223
223
|
function resultFiles(value, index) {
|
|
224
224
|
if (!Array.isArray(value))
|
|
225
225
|
fail(`Tool result ${index} files must be an array`);
|