@nylorun/harness 0.27.1-beta → 0.29.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 +131 -0
- package/HOST_CONTRACT.md +15 -13
- package/README.md +3 -1
- package/dist/api/executors.d.ts +79 -11
- package/dist/api/harness.d.ts +83 -2
- package/dist/api/harness.js +43 -4
- package/dist/api/host.d.ts +30 -2
- package/dist/api/host.js +156 -8
- package/dist/api/index.d.ts +21 -6
- package/dist/api/index.js +19 -4
- package/dist/api/run.d.ts +3 -0
- package/dist/api/run.js +91 -16
- package/dist/flow/context.d.ts +3 -0
- package/dist/flow/context.js +2 -1
- package/dist/flow/engine.d.ts +2 -0
- package/dist/flow/engine.js +10 -7
- package/dist/flow/limits.d.ts +8 -5
- package/dist/flow/limits.js +11 -7
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/loop/compaction/config.d.ts +39 -0
- package/dist/loop/compaction/config.js +29 -0
- package/dist/loop/compaction/index.d.ts +18 -8
- package/dist/loop/compaction/index.js +57 -66
- package/dist/loop/config.d.ts +20 -0
- package/dist/loop/config.js +17 -0
- package/dist/loop/delegation.d.ts +3 -0
- package/dist/loop/delegation.js +14 -10
- package/dist/loop/invocation.d.ts +3 -0
- package/dist/loop/invocation.js +2 -0
- package/dist/loop/model/files.d.ts +77 -0
- package/dist/loop/model/files.js +168 -0
- package/dist/loop/model/json-answer.d.ts +26 -0
- package/dist/loop/model/json-answer.js +125 -0
- package/dist/loop/model/project.d.ts +14 -4
- package/dist/loop/model/project.js +70 -41
- package/dist/loop/options.js +11 -3
- package/dist/loop/run.js +15 -5
- package/dist/loop/state.d.ts +6 -1
- package/dist/loop/state.js +19 -0
- package/dist/loop/step/canonicalize.d.ts +11 -2
- package/dist/loop/step/canonicalize.js +21 -5
- package/dist/loop/step/resolve.js +1 -0
- package/dist/loop/step/run.js +20 -3
- package/dist/loop/step/runtime.d.ts +6 -0
- package/dist/loop/step/seal.js +8 -2
- package/dist/loop/step/step-context.js +1 -1
- package/dist/run/durable.d.ts +58 -3
- package/dist/run/durable.js +104 -33
- package/dist/tools/artifacts.d.ts +33 -0
- package/dist/tools/artifacts.js +323 -0
- package/dist/tools/engine-tools.d.ts +50 -0
- package/dist/tools/engine-tools.js +42 -0
- package/dist/tools/mcp.d.ts +92 -0
- package/dist/tools/mcp.js +240 -0
- package/dist/tools/memory.d.ts +16 -0
- package/dist/tools/memory.js +140 -0
- package/dist/tools/outputs.d.ts +23 -0
- package/dist/tools/outputs.js +193 -0
- package/dist/tools/results.d.ts +108 -0
- package/dist/tools/results.js +329 -0
- package/dist/tools/sandbox.d.ts +35 -0
- package/dist/tools/sandbox.js +129 -0
- package/dist/tools/skills.d.ts +94 -0
- package/dist/tools/skills.js +243 -0
- package/dist/tools/text-page.d.ts +20 -0
- package/dist/tools/text-page.js +64 -0
- package/dist/tools/tool-search.d.ts +56 -0
- package/dist/tools/tool-search.js +174 -0
- package/dist/tools/trace.d.ts +13 -0
- package/dist/tools/trace.js +34 -0
- package/dist/tools/wake.d.ts +13 -0
- package/dist/tools/wake.js +33 -0
- package/dist/types/execution.d.ts +35 -1
- package/package.json +7 -7
package/dist/loop/options.js
CHANGED
|
@@ -11,6 +11,8 @@ const acceptedOptions = new Set([
|
|
|
11
11
|
"signal",
|
|
12
12
|
"onEvent",
|
|
13
13
|
"record",
|
|
14
|
+
"model",
|
|
15
|
+
"files",
|
|
14
16
|
]);
|
|
15
17
|
export function validateRunOptions(options) {
|
|
16
18
|
if (!options || typeof options.onModelCall !== "function")
|
|
@@ -28,13 +30,19 @@ export function validateRunOptions(options) {
|
|
|
28
30
|
throw new HarnessError("execution.invalid-input", "signal must be an AbortSignal");
|
|
29
31
|
}
|
|
30
32
|
export function openExecution(agent, options) {
|
|
31
|
-
|
|
33
|
+
let state = options.state === undefined
|
|
32
34
|
? initializeExecutionState(agent)
|
|
33
35
|
: validateExecutionState(options.state);
|
|
34
36
|
if (state.agentId !== agent.id)
|
|
35
37
|
throw new HarnessError("execution.incompatible", "Saved state requires the original compatible agent and outputSchema");
|
|
36
|
-
if (canonical(state.outputContract) !== canonical(agent.output?.schema.jsonSchema))
|
|
37
|
-
|
|
38
|
+
if (canonical(state.outputContract) !== canonical(agent.output?.schema.jsonSchema)) {
|
|
39
|
+
// Between turns, a new version of the agent (track T3) may change its output schema: the next
|
|
40
|
+
// turn takes it. A turn in progress keeps the schema it started with.
|
|
41
|
+
if (state.status === "active" || state.plan !== undefined)
|
|
42
|
+
throw new HarnessError("execution.incompatible", "Saved state requires the original compatible agent and outputSchema");
|
|
43
|
+
const { outputContract: _previous, ...rest } = state;
|
|
44
|
+
state = agent.output ? { ...rest, outputContract: agent.output.schema.jsonSchema } : rest;
|
|
45
|
+
}
|
|
38
46
|
if (state.manifestHash) {
|
|
39
47
|
const compatibility = checkCompatibility(agent.manifest, state);
|
|
40
48
|
if (!compatibility.ok)
|
package/dist/loop/run.js
CHANGED
|
@@ -29,6 +29,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
const invocation = createInvocation({ agent, options, state, definitions, internals });
|
|
31
31
|
const { signal, observe, record } = invocation;
|
|
32
|
+
const compaction = invocation.loop.compaction;
|
|
32
33
|
const finish = (result) => finishInvocation(invocation, result);
|
|
33
34
|
try {
|
|
34
35
|
signal.throwIfAborted();
|
|
@@ -47,13 +48,17 @@ export async function execute(agent, options, internals = {}) {
|
|
|
47
48
|
turnId,
|
|
48
49
|
stepId,
|
|
49
50
|
trigger,
|
|
50
|
-
budget: contextBudget(invocation.state.transcript),
|
|
51
|
+
budget: contextBudget(invocation.state.transcript, options.model, compaction),
|
|
52
|
+
...(options.files === undefined ? {} : { files: options.files }),
|
|
51
53
|
invoke: options.onModelCall,
|
|
52
54
|
signal,
|
|
55
|
+
config: compaction,
|
|
53
56
|
});
|
|
54
57
|
if (!next)
|
|
55
58
|
return false;
|
|
56
|
-
|
|
59
|
+
// The pinned text is re-pinned fresh by the next segment (the memory index, track T5).
|
|
60
|
+
const { pinned: _pinned, ...state } = invocation.state;
|
|
61
|
+
invocation.state = { ...state, transcript: next };
|
|
57
62
|
await record();
|
|
58
63
|
return true;
|
|
59
64
|
};
|
|
@@ -81,7 +86,9 @@ export async function execute(agent, options, internals = {}) {
|
|
|
81
86
|
else {
|
|
82
87
|
turnId = createId("turn");
|
|
83
88
|
stepNumber = 1;
|
|
84
|
-
if (input.kind
|
|
89
|
+
if (input.kind === "messages")
|
|
90
|
+
arrivals = input.events;
|
|
91
|
+
else if (input.kind !== "continue" && input.kind !== "settle")
|
|
85
92
|
arrivals = [input];
|
|
86
93
|
invocation.state = {
|
|
87
94
|
...invocation.state,
|
|
@@ -110,9 +117,10 @@ export async function execute(agent, options, internals = {}) {
|
|
|
110
117
|
stepsRun++;
|
|
111
118
|
const stepId = createId("step");
|
|
112
119
|
// Keep the next prompt inside the model's window, before it is sent.
|
|
113
|
-
const budget = contextBudget(invocation.state.transcript);
|
|
120
|
+
const budget = contextBudget(invocation.state.transcript, options.model, compaction);
|
|
114
121
|
if (budget &&
|
|
115
|
-
estimateTokens(invocation.state.transcript, turnId
|
|
122
|
+
estimateTokens(invocation.state.transcript, turnId, options.files, compaction) >
|
|
123
|
+
budget.contextWindow - budget.reserve)
|
|
116
124
|
await compactHistory("threshold", stepId);
|
|
117
125
|
const snapshot = {
|
|
118
126
|
id: invocation.state.executionId,
|
|
@@ -120,12 +128,14 @@ export async function execute(agent, options, internals = {}) {
|
|
|
120
128
|
revision: invocation.state.revision,
|
|
121
129
|
turnCount: invocation.state.turnCount,
|
|
122
130
|
transcript: invocation.state.transcript,
|
|
131
|
+
...(invocation.state.pinned ? { pinned: invocation.state.pinned } : {}),
|
|
123
132
|
};
|
|
124
133
|
const result = await runStep({
|
|
125
134
|
agent: {
|
|
126
135
|
parts: agent.parts,
|
|
127
136
|
invoke: options.onModelCall,
|
|
128
137
|
registry: agent.registry,
|
|
138
|
+
...(options.files === undefined ? {} : { files: options.files }),
|
|
129
139
|
sessionState: invocation.sessionBag,
|
|
130
140
|
},
|
|
131
141
|
state: snapshot,
|
package/dist/loop/state.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { ExecutionInput, ExecutionState } from "../types/execution.js";
|
|
|
3
3
|
import type { InputEvent } from "@nylorun/core/define";
|
|
4
4
|
export declare function createExecutionState<Info, Output>(agent: BuiltAgent<Info, Output>): ExecutionState;
|
|
5
5
|
export declare function validateExecutionState(value: unknown): ExecutionState;
|
|
6
|
-
|
|
6
|
+
/** Queued messages (protocol 17), each its own user message of the turn they start. */
|
|
7
|
+
export interface MessagesInput {
|
|
8
|
+
readonly kind: "messages";
|
|
9
|
+
readonly events: readonly InputEvent[];
|
|
10
|
+
}
|
|
11
|
+
export declare function normalizeInput(value: ExecutionInput): InputEvent | MessagesInput | Extract<ExecutionInput, {
|
|
7
12
|
kind: "continue" | "settle";
|
|
8
13
|
}>;
|
package/dist/loop/state.js
CHANGED
|
@@ -103,6 +103,11 @@ const schema = z
|
|
|
103
103
|
status: z.enum(["ready", "active", "completed", "paused", "cancelled", "failed"]),
|
|
104
104
|
cancelledCalls: z.array(call).optional(),
|
|
105
105
|
state: z.record(z.string(), json).optional(),
|
|
106
|
+
mcpLayout: z
|
|
107
|
+
.object({ factsHash: z.string(), deferred: z.array(z.string()) })
|
|
108
|
+
.strict()
|
|
109
|
+
.optional(),
|
|
110
|
+
pinned: z.array(z.string()).optional(),
|
|
106
111
|
turn: z.object({ turnId: id }).strict().optional(),
|
|
107
112
|
plan: z
|
|
108
113
|
.object({
|
|
@@ -205,6 +210,20 @@ export function normalizeInput(value) {
|
|
|
205
210
|
if (typeof value === "string")
|
|
206
211
|
return { kind: "user-message", text: value };
|
|
207
212
|
assertJson(value);
|
|
213
|
+
if ("kind" in value && value.kind === "messages") {
|
|
214
|
+
const messages = value.messages;
|
|
215
|
+
if (!Array.isArray(messages) || messages.length === 0)
|
|
216
|
+
throw new HarnessError("execution.invalid-input", "messages must list at least one message");
|
|
217
|
+
return {
|
|
218
|
+
kind: "messages",
|
|
219
|
+
events: messages.map((message) => {
|
|
220
|
+
const event = normalizeInput(message);
|
|
221
|
+
if (event.kind !== "user-message")
|
|
222
|
+
throw new HarnessError("execution.invalid-input", "each of messages must be a user message");
|
|
223
|
+
return event;
|
|
224
|
+
}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
208
227
|
if ("kind" in value && value.kind === "continue")
|
|
209
228
|
return z
|
|
210
229
|
.object({ kind: z.literal("continue") })
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { ModelCandidate, ModelOutputBlock } from "@nylorun/core/define";
|
|
2
2
|
import type { JsonObject } from "@nylorun/core/define";
|
|
3
|
+
/**
|
|
4
|
+
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory` (track
|
|
5
|
+
* T5, E-P1): the `memory` tool with that command, as the conversation records it from then on.
|
|
6
|
+
* A call whose own `command` disagrees with its name stays as it was, and fails as unknown.
|
|
7
|
+
*/
|
|
8
|
+
export declare function memoryAliasCall(name: string, args: JsonObject, offered: ReadonlySet<string>): {
|
|
9
|
+
name: string;
|
|
10
|
+
args: JsonObject;
|
|
11
|
+
} | undefined;
|
|
3
12
|
export interface CanonicalCall {
|
|
4
13
|
readonly id: string;
|
|
5
14
|
readonly name: string;
|
|
@@ -11,8 +20,8 @@ export declare function canonicalizeCalls(calls: readonly {
|
|
|
11
20
|
readonly id?: string;
|
|
12
21
|
readonly name?: string;
|
|
13
22
|
readonly args: JsonObject;
|
|
14
|
-
}[]): readonly CanonicalCall[];
|
|
15
|
-
export declare function canonicalizeOutput(output: readonly ModelOutputBlock[]): {
|
|
23
|
+
}[], offered?: ReadonlySet<string>): readonly CanonicalCall[];
|
|
24
|
+
export declare function canonicalizeOutput(output: readonly ModelOutputBlock[], offered?: ReadonlySet<string>): {
|
|
16
25
|
readonly output: readonly ModelOutputBlock[];
|
|
17
26
|
readonly calls: readonly CanonicalCall[];
|
|
18
27
|
};
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { createId } from "../../utils/ids.js";
|
|
2
2
|
import { copyJson } from "@nylorun/core/define";
|
|
3
|
-
|
|
3
|
+
import { memoryAliasOf } from "@nylorun/core/contracts";
|
|
4
|
+
/**
|
|
5
|
+
* A call to `memory.<command>` or `memory/<command>` when the model was offered `memory` (track
|
|
6
|
+
* T5, E-P1): the `memory` tool with that command, as the conversation records it from then on.
|
|
7
|
+
* A call whose own `command` disagrees with its name stays as it was, and fails as unknown.
|
|
8
|
+
*/
|
|
9
|
+
export function memoryAliasCall(name, args, offered) {
|
|
10
|
+
if (offered.has(name) || !offered.has("memory"))
|
|
11
|
+
return undefined;
|
|
12
|
+
const command = memoryAliasOf(name);
|
|
13
|
+
if (!command || (args.command !== undefined && args.command !== command))
|
|
14
|
+
return undefined;
|
|
15
|
+
return { name: "memory", args: { command, ...args } };
|
|
16
|
+
}
|
|
17
|
+
export function canonicalizeCalls(calls, offered = new Set()) {
|
|
4
18
|
const idCounts = new Map();
|
|
5
19
|
for (const call of calls) {
|
|
6
20
|
if (typeof call.id === "string" && call.id)
|
|
@@ -9,17 +23,19 @@ export function canonicalizeCalls(calls) {
|
|
|
9
23
|
return Object.freeze(calls.map((call) => {
|
|
10
24
|
const hasId = typeof call.id === "string" && call.id.length > 0;
|
|
11
25
|
const duplicateId = hasId && (idCounts.get(call.id) ?? 0) > 1 ? call.id : undefined;
|
|
26
|
+
const name = typeof call.name === "string" && call.name ? call.name : "unknown";
|
|
27
|
+
const alias = memoryAliasCall(name, call.args, offered);
|
|
12
28
|
return Object.freeze({
|
|
13
29
|
id: hasId && !duplicateId ? call.id : createId("call"),
|
|
14
|
-
name:
|
|
15
|
-
args: call.args,
|
|
30
|
+
name: alias?.name ?? name,
|
|
31
|
+
args: alias?.args ?? call.args,
|
|
16
32
|
missingId: !hasId,
|
|
17
33
|
...(duplicateId ? { duplicateId } : {}),
|
|
18
34
|
});
|
|
19
35
|
}));
|
|
20
36
|
}
|
|
21
|
-
export function canonicalizeOutput(output) {
|
|
22
|
-
const calls = canonicalizeCalls(output.flatMap((block) => (block.type === "tool-call" ? [block] : [])));
|
|
37
|
+
export function canonicalizeOutput(output, offered) {
|
|
38
|
+
const calls = canonicalizeCalls(output.flatMap((block) => (block.type === "tool-call" ? [block] : [])), offered);
|
|
23
39
|
let index = 0;
|
|
24
40
|
return {
|
|
25
41
|
output: Object.freeze(output.map((block) => {
|
|
@@ -8,6 +8,7 @@ export function resolveModelRequest(input) {
|
|
|
8
8
|
stepId: ctx.input.stepId,
|
|
9
9
|
configuration,
|
|
10
10
|
instructions: Object.freeze([...ctx.instructions]),
|
|
11
|
+
...(ctx.input.pinned?.length ? { pinned: Object.freeze([...ctx.input.pinned]) } : {}),
|
|
11
12
|
context: ctx.contextSnapshot(),
|
|
12
13
|
transcript: Object.freeze([...ctx.input.transcript]),
|
|
13
14
|
arrivals: Object.freeze([...input.arrivals]),
|
package/dist/loop/step/run.js
CHANGED
|
@@ -3,7 +3,9 @@ import { normalizeCandidate } from "../model/normalize.js";
|
|
|
3
3
|
import { HarnessError, isHarnessError, isModelFailureOutcome } from "@nylorun/core/define";
|
|
4
4
|
import { copyJson } from "@nylorun/core/define";
|
|
5
5
|
import { StepContext } from "./step-context.js";
|
|
6
|
-
import { projectModelCall } from "../model/project.js";
|
|
6
|
+
import { liveFilesOf, projectModelCall } from "../model/project.js";
|
|
7
|
+
import { representFiles } from "../model/files.js";
|
|
8
|
+
import { structuredAnswer } from "../model/json-answer.js";
|
|
7
9
|
import { resolveModelRequest } from "./resolve.js";
|
|
8
10
|
import { sealStep } from "./seal.js";
|
|
9
11
|
import { ModelConfigurationDraft } from "./model-configuration.js";
|
|
@@ -21,6 +23,7 @@ export async function runStep(input) {
|
|
|
21
23
|
arrivals: Object.freeze([...input.arrivals]),
|
|
22
24
|
toolResults: Object.freeze([...input.toolResults]),
|
|
23
25
|
transcript: Object.freeze([...input.state.transcript]),
|
|
26
|
+
...(input.state.pinned ? { pinned: Object.freeze([...input.state.pinned]) } : {}),
|
|
24
27
|
});
|
|
25
28
|
const configuration = new ModelConfigurationDraft();
|
|
26
29
|
const context = new StepContext(stepInput, configuration);
|
|
@@ -60,7 +63,10 @@ export async function runStep(input) {
|
|
|
60
63
|
output: input.output,
|
|
61
64
|
});
|
|
62
65
|
requestedModelId = request.model?.id;
|
|
63
|
-
|
|
66
|
+
// How each file of the turn reaches the model is ours to decide (protocol 15): text is read
|
|
67
|
+
// and inlined here, the rest goes as its reference or a note.
|
|
68
|
+
const files = await representFiles(liveFilesOf(request), input.agent.files, input.signal);
|
|
69
|
+
const call = projectModelCall(request, files);
|
|
64
70
|
const invocationId = createId("invocation");
|
|
65
71
|
modelInvocationId = invocationId;
|
|
66
72
|
input.observe(() => ({
|
|
@@ -108,7 +114,18 @@ export async function runStep(input) {
|
|
|
108
114
|
...(outcome.retryAfterMs === undefined ? {} : { retryAfterMs: outcome.retryAfterMs }),
|
|
109
115
|
},
|
|
110
116
|
});
|
|
111
|
-
|
|
117
|
+
// With an output schema, the final answer's text is read as JSON here (protocol 15). An
|
|
118
|
+
// answer that is not JSON stays in the transcript, as evidence, and fails the step.
|
|
119
|
+
const candidate = normalizeCandidate(outcome);
|
|
120
|
+
let answer;
|
|
121
|
+
try {
|
|
122
|
+
answer = structuredAnswer(candidate, request.outputSchema);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
context.mintFromModel(candidate);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
context.mintFromModel(answer);
|
|
112
129
|
if (!context.currentCandidate)
|
|
113
130
|
throw new HarnessError("model.candidate-missing", "Model candidate missing after mint");
|
|
114
131
|
}
|
|
@@ -4,11 +4,14 @@ import type { InputEvent, TranscriptEntry } from "@nylorun/core/define";
|
|
|
4
4
|
import type { ToolResult } from "@nylorun/core/define";
|
|
5
5
|
import type { DefinitionPart } from "@nylorun/core/define";
|
|
6
6
|
import type { JsonValue } from "@nylorun/core/define";
|
|
7
|
+
import type { FileContext } from "../model/files.js";
|
|
7
8
|
/** Compiled definition pieces plus the per-run model adapter for one step. */
|
|
8
9
|
export interface StepRuntime {
|
|
9
10
|
readonly parts: readonly DefinitionPart[];
|
|
10
11
|
readonly invoke: ModelAdapter;
|
|
11
12
|
readonly registry: ToolRegistry;
|
|
13
|
+
/** How the step reads and represents the turn's files (`representFiles`); none in a local run. */
|
|
14
|
+
readonly files?: FileContext;
|
|
12
15
|
/** Mutable session memory bag shared with tools. */
|
|
13
16
|
sessionState?: Record<string, JsonValue>;
|
|
14
17
|
}
|
|
@@ -24,6 +27,8 @@ export interface StepInput {
|
|
|
24
27
|
readonly arrivals: readonly InputEvent[];
|
|
25
28
|
readonly toolResults: readonly ToolResult[];
|
|
26
29
|
readonly transcript: readonly TranscriptEntry[];
|
|
30
|
+
/** Text kept at the head of the conversation (`ExecutionState.pinned`). */
|
|
31
|
+
readonly pinned?: readonly string[];
|
|
27
32
|
}
|
|
28
33
|
/** Internal view consumed by a single model step. */
|
|
29
34
|
export interface ExecutionSnapshot {
|
|
@@ -32,4 +37,5 @@ export interface ExecutionSnapshot {
|
|
|
32
37
|
readonly turnCount: number;
|
|
33
38
|
readonly revision: number;
|
|
34
39
|
readonly transcript: readonly TranscriptEntry[];
|
|
40
|
+
readonly pinned?: readonly string[];
|
|
35
41
|
}
|
package/dist/loop/step/seal.js
CHANGED
|
@@ -2,6 +2,7 @@ import { textFromOutput } from "../model/normalize.js";
|
|
|
2
2
|
import { createId } from "../../utils/ids.js";
|
|
3
3
|
import { HarnessError, isHarnessError } from "@nylorun/core/define";
|
|
4
4
|
import { assertJson, copyJson } from "@nylorun/core/define";
|
|
5
|
+
import { memoryAliasOf } from "@nylorun/core/contracts";
|
|
5
6
|
const failed = (callId, toolName, code, message, details) => Object.freeze({
|
|
6
7
|
kind: "failed",
|
|
7
8
|
callId,
|
|
@@ -80,12 +81,17 @@ function sealCall(context, catalog, candidate) {
|
|
|
80
81
|
immediate: failed(candidate.id, candidate.name, "tool.duplicate-call-id", `Duplicate Tool call id '${candidate.duplicateId}'`),
|
|
81
82
|
};
|
|
82
83
|
const tool = catalog.get(candidate.name);
|
|
83
|
-
if (!tool)
|
|
84
|
+
if (!tool) {
|
|
85
|
+
// `memory.<command>` whose own `command` disagrees: not mapped (`memoryAliasCall`).
|
|
86
|
+
const alias = catalog.has("memory") ? memoryAliasOf(candidate.name) : undefined;
|
|
84
87
|
return {
|
|
85
88
|
order,
|
|
86
89
|
canonical,
|
|
87
|
-
immediate: failed(candidate.id, candidate.name, "tool.unknown",
|
|
90
|
+
immediate: failed(candidate.id, candidate.name, "tool.unknown", alias
|
|
91
|
+
? `Unknown Tool '${candidate.name}'. Call memory with command "${alias}"; a call's command must match its name.`
|
|
92
|
+
: `Unknown Tool '${candidate.name}'`),
|
|
88
93
|
};
|
|
94
|
+
}
|
|
89
95
|
const args = validatedArguments(tool, candidate);
|
|
90
96
|
if (!args.ok)
|
|
91
97
|
return {
|
|
@@ -45,7 +45,7 @@ export class StepContext {
|
|
|
45
45
|
return this.#canonical;
|
|
46
46
|
}
|
|
47
47
|
mintFromModel(candidate) {
|
|
48
|
-
const { output, calls } = canonicalizeOutput(candidate.output);
|
|
48
|
+
const { output, calls } = canonicalizeOutput(candidate.output, new Set(this.offeredTools.map((tool) => tool.name)));
|
|
49
49
|
this.#canonical = calls;
|
|
50
50
|
this.#candidate = candidateFromCanonical(candidate, output);
|
|
51
51
|
}
|
package/dist/run/durable.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { type EffectTarget, type ModelDescriptor } from "@nylorun/core/harness-api";
|
|
2
|
+
import type { FileContext } from "../loop/model/files.js";
|
|
1
3
|
import type { AgentManifest } from "@nylorun/core/define";
|
|
2
4
|
import type { ExecutionInput, ExecutionState, RunResult } from "../types/execution.js";
|
|
3
5
|
import type { JsonObject } from "@nylorun/core/define";
|
|
4
6
|
import type { EffectOutcome } from "@nylorun/core/contracts";
|
|
5
7
|
import type { AgentRef } from "@nylorun/core/define";
|
|
8
|
+
import type { McpToolSet } from "../tools/mcp.js";
|
|
9
|
+
import type { EngineTools } from "../tools/engine-tools.js";
|
|
6
10
|
import { ENGINE_VERSION } from "../compatibility.js";
|
|
11
|
+
import type { LoopConfig } from "../loop/config.js";
|
|
7
12
|
/** Private persistence contract for hosts; this is not a session wire type. */
|
|
8
13
|
export interface DurableCheckpoint {
|
|
9
14
|
readonly version: 1;
|
|
@@ -30,7 +35,22 @@ export interface HostEffect {
|
|
|
30
35
|
readonly kind: "model" | "tool" | "delegation" | "agent";
|
|
31
36
|
/** Set on work for an agent used as a tool; `agentId` stays the session's root agent. */
|
|
32
37
|
readonly agent?: AgentRef;
|
|
38
|
+
/** The name the model called a tool by, for display; the record routes by `target`. */
|
|
33
39
|
readonly toolName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* What runs a tool call (protocol 15): an `mcp` tool by its identity (`server`, and `tool`, its
|
|
42
|
+
* name on the server), an `http` tool by its declared name, a `sandbox` operation, or a
|
|
43
|
+
* `harness` tool (ours, run here). An author's code tool has none: the record fails it to the
|
|
44
|
+
* model.
|
|
45
|
+
*/
|
|
46
|
+
readonly target?: EffectTarget;
|
|
47
|
+
/** The skill the call ran, which the record keeps when the agent has that skill. */
|
|
48
|
+
readonly skill?: string;
|
|
49
|
+
/**
|
|
50
|
+
* A model call that summarizes history for a compaction (protocol 15): the record writes no
|
|
51
|
+
* assistant message for it, and the compaction's transcript edit names it.
|
|
52
|
+
*/
|
|
53
|
+
readonly purpose?: "summary";
|
|
34
54
|
/** Workflow node path (flow effects). */
|
|
35
55
|
readonly path?: string;
|
|
36
56
|
/** Workflow node key without Map indices (flow effects). */
|
|
@@ -61,8 +81,16 @@ export type DurableResult = {
|
|
|
61
81
|
readonly status: "completed" | "paused" | "cancelled" | "failed" | "yielded";
|
|
62
82
|
readonly checkpoint: DurableCheckpoint;
|
|
63
83
|
readonly result: RunResult<unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* The root agent's summary calls of this segment, in order: the effects a compaction edit
|
|
86
|
+
* of its transcript names (`CompactionFacts.summaryEffectIds`).
|
|
87
|
+
*/
|
|
88
|
+
readonly summaryEffectIds?: readonly string[];
|
|
64
89
|
};
|
|
65
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* A tool our engine adds to an agent for this execution (an MCP tool of the session, one of our
|
|
92
|
+
* engine's own). It is not part of the hashed manifest.
|
|
93
|
+
*/
|
|
66
94
|
export interface DurableSessionTool {
|
|
67
95
|
/** The agent used as a tool that owns this tool; absent for the root agent. */
|
|
68
96
|
readonly agentId?: string;
|
|
@@ -75,8 +103,10 @@ export interface DurableSessionTool {
|
|
|
75
103
|
* with `tool_call`, which makes the call as this tool's own.
|
|
76
104
|
*/
|
|
77
105
|
readonly deferred?: boolean;
|
|
78
|
-
/** Text the model reads
|
|
106
|
+
/** Text the model reads, after the engine's, while this tool is advertised. */
|
|
79
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;
|
|
80
110
|
}
|
|
81
111
|
export declare function createDurableCheckpoint(input: {
|
|
82
112
|
manifest: AgentManifest;
|
|
@@ -96,10 +126,35 @@ export declare function runDurable(options: {
|
|
|
96
126
|
checkpoint: DurableCheckpoint;
|
|
97
127
|
host: DurableHost;
|
|
98
128
|
signal?: AbortSignal;
|
|
99
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The session's MCP tools as our engine offers them (`mcpToolSet`, from `turn.start.mcp`),
|
|
131
|
+
* after the agent's own and our engine's: every call an effect of the tool's identity. Their
|
|
132
|
+
* layout goes into the state the segment ends with (`mcpLayout`). Not hashed.
|
|
133
|
+
*/
|
|
134
|
+
mcp?: McpToolSet;
|
|
135
|
+
/**
|
|
136
|
+
* What our engine adds to each agent of the tree (root and agents used as tools,
|
|
137
|
+
* `engineToolsFor`): its tools, offered after the agent's own and before the session's MCP
|
|
138
|
+
* tools, and the text that goes with them, before the MCP tools' own. Run as host effects; not
|
|
139
|
+
* hashed.
|
|
140
|
+
*/
|
|
141
|
+
engineTools?: (agent: AgentManifest) => EngineTools;
|
|
142
|
+
/**
|
|
143
|
+
* Text to keep at the head of the conversation (`ExecutionState.pinned`): the memory index
|
|
144
|
+
* block (`memoryIndexBlock`, track T5). The state keeps what it pinned at the session's first
|
|
145
|
+
* turn, and after a compaction takes this; without it, the state drops its pinned text. Not
|
|
146
|
+
* hashed.
|
|
147
|
+
*/
|
|
148
|
+
pinned?: readonly string[];
|
|
100
149
|
/** Segment rollover (Model Calls §10): yield after this many steps or milliseconds. */
|
|
101
150
|
yieldAfter?: {
|
|
102
151
|
readonly steps?: number;
|
|
103
152
|
readonly ms?: number;
|
|
104
153
|
};
|
|
154
|
+
/** The model the turn's calls use (`turn.start.model`), for the root and every child. */
|
|
155
|
+
model?: ModelDescriptor;
|
|
156
|
+
/** How the turn's files reach the model (`representFiles`), for the root and every child. */
|
|
157
|
+
files?: FileContext;
|
|
158
|
+
/** The loop's settings (compaction, a failed child's partial output). Default `DEFAULT_LOOP_CONFIG`. */
|
|
159
|
+
loop?: LoopConfig;
|
|
105
160
|
}): Promise<DurableResult>;
|