@nylorun/harness 0.27.1-beta → 0.28.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 +100 -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 +20 -6
- package/dist/api/index.js +18 -4
- package/dist/api/run.d.ts +3 -0
- package/dist/api/run.js +81 -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 +8 -0
- package/dist/index.js +8 -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 +69 -41
- package/dist/loop/options.js +2 -0
- package/dist/loop/run.js +8 -3
- package/dist/loop/state.js +4 -0
- package/dist/loop/step/run.js +19 -3
- package/dist/loop/step/runtime.d.ts +3 -0
- package/dist/run/durable.d.ts +51 -3
- package/dist/run/durable.js +71 -31
- package/dist/tools/artifacts.d.ts +33 -0
- package/dist/tools/artifacts.js +323 -0
- package/dist/tools/engine-tools.d.ts +42 -0
- package/dist/tools/engine-tools.js +26 -0
- package/dist/tools/mcp.d.ts +92 -0
- package/dist/tools/mcp.js +240 -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/types/execution.d.ts +20 -0
- package/package.json +2 -2
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,9 +48,11 @@ 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;
|
|
@@ -110,9 +113,10 @@ export async function execute(agent, options, internals = {}) {
|
|
|
110
113
|
stepsRun++;
|
|
111
114
|
const stepId = createId("step");
|
|
112
115
|
// Keep the next prompt inside the model's window, before it is sent.
|
|
113
|
-
const budget = contextBudget(invocation.state.transcript);
|
|
116
|
+
const budget = contextBudget(invocation.state.transcript, options.model, compaction);
|
|
114
117
|
if (budget &&
|
|
115
|
-
estimateTokens(invocation.state.transcript, turnId
|
|
118
|
+
estimateTokens(invocation.state.transcript, turnId, options.files, compaction) >
|
|
119
|
+
budget.contextWindow - budget.reserve)
|
|
116
120
|
await compactHistory("threshold", stepId);
|
|
117
121
|
const snapshot = {
|
|
118
122
|
id: invocation.state.executionId,
|
|
@@ -126,6 +130,7 @@ export async function execute(agent, options, internals = {}) {
|
|
|
126
130
|
parts: agent.parts,
|
|
127
131
|
invoke: options.onModelCall,
|
|
128
132
|
registry: agent.registry,
|
|
133
|
+
...(options.files === undefined ? {} : { files: options.files }),
|
|
129
134
|
sessionState: invocation.sessionBag,
|
|
130
135
|
},
|
|
131
136
|
state: snapshot,
|
package/dist/loop/state.js
CHANGED
|
@@ -103,6 +103,10 @@ 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(),
|
|
106
110
|
turn: z.object({ turnId: id }).strict().optional(),
|
|
107
111
|
plan: z
|
|
108
112
|
.object({
|
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";
|
|
@@ -60,7 +62,10 @@ export async function runStep(input) {
|
|
|
60
62
|
output: input.output,
|
|
61
63
|
});
|
|
62
64
|
requestedModelId = request.model?.id;
|
|
63
|
-
|
|
65
|
+
// How each file of the turn reaches the model is ours to decide (protocol 15): text is read
|
|
66
|
+
// and inlined here, the rest goes as its reference or a note.
|
|
67
|
+
const files = await representFiles(liveFilesOf(request), input.agent.files, input.signal);
|
|
68
|
+
const call = projectModelCall(request, files);
|
|
64
69
|
const invocationId = createId("invocation");
|
|
65
70
|
modelInvocationId = invocationId;
|
|
66
71
|
input.observe(() => ({
|
|
@@ -108,7 +113,18 @@ export async function runStep(input) {
|
|
|
108
113
|
...(outcome.retryAfterMs === undefined ? {} : { retryAfterMs: outcome.retryAfterMs }),
|
|
109
114
|
},
|
|
110
115
|
});
|
|
111
|
-
|
|
116
|
+
// With an output schema, the final answer's text is read as JSON here (protocol 15). An
|
|
117
|
+
// answer that is not JSON stays in the transcript, as evidence, and fails the step.
|
|
118
|
+
const candidate = normalizeCandidate(outcome);
|
|
119
|
+
let answer;
|
|
120
|
+
try {
|
|
121
|
+
answer = structuredAnswer(candidate, request.outputSchema);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
context.mintFromModel(candidate);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
context.mintFromModel(answer);
|
|
112
128
|
if (!context.currentCandidate)
|
|
113
129
|
throw new HarnessError("model.candidate-missing", "Model candidate missing after mint");
|
|
114
130
|
}
|
|
@@ -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
|
}
|
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,28 @@ 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;
|
|
100
142
|
/** Segment rollover (Model Calls §10): yield after this many steps or milliseconds. */
|
|
101
143
|
yieldAfter?: {
|
|
102
144
|
readonly steps?: number;
|
|
103
145
|
readonly ms?: number;
|
|
104
146
|
};
|
|
147
|
+
/** The model the turn's calls use (`turn.start.model`), for the root and every child. */
|
|
148
|
+
model?: ModelDescriptor;
|
|
149
|
+
/** How the turn's files reach the model (`representFiles`), for the root and every child. */
|
|
150
|
+
files?: FileContext;
|
|
151
|
+
/** The loop's settings (compaction, a failed child's partial output). Default `DEFAULT_LOOP_CONFIG`. */
|
|
152
|
+
loop?: LoopConfig;
|
|
105
153
|
}): Promise<DurableResult>;
|
package/dist/run/durable.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { HarnessError } from "@nylorun/core/define";
|
|
2
2
|
import { effectIdOf } from "@nylorun/core/harness-api";
|
|
3
3
|
import { AgentManifestSchema } from "@nylorun/core/contracts";
|
|
4
|
-
import {
|
|
4
|
+
import { agentFrom, withHttpTarget } from "@nylorun/core/define";
|
|
5
|
+
import { TOOL_CALL_TOOL } from "../tools/tool-search.js";
|
|
5
6
|
import { definitionFor } from "../definition/agent-definition.js";
|
|
6
7
|
import { schemaFromJSON } from "@nylorun/core/define";
|
|
7
8
|
import { hashManifest } from "@nylorun/core/define";
|
|
8
9
|
import { withDeterministicIds } from "../utils/ids.js";
|
|
10
|
+
import { skillOfToolCall } from "../tools/trace.js";
|
|
9
11
|
import { execute } from "../loop/run.js";
|
|
10
12
|
import { initializeExecutionState } from "../loop/initial-state.js";
|
|
11
13
|
import { HostSuspension } from "../loop/host-suspension.js";
|
|
@@ -72,7 +74,7 @@ export async function runDurable(options) {
|
|
|
72
74
|
return result.outcome;
|
|
73
75
|
};
|
|
74
76
|
/** Tools of one agent. Each agent keeps its own patch order; children namespace their effects. */
|
|
75
|
-
const hostedTools = (ref) => {
|
|
77
|
+
const hostedTools = (agent, ref) => {
|
|
76
78
|
let patchTail = Promise.resolve();
|
|
77
79
|
return (tool) => ({
|
|
78
80
|
name: tool.name,
|
|
@@ -99,7 +101,7 @@ export async function runDurable(options) {
|
|
|
99
101
|
info: ctx.info,
|
|
100
102
|
state: ctx.state.entries(),
|
|
101
103
|
resume: ctx.resume,
|
|
102
|
-
}, scoped(ref, ctx.invocationId),
|
|
104
|
+
}, scoped(ref, ctx.invocationId), identityOf(agent, tool, args, ref));
|
|
103
105
|
// Apply concurrently resolved patches in manifest call order, independent of host I/O timing.
|
|
104
106
|
await previous;
|
|
105
107
|
for (const [key, value] of Object.entries(outcome.statePatch ?? {}))
|
|
@@ -122,50 +124,60 @@ export async function runDurable(options) {
|
|
|
122
124
|
},
|
|
123
125
|
});
|
|
124
126
|
};
|
|
125
|
-
const sessionTools = options.
|
|
127
|
+
const sessionTools = options.mcp?.tools ?? [];
|
|
126
128
|
/** Rebuild one agent from its manifest with every tool routed through host effects. */
|
|
127
129
|
const hostedDefinition = (agent, ref) => {
|
|
128
|
-
const hostedTool = hostedTools(ref);
|
|
129
|
-
const
|
|
130
|
+
const hostedTool = hostedTools(agent, ref);
|
|
131
|
+
const engine = options.engineTools?.(agent);
|
|
132
|
+
const mine = [
|
|
133
|
+
...(engine?.tools ?? []),
|
|
134
|
+
...sessionTools.filter((tool) => (tool.agentId ?? manifest.id) === agent.id),
|
|
135
|
+
];
|
|
130
136
|
// Deferred tools stay out of the model's list; `tool_call` runs them (R2b C10).
|
|
131
137
|
const owned = mine.filter((tool) => !tool.deferred);
|
|
132
138
|
const deferred = new Map(mine.filter((tool) => tool.deferred).map((tool) => [tool.name, tool]));
|
|
133
139
|
const tools = {};
|
|
134
140
|
// Agents used as tools are rebuilt from their manifest body; the engine runs them. An
|
|
135
141
|
// HTTP tool keeps its target (the manifest's hash covers it) and runs as a host effect.
|
|
142
|
+
// An author's code tool names no target: the record fails it to the model.
|
|
136
143
|
for (const tool of agent.tools ?? [])
|
|
137
144
|
if (tool.http)
|
|
138
145
|
// A pinned `approval` stays for the definition's hash; the Tool Gate holds the call.
|
|
139
|
-
tools[tool.name] = withHttpTarget(hostedTool(tool), {
|
|
146
|
+
tools[tool.name] = withHttpTarget(hostedTool({ ...tool, target: { kind: "http", tool: tool.name } }), {
|
|
140
147
|
http: tool.http,
|
|
141
148
|
...(tool.approval === undefined ? {} : { approval: tool.approval }),
|
|
142
149
|
});
|
|
143
150
|
else if (!tool.agent)
|
|
144
151
|
tools[tool.name] = hostedTool(tool);
|
|
145
|
-
//
|
|
146
|
-
for (const tool of agent.runtime?.tools ?? [])
|
|
147
|
-
tools[tool.name] = hostedTool(tool);
|
|
152
|
+
// Our engine's own tools and the session's run as host effects too.
|
|
148
153
|
for (const tool of owned)
|
|
149
154
|
tools[tool.name] =
|
|
150
155
|
tool.name === TOOL_CALL_TOOL
|
|
151
156
|
? deferredToolCall(tool, deferred, hostedTool)
|
|
152
157
|
: hostedTool(tool);
|
|
153
158
|
const implementations = { tools };
|
|
154
|
-
return definitionFor(agentFrom(agent, implementations,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
return definitionFor(agentFrom(agent, implementations, {
|
|
160
|
+
sessionTools: owned.map((tool) => ({
|
|
161
|
+
name: tool.name,
|
|
162
|
+
...(tool.instructions?.length ? { instructions: tool.instructions } : {}),
|
|
163
|
+
})),
|
|
164
|
+
...(engine?.instructions.length ? { sessionInstructions: engine.instructions } : {}),
|
|
165
|
+
}));
|
|
166
|
+
};
|
|
167
|
+
/** The root agent's summary calls, in the order they were made: a compaction edit names them. */
|
|
168
|
+
const summaries = [];
|
|
169
|
+
const modelCall = (ref) => async (call, ctx) => {
|
|
170
|
+
const identity = scoped(ref, ctx.invocationId);
|
|
171
|
+
// A compaction of an agent used as a tool lives in our state, not the session's transcript.
|
|
172
|
+
if (ctx.compaction && !ref)
|
|
173
|
+
summaries.push(effectIdOf(checkpoint.turnId, checkpoint.segment, "model", identity));
|
|
174
|
+
return (await effect("model", call,
|
|
175
|
+
// The call already holds the whole prompt; journaling the request would store it twice.
|
|
176
|
+
{ invocationId: ctx.invocationId }, identity, {
|
|
177
|
+
...(ref ? { agent: ref } : {}),
|
|
178
|
+
...(ctx.compaction ? { purpose: "summary" } : {}),
|
|
179
|
+
})).value;
|
|
162
180
|
};
|
|
163
|
-
const modelCall = (ref) => async (call, ctx) => (await effect("model", call,
|
|
164
|
-
// The call already holds the whole prompt; journaling the request would store it twice.
|
|
165
|
-
{
|
|
166
|
-
invocationId: ctx.invocationId,
|
|
167
|
-
...(ctx.compaction ? { compaction: ctx.compaction } : {}),
|
|
168
|
-
}, scoped(ref, ctx.invocationId), ref ? { agent: ref } : {})).value;
|
|
169
181
|
const delegation = {
|
|
170
182
|
child: (delegate, ref) => ({
|
|
171
183
|
definition: hostedDefinition(delegate.manifest, ref),
|
|
@@ -189,14 +201,25 @@ export async function runDurable(options) {
|
|
|
189
201
|
throw new HarnessError("execution.incompatible", "Reconstructed definition hash mismatch");
|
|
190
202
|
try {
|
|
191
203
|
const result = await withDeterministicIds(`${checkpoint.turnId}_${checkpoint.segment}`, () => execute(hosted, {
|
|
192
|
-
state: checkpoint.state ??
|
|
193
|
-
initializeExecutionState(hosted, { executionId: checkpoint.sessionId }),
|
|
204
|
+
state: withLayout(checkpoint.state ??
|
|
205
|
+
initializeExecutionState(hosted, { executionId: checkpoint.sessionId }), options.mcp),
|
|
194
206
|
input: checkpoint.input,
|
|
195
207
|
info: checkpoint.info,
|
|
196
208
|
signal: options.signal,
|
|
197
209
|
onModelCall: modelCall(),
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
...(options.model === undefined ? {} : { model: options.model }),
|
|
211
|
+
...(options.files === undefined ? {} : { files: options.files }),
|
|
212
|
+
}, {
|
|
213
|
+
delegation,
|
|
214
|
+
...(options.yieldAfter ? { yieldAfter: options.yieldAfter } : {}),
|
|
215
|
+
...(options.loop ? { loop: options.loop } : {}),
|
|
216
|
+
}));
|
|
217
|
+
return {
|
|
218
|
+
status: result.status,
|
|
219
|
+
checkpoint: { ...checkpoint, state: result.state },
|
|
220
|
+
result,
|
|
221
|
+
...(summaries.length > 0 ? { summaryEffectIds: [...summaries] } : {}),
|
|
222
|
+
};
|
|
200
223
|
}
|
|
201
224
|
catch (error) {
|
|
202
225
|
// Parallel tool dispatch can suspend more than one action. Drain persistence before returning.
|
|
@@ -210,6 +233,23 @@ export async function runDurable(options) {
|
|
|
210
233
|
};
|
|
211
234
|
}
|
|
212
235
|
}
|
|
236
|
+
/** The state with the MCP tools' layout our engine follows (`mcpLayout`), when it has MCP tools. */
|
|
237
|
+
function withLayout(state, mcp) {
|
|
238
|
+
if (mcp === undefined)
|
|
239
|
+
return state;
|
|
240
|
+
const { factsHash, deferred } = mcp.layout;
|
|
241
|
+
return { ...state, mcpLayout: { factsHash, deferred: [...deferred] } };
|
|
242
|
+
}
|
|
243
|
+
/** What a tool effect names beside its input: the tool, what runs it, its skill and its agent. */
|
|
244
|
+
function identityOf(agent, tool, input, ref) {
|
|
245
|
+
const skill = skillOfToolCall(agent, tool, input);
|
|
246
|
+
return {
|
|
247
|
+
toolName: tool.name,
|
|
248
|
+
...(tool.target === undefined ? {} : { target: tool.target }),
|
|
249
|
+
...(skill === undefined ? {} : { skill }),
|
|
250
|
+
...(ref ? { agent: ref } : {}),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
213
253
|
/** Effect identities of an agent used as a tool live under its delegation. */
|
|
214
254
|
function scoped(ref, identity) {
|
|
215
255
|
return ref ? `${ref.delegationId}/${identity}` : identity;
|
|
@@ -217,9 +257,9 @@ function scoped(ref, identity) {
|
|
|
217
257
|
/**
|
|
218
258
|
* `tool_call` (R2b C10): runs a deferred tool by name, as that tool's own call. It checks the
|
|
219
259
|
* arguments against the tool's `inputSchema` first, so a mistake comes back to the model as a
|
|
220
|
-
* failed result it can fix. The effect then names the tool
|
|
221
|
-
*
|
|
222
|
-
* would a direct call.
|
|
260
|
+
* failed result it can fix. The effect then names the tool and its identity (`target`), so the
|
|
261
|
+
* record routes it and records `tool.completed` as for a direct call, the host shapes its result,
|
|
262
|
+
* and the Tool Gate holds it as it would a direct call.
|
|
223
263
|
*/
|
|
224
264
|
function deferredToolCall(tool, deferred, hostedTool) {
|
|
225
265
|
const hosted = new Map();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ArtifactRequester } from "@nylorun/core/harness-api";
|
|
2
|
+
import type { DurableSessionTool, HostEffect } from "../run/durable.js";
|
|
3
|
+
import type { FailedFileOutcome, HarnessFiles, HarnessRun } from "../api/executors.js";
|
|
4
|
+
/** The harness's configuration of its artifact tools. */
|
|
5
|
+
export interface ArtifactToolOptions {
|
|
6
|
+
/** The most bytes one `read_artifact` page holds, escaped as JSON. */
|
|
7
|
+
readonly pageBytes: number;
|
|
8
|
+
}
|
|
9
|
+
/** True when `name` is one of our engine's artifact tools. */
|
|
10
|
+
export declare function isArtifactTool(name: string | undefined): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The artifact tools our engine offers an agent: `save_artifact` when the session has a sandbox,
|
|
13
|
+
* and `read_artifact`, which takes `path` only then. Each runs here (`harness`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function artifactToolsFor(sandboxed: boolean, options: ArtifactToolOptions): DurableSessionTool[];
|
|
16
|
+
/** What the model reads with the artifact tools, in their order. */
|
|
17
|
+
export declare function artifactInstructions(sandboxed: boolean): string[];
|
|
18
|
+
/** What an artifact tool runs with. */
|
|
19
|
+
export interface ArtifactToolContext extends ArtifactToolOptions {
|
|
20
|
+
readonly channel: ArtifactRequester;
|
|
21
|
+
readonly run: HarnessRun;
|
|
22
|
+
/** The run's sandbox files; undefined where the harness has none. */
|
|
23
|
+
readonly files?: HarnessFiles;
|
|
24
|
+
readonly signal: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
type Outcome = {
|
|
27
|
+
readonly kind: "completed";
|
|
28
|
+
readonly output: Record<string, unknown>;
|
|
29
|
+
readonly files?: readonly unknown[];
|
|
30
|
+
} | FailedFileOutcome;
|
|
31
|
+
/** Runs a call of one of our engine's artifact tools, as its outcome. */
|
|
32
|
+
export declare function runArtifactTool(effect: HostEffect, context: ArtifactToolContext): Promise<Outcome>;
|
|
33
|
+
export {};
|