@nylorun/harness 0.30.1-beta → 0.32.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 +46 -0
- package/dist/api/host.js +13 -0
- package/dist/api/run.js +33 -5
- package/dist/loop/compaction/index.js +11 -8
- package/dist/loop/delegation.d.ts +2 -0
- package/dist/loop/delegation.js +9 -2
- package/dist/loop/model/files.d.ts +8 -2
- package/dist/loop/model/files.js +5 -3
- package/dist/loop/model/project.d.ts +5 -4
- package/dist/loop/model/project.js +16 -14
- package/dist/loop/step/run.js +3 -2
- package/dist/run/durable.d.ts +8 -18
- package/dist/run/durable.js +9 -4
- package/dist/tools/artifacts.d.ts +5 -3
- package/dist/tools/artifacts.js +13 -107
- package/dist/tools/connection.d.ts +2 -8
- package/dist/tools/connection.js +20 -39
- package/dist/tools/engine-tools.d.ts +27 -18
- package/dist/tools/engine-tools.js +9 -53
- package/dist/tools/mcp.d.ts +5 -90
- package/dist/tools/mcp.js +5 -238
- package/dist/tools/memory.d.ts +18 -5
- package/dist/tools/memory.js +4 -125
- package/dist/tools/plan.d.ts +6 -7
- package/dist/tools/plan.js +4 -48
- package/dist/tools/results.d.ts +6 -0
- package/dist/tools/results.js +3 -2
- package/dist/tools/sandbox.d.ts +13 -33
- package/dist/tools/sandbox.js +13 -127
- package/dist/tools/skills.d.ts +4 -24
- package/dist/tools/skills.js +3 -69
- package/dist/tools/tool-search.d.ts +1 -22
- package/dist/tools/tool-search.js +2 -78
- package/dist/tools/wake.d.ts +0 -7
- package/dist/tools/wake.js +10 -30
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.32.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 714bee2: The triggers capability (Host feature `agent-triggers`): an agent-folder/2 folder declares `engine: { triggers: true }` (the root agent's only; `engine.instructions.triggers` replaces its wording), which compiles to `harness.engine.triggers` and offers the root agent the `triggers` tool (`list`, `create`, `delete`) and the text block `triggers@1`. The Runtime serves each call as a `runtime` effect (operation `triggers`, `turn.start.agent.triggers`, Harness API v5.3): a trigger an agent makes is the Agent's (`origin: "agent"`, with its title and the session that made it), runs in the calling session (`session: "this"`) or one of its own (`"own"`, `<session>_t_<id>`), is checked against the limits in force (`runtime.limits.triggers` within the Tenant's), survives upgrades and waits paused while a version lacks the capability; a turn a trigger started can't create one. Tool rules take `kind: "runtime"`, so an `ask` rule can hold a `triggers` call (its interaction carries `metadata.input`); `DELETE /v1/agents/{id}/triggers/{triggerId}` deletes an agent's trigger (`409 trigger_from_manifest` for a manifest's); `GET /v1/runs/stream` serves the Tenant's runs as server-sent events from a cursor (`410 cursor_expired` across a reset). `client.agents.deleteTrigger`, `client.runs.stream` and `nylorun agents triggers rm` follow. The JSON Schemas are republished as `agent-manifest/v8.3`, `harness-manifest/v1.3`, `runtime-manifest/v1.2`, `agent-folder/v1/agent-md.3`, `agent-folder/v1/runtime.2` and `harness-api/v5.3`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Pin core to the tested release.
|
|
12
|
+
- Updated dependencies [714bee2]
|
|
13
|
+
- @nylorun/core@0.35.0-beta
|
|
14
|
+
|
|
15
|
+
## 0.31.0-beta
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 67ed2ea: An agent that declares its engine features (`engine`, `agent-folder/2`, ADR-100) gets only those:
|
|
20
|
+
no shell or file tools and no sandbox note without `engine.sandbox` (or only the tools it names),
|
|
21
|
+
no `read_artifact` or `save_artifact` or their text unless declared, and `/workspace/outputs` is
|
|
22
|
+
saved when a turn ends only with `engine.outputs`. Without `artifacts.read`, a tool result past
|
|
23
|
+
the inline cap is cut to its preview with `retrievable: false` (still stored), and file reference
|
|
24
|
+
lines do not offer `read_artifact`. Without `toolSearch`, MCP tools are never deferred
|
|
25
|
+
automatically (a server's own `deferred` still applies); past the threshold the harness claims
|
|
26
|
+
`engine.diagnostic` (`mcp_tools_inline`) once. A turn whose `memory` has no `index` pins none, and
|
|
27
|
+
the memory rules do not name one. A block the manifest replaces (`engine.instructions`) is in its
|
|
28
|
+
words, the memory rule that outside text is data kept. Agents that declare nothing get exactly
|
|
29
|
+
what they got before. The engine's text and tool definitions now come from
|
|
30
|
+
`@nylorun/core/engine`, which the SDK's `previewTurn` runs too.
|
|
31
|
+
- 67ed2ea: The memory index a session pinned is refreshed at its next turn's first segment (never mid-turn)
|
|
32
|
+
when another session of the Agent, or the API, wrote the Agent's memory since its last turn started:
|
|
33
|
+
`turn.start.memory.refresh` (Harness API), and our engine pins the index again (`runDurable`'s
|
|
34
|
+
`refreshPinned`). The Runtime keeps the newest memory version a turn saw on the session
|
|
35
|
+
(`Session.memoryIndex`, `memoryWritesSince`). A session's own writes leave its index as pinned.
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Pin core to the tested release.
|
|
40
|
+
- Updated dependencies [67ed2ea]
|
|
41
|
+
- Updated dependencies [67ed2ea]
|
|
42
|
+
- Updated dependencies [67ed2ea]
|
|
43
|
+
- Updated dependencies [67ed2ea]
|
|
44
|
+
- Updated dependencies [67ed2ea]
|
|
45
|
+
- Updated dependencies [67ed2ea]
|
|
46
|
+
- Updated dependencies [67ed2ea]
|
|
47
|
+
- @nylorun/core@0.34.0-beta
|
|
48
|
+
|
|
3
49
|
## 0.30.1-beta
|
|
4
50
|
|
|
5
51
|
### Patch Changes
|
package/dist/api/host.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { HarnessApiError, effectRequestHash, writeArtifactBytes, } from "@nylorun/core/harness-api";
|
|
20
20
|
import { delegatesOf } from "@nylorun/core/define";
|
|
21
|
+
import { engineFeaturesOf } from "@nylorun/core/engine";
|
|
21
22
|
import { isArtifactTool, runArtifactTool } from "../tools/artifacts.js";
|
|
22
23
|
import { isSkillTool, mountSkills, runSkillTool } from "../tools/skills.js";
|
|
23
24
|
import { StepBudget, jsonBytes, mayNeedShaping, shapeToolOutcome, spillKey, } from "../tools/results.js";
|
|
@@ -123,6 +124,7 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
123
124
|
...(run.start.model ? { model: run.start.model } : {}),
|
|
124
125
|
limits,
|
|
125
126
|
config: engine.toolResults,
|
|
127
|
+
...(readsArtifacts(effect) ? {} : { retrievable: false }),
|
|
126
128
|
store: (bytes, artifact) => store(effect, bytes, artifact),
|
|
127
129
|
});
|
|
128
130
|
// Shaping keeps a result under its cap; one that a store could not hold is refused here,
|
|
@@ -132,6 +134,17 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
132
134
|
return fitted;
|
|
133
135
|
});
|
|
134
136
|
};
|
|
137
|
+
/** Whether the call's agent (the root, or the agent used as a tool) has `read_artifact`. */
|
|
138
|
+
const readsArtifacts = (effect) => {
|
|
139
|
+
const root = run.start.manifest;
|
|
140
|
+
if (!root || typeof root !== "object")
|
|
141
|
+
return true;
|
|
142
|
+
const agent = effect.agent === undefined
|
|
143
|
+
? root
|
|
144
|
+
: (delegatesOf(root).find(({ manifest }) => manifest.id === effect.agent.id)?.manifest ??
|
|
145
|
+
root);
|
|
146
|
+
return engineFeaturesOf(agent.engine, { computer: false }).artifactsRead;
|
|
147
|
+
};
|
|
135
148
|
/** Stores a tool result's bytes as an artifact of the run's session, linked to its call. */
|
|
136
149
|
const store = async (effect, bytes, artifact) => {
|
|
137
150
|
try {
|
package/dist/api/run.js
CHANGED
|
@@ -12,6 +12,7 @@ import { runFlowDurable } from "../flow/engine.js";
|
|
|
12
12
|
import { runAbortKind } from "./abort.js";
|
|
13
13
|
import { apiHost } from "./host.js";
|
|
14
14
|
import { engineToolsFor } from "../tools/engine-tools.js";
|
|
15
|
+
import { engineFeaturesOf } from "@nylorun/core/engine";
|
|
15
16
|
import { memoryIndexBlock } from "../tools/memory.js";
|
|
16
17
|
import { mcpToolSet } from "../tools/mcp.js";
|
|
17
18
|
import { saveOutputs } from "../tools/outputs.js";
|
|
@@ -68,11 +69,16 @@ export async function runTurn(ctx, run) {
|
|
|
68
69
|
: undefined;
|
|
69
70
|
const plan = loop?.plan === true;
|
|
70
71
|
const connections = loop?.connections === true;
|
|
72
|
+
// The triggers the agent sets up itself (D83): the version declares `harness.engine.triggers`,
|
|
73
|
+
// for the root agent only.
|
|
74
|
+
const triggers = start.engine === "agent" && start.agent?.triggers === true;
|
|
71
75
|
const engineTools = (agent) => engineToolsFor(agent, start.agent, ctx.engine, memory && {
|
|
72
76
|
access: memory.access,
|
|
73
77
|
...(memory.instructions === undefined ? {} : { instructions: memory.instructions }),
|
|
74
78
|
root: agent.id === rootId,
|
|
75
|
-
|
|
79
|
+
// No index is pinned when the version sets `harness.memory.index: false` (ADR-100).
|
|
80
|
+
index: memory.index !== undefined,
|
|
81
|
+
}, plan && agent.id === rootId, connections && agent.id === rootId, triggers && agent.id === rootId);
|
|
76
82
|
const mcp = start.engine === "agent" && start.mcp
|
|
77
83
|
? mcpToolSet(start.mcp, start.manifest, {
|
|
78
84
|
config: ctx.engine.mcpTools,
|
|
@@ -81,6 +87,18 @@ export async function runTurn(ctx, run) {
|
|
|
81
87
|
taken: (agent) => engineTools(agent).tools.map((tool) => tool.name),
|
|
82
88
|
})
|
|
83
89
|
: undefined;
|
|
90
|
+
// What the agent's declarations leave our engine to say, not choose (ADR-100): claimed once,
|
|
91
|
+
// when the session's layout is decided.
|
|
92
|
+
for (const diagnostic of mcp?.diagnostics ?? [])
|
|
93
|
+
await ctx.channel
|
|
94
|
+
.request("event", {
|
|
95
|
+
runId,
|
|
96
|
+
sessionId,
|
|
97
|
+
turnId: run.grant.turnId,
|
|
98
|
+
type: "engine.diagnostic",
|
|
99
|
+
payload: diagnostic,
|
|
100
|
+
})
|
|
101
|
+
.catch(() => undefined);
|
|
84
102
|
const host = apiHost(ctx.channel, ctx.executors, run, ctx.engine, mcp);
|
|
85
103
|
const result = start.engine === "flow"
|
|
86
104
|
? await runFlowDurable({
|
|
@@ -99,16 +117,22 @@ export async function runTurn(ctx, run) {
|
|
|
99
117
|
...(mcp ? { mcp } : {}),
|
|
100
118
|
// Our engine's own tools and text, from the turn's facts (protocol 15).
|
|
101
119
|
engineTools,
|
|
102
|
-
...(memory
|
|
120
|
+
...(memory?.index !== undefined
|
|
121
|
+
? { pinned: [memoryIndexBlock({ index: memory.index, truncated: memory.truncated })] }
|
|
122
|
+
: {}),
|
|
123
|
+
// Another session wrote the memory since this one's last turn: its index again.
|
|
124
|
+
...(memory?.refresh ? { refreshPinned: true } : {}),
|
|
103
125
|
...(start.options.yieldAfter ? { yieldAfter: start.options.yieldAfter } : {}),
|
|
104
126
|
...(start.model ? { model: start.model } : {}),
|
|
105
|
-
files: filesOf(ctx, run, start),
|
|
127
|
+
files: filesOf(ctx, run, start, start.manifest.engine),
|
|
106
128
|
loop: ctx.engine.loop,
|
|
107
129
|
});
|
|
108
|
-
// Our engine's outputs folder (Q5): saved before the turn ends, while the run is held
|
|
130
|
+
// Our engine's outputs folder (Q5): saved before the turn ends, while the run is held, for
|
|
131
|
+
// a root agent that declares nothing or declares `engine.outputs` (ADR-100).
|
|
109
132
|
if (start.engine === "agent" &&
|
|
110
133
|
result.status === "completed" &&
|
|
111
134
|
start.agent?.sandbox !== undefined &&
|
|
135
|
+
engineFeaturesOf(start.manifest.engine, { computer: true }).outputs &&
|
|
112
136
|
ctx.executors.files)
|
|
113
137
|
await saveOutputs({
|
|
114
138
|
channel: ctx.channel,
|
|
@@ -154,10 +178,14 @@ export async function runTurn(ctx, run) {
|
|
|
154
178
|
* How the run's engine reads the turn's files (protocol 15): it decides from the model
|
|
155
179
|
* descriptor and the Runtime limits, and reads text over the artifact seam.
|
|
156
180
|
*/
|
|
157
|
-
function filesOf(ctx, run, start) {
|
|
181
|
+
function filesOf(ctx, run, start, engine) {
|
|
158
182
|
return {
|
|
159
183
|
...(start.model ? { model: start.model } : {}),
|
|
160
184
|
limits: start.limits,
|
|
185
|
+
// Reference lines offer `read_artifact` only to an agent that has it (ADR-100).
|
|
186
|
+
...(engineFeaturesOf(engine, { computer: false }).artifactsRead
|
|
187
|
+
? {}
|
|
188
|
+
: { artifactReads: false }),
|
|
161
189
|
async read(reference, offset, length, signal) {
|
|
162
190
|
const answer = await ctx.channel.request("artifact.read", {
|
|
163
191
|
runId: run.runId,
|
|
@@ -82,19 +82,19 @@ function filesTokens(entry, files, config) {
|
|
|
82
82
|
}, 0);
|
|
83
83
|
}
|
|
84
84
|
/** The files an entry names (protocol 12): a message's media parts, and a tool result's files. */
|
|
85
|
-
function filesOf(entry) {
|
|
85
|
+
function filesOf(entry, readable = true) {
|
|
86
86
|
if (entry.kind === "input") {
|
|
87
87
|
const event = entry.event;
|
|
88
88
|
if ((event.kind !== "user-message" && event.kind !== "interrupt") ||
|
|
89
89
|
!("content" in event) ||
|
|
90
90
|
!event.content)
|
|
91
91
|
return [];
|
|
92
|
-
return event.content.flatMap((part) => part.type === "media" ? [{ line: mediaReferenceLine(part, "uploaded"), part }] : []);
|
|
92
|
+
return event.content.flatMap((part) => part.type === "media" ? [{ line: mediaReferenceLine(part, "uploaded", readable), part }] : []);
|
|
93
93
|
}
|
|
94
94
|
if (entry.kind === "tool-results")
|
|
95
95
|
return entry.results.flatMap((result) => result.kind === "completed" && result.files
|
|
96
96
|
? result.files.map((part) => ({
|
|
97
|
-
line: mediaReferenceLine(part, { tool: result.toolName }),
|
|
97
|
+
line: mediaReferenceLine(part, { tool: result.toolName }, readable),
|
|
98
98
|
part,
|
|
99
99
|
}))
|
|
100
100
|
: []);
|
|
@@ -133,6 +133,8 @@ export function findCut(transcript, keepTokens, config = DEFAULT_COMPACTION_CONF
|
|
|
133
133
|
export async function compact(input) {
|
|
134
134
|
const { transcript } = input;
|
|
135
135
|
const config = input.config ?? DEFAULT_COMPACTION_CONFIG;
|
|
136
|
+
// An agent without `read_artifact` (ADR-100) is offered it in no line, a summary's either.
|
|
137
|
+
const readable = input.files?.artifactReads !== false;
|
|
136
138
|
const tokensBefore = estimateTokens(transcript, input.turnId, input.files, config);
|
|
137
139
|
const window = input.budget?.contextWindow ?? tokensBefore;
|
|
138
140
|
const keepTokens = Math.max(1, Math.min(config.keepTokens, Math.floor(window * config.keepShare)));
|
|
@@ -153,7 +155,7 @@ export async function compact(input) {
|
|
|
153
155
|
...(previous?.files ?? []),
|
|
154
156
|
...older
|
|
155
157
|
.filter((entry) => !request.includes(entry))
|
|
156
|
-
.flatMap((entry) => filesOf(entry).map(({ line }) => line)),
|
|
158
|
+
.flatMap((entry) => filesOf(entry, readable).map(({ line }) => line)),
|
|
157
159
|
]),
|
|
158
160
|
];
|
|
159
161
|
const keptTokens = tail.reduce((sum, entry) => sum + entryTokens(entry, config), 0);
|
|
@@ -247,8 +249,9 @@ function chunked(entries, limit, config) {
|
|
|
247
249
|
return chunks;
|
|
248
250
|
}
|
|
249
251
|
function summaryCall(input, older, previous, maxOutputTokens, clip) {
|
|
252
|
+
const readable = input.files?.artifactReads !== false;
|
|
250
253
|
const conversation = older
|
|
251
|
-
.map((entry) => entryText(entry, clip))
|
|
254
|
+
.map((entry) => entryText(entry, clip, readable))
|
|
252
255
|
.filter((text) => text !== "")
|
|
253
256
|
.join("\n\n");
|
|
254
257
|
const text = [
|
|
@@ -296,14 +299,14 @@ function summaryText(outcome) {
|
|
|
296
299
|
return outcome.output.flatMap((block) => (block.type === "text" ? [block.text] : [])).join("");
|
|
297
300
|
}
|
|
298
301
|
/** The model-visible text of one entry, with tool payloads clipped to `clip` characters. */
|
|
299
|
-
function entryText(entry, clip) {
|
|
302
|
+
function entryText(entry, clip, readable = true) {
|
|
300
303
|
switch (entry.kind) {
|
|
301
304
|
case "input": {
|
|
302
305
|
const event = entry.event;
|
|
303
306
|
if (event.kind === "user-message" || event.kind === "interrupt")
|
|
304
307
|
return `[User]: ${"content" in event && event.content
|
|
305
308
|
? event.content
|
|
306
|
-
.map((part) => part.type === "text" ? part.text : mediaReferenceLine(part, "uploaded"))
|
|
309
|
+
.map((part) => part.type === "text" ? part.text : mediaReferenceLine(part, "uploaded", readable))
|
|
307
310
|
.join(" ")
|
|
308
311
|
: (event.text ?? "")}`;
|
|
309
312
|
if (event.kind === "approve")
|
|
@@ -329,7 +332,7 @@ function entryText(entry, clip) {
|
|
|
329
332
|
.map((result) => result.kind === "completed"
|
|
330
333
|
? [
|
|
331
334
|
`[Tool ${result.toolName} result]: ${clipped(result.output, clip)}`,
|
|
332
|
-
...(result.files ?? []).map((file) => mediaReferenceLine(file, { tool: result.toolName })),
|
|
335
|
+
...(result.files ?? []).map((file) => mediaReferenceLine(file, { tool: result.toolName }, readable)),
|
|
333
336
|
].join("\n")
|
|
334
337
|
: result.kind === "denied"
|
|
335
338
|
? `[Tool ${result.toolName} denied]: ${result.reason ?? ""}`
|
|
@@ -8,6 +8,8 @@ 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` (ADR-100), when it is not the parent's. */
|
|
12
|
+
readonly artifactReads?: boolean;
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* Run a flow agent used as a tool: the host starts it in its own linked session and
|
package/dist/loop/delegation.js
CHANGED
|
@@ -52,9 +52,16 @@ export async function runDelegation(invocation, execute, call, delegate) {
|
|
|
52
52
|
input: task,
|
|
53
53
|
onModelCall: child.onModelCall,
|
|
54
54
|
signal,
|
|
55
|
-
// A child calls the same model, and reads its files as the parent does
|
|
55
|
+
// A child calls the same model, and reads its files as the parent does, with
|
|
56
|
+
// `read_artifact` as it declares (ADR-100).
|
|
56
57
|
...(options.model === undefined ? {} : { model: options.model }),
|
|
57
|
-
...(options.files === undefined
|
|
58
|
+
...(options.files === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: {
|
|
61
|
+
files: child.artifactReads === undefined
|
|
62
|
+
? options.files
|
|
63
|
+
: { ...options.files, artifactReads: child.artifactReads },
|
|
64
|
+
}),
|
|
58
65
|
...(options.info === undefined ? {} : { info: options.info }),
|
|
59
66
|
state: initializeExecutionState(child.definition, {
|
|
60
67
|
executionId: `${invocation.state.executionId}/${call.invocationId}`,
|
|
@@ -27,6 +27,11 @@ export type FileView =
|
|
|
27
27
|
};
|
|
28
28
|
/** What `fileView` decides from: the turn's model and the Runtime limits. */
|
|
29
29
|
export interface FileViewContext {
|
|
30
|
+
/**
|
|
31
|
+
* False when the agent has no `read_artifact` (ADR-100, an `agent-folder/2` agent without
|
|
32
|
+
* `engine.artifacts.read`): its files' reference lines do not offer it. Default true.
|
|
33
|
+
*/
|
|
34
|
+
readonly artifactReads?: boolean;
|
|
30
35
|
/** `turn.start.model`; undefined when the Runtime sent none. */
|
|
31
36
|
readonly model?: ModelDescriptor;
|
|
32
37
|
readonly limits: Pick<RuntimeLimits, "modelFileBytes">;
|
|
@@ -55,11 +60,12 @@ export declare function fileNote(name: string, type: string, why: string): strin
|
|
|
55
60
|
/**
|
|
56
61
|
* The line a file stands for in a prompt (protocol 12): its name, artifact id and version, and
|
|
57
62
|
* how the model reads it again. A file a tool returned names the tool. Every file is its line
|
|
58
|
-
* once its turn is over; in its own turn the line labels what follows it.
|
|
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` (ADR-100): the line names the file only.
|
|
59
65
|
*/
|
|
60
66
|
export declare function mediaReferenceLine(part: FilePart, origin: "uploaded" | {
|
|
61
67
|
readonly tool: string;
|
|
62
|
-
}): string;
|
|
68
|
+
}, readable?: boolean): string;
|
|
63
69
|
/** A file of the turn in progress: its key (artifact and version), reference line and part. */
|
|
64
70
|
export interface LiveFile {
|
|
65
71
|
readonly key: string;
|
package/dist/loop/model/files.js
CHANGED
|
@@ -53,15 +53,17 @@ export function fileNote(name, type, why) {
|
|
|
53
53
|
/**
|
|
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
|
-
* once its turn is over; in its own turn the line labels what follows it.
|
|
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` (ADR-100): the line names the file only.
|
|
57
58
|
*/
|
|
58
|
-
export function mediaReferenceLine(part, origin) {
|
|
59
|
+
export function mediaReferenceLine(part, origin, readable = true) {
|
|
59
60
|
const reference = mediaReferenceOf(part.reference);
|
|
60
61
|
const what = origin === "uploaded" ? "Uploaded artifact" : `Tool ${origin.tool} returned artifact`;
|
|
61
62
|
if (!reference)
|
|
62
63
|
return `[${what} (${part.mediaType})]`;
|
|
63
64
|
const name = JSON.stringify(reference.name ?? reference.artifactId);
|
|
64
|
-
|
|
65
|
+
// An agent without `read_artifact` (ADR-100) is not offered it.
|
|
66
|
+
return `[${what} ${name} · ${reference.artifactId} v${reference.version}${readable ? " · read_artifact to view" : ""}]`;
|
|
65
67
|
}
|
|
66
68
|
/** The key a file goes by in one call: its artifact version, or its reference. */
|
|
67
69
|
export function fileKeyOf(part) {
|
|
@@ -6,13 +6,14 @@ import { type LiveFile } from "./files.js";
|
|
|
6
6
|
* messages, tool results and `read_artifact` loads) also go once, after the conversation and
|
|
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
|
-
* part. Their content reaches the model only in their own turn.
|
|
9
|
+
* part. Their content reaches the model only in their own turn. `readable` false for an agent
|
|
10
|
+
* without `read_artifact` (ADR-100): no reference line offers it.
|
|
10
11
|
*/
|
|
11
|
-
export declare function projectModelCall(request: ModelRequest, files?: ReadonlyMap<string, readonly PromptContentPart[]
|
|
12
|
+
export declare function projectModelCall(request: ModelRequest, files?: ReadonlyMap<string, readonly PromptContentPart[]>, readable?: boolean): ModelCall;
|
|
12
13
|
/**
|
|
13
14
|
* The files of the turn in progress, in the order the prompt names them, once each: a user
|
|
14
15
|
* message's media parts and the files its tool results returned.
|
|
15
16
|
*/
|
|
16
|
-
export declare function liveFilesOf(request: ModelRequest): LiveFile[];
|
|
17
|
-
/** What a turn with an output schema asks of the model's final answer. */
|
|
17
|
+
export declare function liveFilesOf(request: ModelRequest, readable?: boolean): LiveFile[];
|
|
18
|
+
/** What a turn with an output schema asks of the model's final answer (`@nylorun/core/engine`). */
|
|
18
19
|
export declare function schemaInstruction(schema: NonNullable<ModelRequest["outputSchema"]>): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { copyJson, freezeGraph } from "@nylorun/core/define";
|
|
2
|
+
import { outputSchemaInstruction } from "@nylorun/core/engine";
|
|
2
3
|
import { summaryPrompt } from "../compaction/index.js";
|
|
3
4
|
import { FILES_MESSAGE_HEADER, fileKeyOf, mediaReferenceLine, } from "./files.js";
|
|
4
5
|
/**
|
|
@@ -7,16 +8,17 @@ import { FILES_MESSAGE_HEADER, fileKeyOf, mediaReferenceLine, } from "./files.js
|
|
|
7
8
|
* messages, tool results and `read_artifact` loads) also go once, after the conversation and
|
|
8
9
|
* the context, in one user message: each file's line, then what `files` (`representFiles`)
|
|
9
10
|
* made of it, a media part, a `<file>` block or a note. Without `files`, each goes as its media
|
|
10
|
-
* part. Their content reaches the model only in their own turn.
|
|
11
|
+
* part. Their content reaches the model only in their own turn. `readable` false for an agent
|
|
12
|
+
* without `read_artifact` (ADR-100): no reference line offers it.
|
|
11
13
|
*/
|
|
12
|
-
export function projectModelCall(request, files) {
|
|
14
|
+
export function projectModelCall(request, files, readable = true) {
|
|
13
15
|
return freezeGraph({
|
|
14
16
|
prompt: Object.freeze([
|
|
15
17
|
...projectInstructions(request.instructions, request.outputSchema),
|
|
16
18
|
...(request.pinned ?? []).map((text) => freezeItem({ kind: "context", role: "user", content: [textPart(text)] })),
|
|
17
|
-
...request.transcript.flatMap((entry) => projectEntry(entry, request.turnId)),
|
|
19
|
+
...request.transcript.flatMap((entry) => projectEntry(entry, request.turnId, readable)),
|
|
18
20
|
...projectContext(request.context),
|
|
19
|
-
...projectFiles(liveFilesOf(request), files),
|
|
21
|
+
...projectFiles(liveFilesOf(request, readable), files),
|
|
20
22
|
]),
|
|
21
23
|
tools: Object.freeze(request.configuration.tools.map((tool) => Object.freeze({
|
|
22
24
|
name: tool.name,
|
|
@@ -31,7 +33,7 @@ export function projectModelCall(request, files) {
|
|
|
31
33
|
* The files of the turn in progress, in the order the prompt names them, once each: a user
|
|
32
34
|
* message's media parts and the files its tool results returned.
|
|
33
35
|
*/
|
|
34
|
-
export function liveFilesOf(request) {
|
|
36
|
+
export function liveFilesOf(request, readable = true) {
|
|
35
37
|
const live = new Map();
|
|
36
38
|
const add = (line, part) => {
|
|
37
39
|
const key = fileKeyOf(part);
|
|
@@ -47,13 +49,13 @@ export function liveFilesOf(request) {
|
|
|
47
49
|
continue;
|
|
48
50
|
for (const part of event.content ?? [])
|
|
49
51
|
if (part.type === "media")
|
|
50
|
-
add(mediaReferenceLine(part, "uploaded"), part);
|
|
52
|
+
add(mediaReferenceLine(part, "uploaded", readable), part);
|
|
51
53
|
}
|
|
52
54
|
else if (entry.kind === "tool-results")
|
|
53
55
|
for (const result of entry.results)
|
|
54
56
|
if (result.kind === "completed")
|
|
55
57
|
for (const file of result.files ?? [])
|
|
56
|
-
add(mediaReferenceLine(file, { tool: result.toolName }), file);
|
|
58
|
+
add(mediaReferenceLine(file, { tool: result.toolName }, readable), file);
|
|
57
59
|
}
|
|
58
60
|
return [...live.values()];
|
|
59
61
|
}
|
|
@@ -70,9 +72,9 @@ function projectInstructions(instructions, outputSchema) {
|
|
|
70
72
|
return [];
|
|
71
73
|
return [freezeItem({ kind: "instructions", role: "system", content: [textPart(text)] })];
|
|
72
74
|
}
|
|
73
|
-
/** What a turn with an output schema asks of the model's final answer. */
|
|
75
|
+
/** What a turn with an output schema asks of the model's final answer (`@nylorun/core/engine`). */
|
|
74
76
|
export function schemaInstruction(schema) {
|
|
75
|
-
return
|
|
77
|
+
return outputSchemaInstruction(schema);
|
|
76
78
|
}
|
|
77
79
|
function projectContext(context) {
|
|
78
80
|
if (context.items.length === 0)
|
|
@@ -118,7 +120,7 @@ function projectFiles(files, represented) {
|
|
|
118
120
|
}),
|
|
119
121
|
];
|
|
120
122
|
}
|
|
121
|
-
function projectEntry(entry, turnId) {
|
|
123
|
+
function projectEntry(entry, turnId, readable) {
|
|
122
124
|
if (entry.kind === "input") {
|
|
123
125
|
if (entry.event.kind !== "user-message" && entry.event.kind !== "interrupt")
|
|
124
126
|
return [];
|
|
@@ -130,7 +132,7 @@ function projectEntry(entry, turnId) {
|
|
|
130
132
|
? entry.event.content.map((part) => {
|
|
131
133
|
if (part.type === "text")
|
|
132
134
|
return textPart(part.text);
|
|
133
|
-
return textPart(mediaReferenceLine(part, "uploaded"));
|
|
135
|
+
return textPart(mediaReferenceLine(part, "uploaded", readable));
|
|
134
136
|
})
|
|
135
137
|
: [textPart(entry.event.text)],
|
|
136
138
|
}),
|
|
@@ -174,14 +176,14 @@ function projectEntry(entry, turnId) {
|
|
|
174
176
|
];
|
|
175
177
|
}
|
|
176
178
|
if (entry.kind === "tool-results")
|
|
177
|
-
return entry.results.map(projectToolResult);
|
|
179
|
+
return entry.results.map((result) => projectToolResult(result, readable));
|
|
178
180
|
if (entry.kind === "compaction")
|
|
179
181
|
return [
|
|
180
182
|
freezeItem({ kind: "message", role: "user", content: [textPart(summaryPrompt(entry))] }),
|
|
181
183
|
];
|
|
182
184
|
return [];
|
|
183
185
|
}
|
|
184
|
-
function projectToolResult(result) {
|
|
186
|
+
function projectToolResult(result, readable) {
|
|
185
187
|
return freezeItem({
|
|
186
188
|
kind: "tool-result",
|
|
187
189
|
toolCallId: result.callId,
|
|
@@ -192,7 +194,7 @@ function projectToolResult(result) {
|
|
|
192
194
|
// Files the tool returned, stored by the host (R2b C11): each is its reference line, and
|
|
193
195
|
// goes to the model in its own turn with the turn's files.
|
|
194
196
|
...(result.kind === "completed" && result.files
|
|
195
|
-
? result.files.map((file) => textPart(mediaReferenceLine(file, { tool: result.toolName })))
|
|
197
|
+
? result.files.map((file) => textPart(mediaReferenceLine(file, { tool: result.toolName }, readable)))
|
|
196
198
|
: []),
|
|
197
199
|
],
|
|
198
200
|
});
|
package/dist/loop/step/run.js
CHANGED
|
@@ -65,8 +65,9 @@ export async function runStep(input) {
|
|
|
65
65
|
requestedModelId = request.model?.id;
|
|
66
66
|
// How each file of the turn reaches the model is ours to decide (protocol 15): text is read
|
|
67
67
|
// and inlined here, the rest goes as its reference or a note.
|
|
68
|
-
const
|
|
69
|
-
const
|
|
68
|
+
const readable = input.agent.files?.artifactReads !== false;
|
|
69
|
+
const files = await representFiles(liveFilesOf(request, readable), input.agent.files, input.signal);
|
|
70
|
+
const call = projectModelCall(request, files, readable);
|
|
70
71
|
const invocationId = createId("invocation");
|
|
71
72
|
modelInvocationId = invocationId;
|
|
72
73
|
input.observe(() => ({
|
package/dist/run/durable.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type EffectTarget, type ModelDescriptor } from "@nylorun/core/harness-api";
|
|
2
|
+
import { type EngineTool } from "@nylorun/core/engine";
|
|
2
3
|
import type { FileContext } from "../loop/model/files.js";
|
|
3
4
|
import type { AgentManifest } from "@nylorun/core/define";
|
|
4
5
|
import type { ExecutionInput, ExecutionState, RunResult } from "../types/execution.js";
|
|
@@ -89,25 +90,9 @@ export type DurableResult = {
|
|
|
89
90
|
};
|
|
90
91
|
/**
|
|
91
92
|
* A tool our engine adds to an agent for this execution (an MCP tool of the session, one of our
|
|
92
|
-
* engine's own)
|
|
93
|
+
* engine's own): `@nylorun/core/engine`'s `EngineTool`. It is not part of the hashed manifest.
|
|
93
94
|
*/
|
|
94
|
-
export
|
|
95
|
-
/** The agent used as a tool that owns this tool; absent for the root agent. */
|
|
96
|
-
readonly agentId?: string;
|
|
97
|
-
readonly name: string;
|
|
98
|
-
readonly description?: string;
|
|
99
|
-
readonly inputSchema: JsonObject;
|
|
100
|
-
readonly outputSchema?: JsonObject;
|
|
101
|
-
/**
|
|
102
|
-
* Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
|
|
103
|
-
* with `tool_call`, which makes the call as this tool's own.
|
|
104
|
-
*/
|
|
105
|
-
readonly deferred?: boolean;
|
|
106
|
-
/** Text the model reads, after the engine's, while this tool is advertised. */
|
|
107
|
-
readonly instructions?: readonly string[];
|
|
108
|
-
/** What runs its calls: their effects' `target` (an MCP tool's identity, our engine's `harness`). */
|
|
109
|
-
readonly target?: EffectTarget;
|
|
110
|
-
}
|
|
95
|
+
export type DurableSessionTool = EngineTool;
|
|
111
96
|
export declare function createDurableCheckpoint(input: {
|
|
112
97
|
manifest: AgentManifest;
|
|
113
98
|
sessionId: string;
|
|
@@ -146,6 +131,11 @@ export declare function runDurable(options: {
|
|
|
146
131
|
* hashed.
|
|
147
132
|
*/
|
|
148
133
|
pinned?: readonly string[];
|
|
134
|
+
/**
|
|
135
|
+
* Pin `pinned` in place of what the state pinned before: at a turn's first segment, when the
|
|
136
|
+
* Agent's memory changed elsewhere since (`turn.start.memory.refresh`).
|
|
137
|
+
*/
|
|
138
|
+
refreshPinned?: boolean;
|
|
149
139
|
/** Segment rollover (Model Calls §10): yield after this many steps or milliseconds. */
|
|
150
140
|
yieldAfter?: {
|
|
151
141
|
readonly steps?: number;
|
package/dist/run/durable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HarnessError } from "@nylorun/core/define";
|
|
2
2
|
import { effectIdOf } from "@nylorun/core/harness-api";
|
|
3
|
+
import { engineFeaturesOf } from "@nylorun/core/engine";
|
|
3
4
|
import { AgentManifestSchema, checkMemoryCall } from "@nylorun/core/contracts";
|
|
4
5
|
import { agentFrom, withHttpTarget } from "@nylorun/core/define";
|
|
5
6
|
import { TOOL_CALL_TOOL } from "../tools/tool-search.js";
|
|
@@ -184,6 +185,9 @@ export async function runDurable(options) {
|
|
|
184
185
|
child: (delegate, ref) => ({
|
|
185
186
|
definition: hostedDefinition(delegate.manifest, ref),
|
|
186
187
|
onModelCall: modelCall(ref),
|
|
188
|
+
artifactReads: engineFeaturesOf(delegate.manifest.engine, {
|
|
189
|
+
computer: false,
|
|
190
|
+
}).artifactsRead,
|
|
187
191
|
}),
|
|
188
192
|
// A flow agent used as a tool runs in its own linked session, like a flow's agent
|
|
189
193
|
// step: the host starts it, and the effect settles when its turn ends.
|
|
@@ -204,7 +208,7 @@ export async function runDurable(options) {
|
|
|
204
208
|
try {
|
|
205
209
|
const result = await withDeterministicIds(`${checkpoint.turnId}_${checkpoint.segment}`, () => execute(hosted, {
|
|
206
210
|
state: withPinned(withLayout(checkpoint.state ??
|
|
207
|
-
initializeExecutionState(hosted, { executionId: checkpoint.sessionId }), options.mcp), options.pinned),
|
|
211
|
+
initializeExecutionState(hosted, { executionId: checkpoint.sessionId }), options.mcp), options.pinned, options.refreshPinned === true),
|
|
208
212
|
input: checkpoint.input,
|
|
209
213
|
info: checkpoint.info,
|
|
210
214
|
signal: options.signal,
|
|
@@ -244,16 +248,17 @@ function withLayout(state, mcp) {
|
|
|
244
248
|
}
|
|
245
249
|
/**
|
|
246
250
|
* The state with the text our engine keeps at the head of the conversation: what it pinned
|
|
247
|
-
* before, or `pinned` when it has none (the session's first turn, or after a compaction)
|
|
251
|
+
* before, or `pinned` when it has none (the session's first turn, or after a compaction) or
|
|
252
|
+
* `refresh` asks for it again.
|
|
248
253
|
*/
|
|
249
|
-
function withPinned(state, pinned) {
|
|
254
|
+
function withPinned(state, pinned, refresh = false) {
|
|
250
255
|
if (pinned === undefined) {
|
|
251
256
|
if (state.pinned === undefined)
|
|
252
257
|
return state;
|
|
253
258
|
const { pinned: _dropped, ...rest } = state;
|
|
254
259
|
return rest;
|
|
255
260
|
}
|
|
256
|
-
return state.pinned === undefined ? { ...state, pinned: [...pinned] } : state;
|
|
261
|
+
return state.pinned === undefined || refresh ? { ...state, pinned: [...pinned] } : state;
|
|
257
262
|
}
|
|
258
263
|
/**
|
|
259
264
|
* `memory` (track T5): each command's parameters are checked before the call is sent
|
|
@@ -9,11 +9,13 @@ export interface ArtifactToolOptions {
|
|
|
9
9
|
/** True when `name` is one of our engine's artifact tools. */
|
|
10
10
|
export declare function isArtifactTool(name: string | undefined): boolean;
|
|
11
11
|
/**
|
|
12
|
-
* The artifact tools our engine offers an agent
|
|
13
|
-
* and `read_artifact`, which takes `path` only
|
|
12
|
+
* The artifact tools our engine offers an agent that declares nothing (`agent-folder/1`):
|
|
13
|
+
* `save_artifact` when the session has a sandbox, and `read_artifact`, which takes `path` only
|
|
14
|
+
* then. Each runs here (`harness`). One that declares its engine features gets those it names
|
|
15
|
+
* (`engineProjection`).
|
|
14
16
|
*/
|
|
15
17
|
export declare function artifactToolsFor(sandboxed: boolean, options: ArtifactToolOptions): DurableSessionTool[];
|
|
16
|
-
/** What the model reads with the artifact tools, in their order. */
|
|
18
|
+
/** What the model reads with the artifact tools, in their order, for an agent that declares nothing. */
|
|
17
19
|
export declare function artifactInstructions(sandboxed: boolean): string[];
|
|
18
20
|
/** What an artifact tool runs with. */
|
|
19
21
|
export interface ArtifactToolContext extends ArtifactToolOptions {
|