@nylorun/harness 0.29.7-beta → 0.30.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 +27 -0
- package/dist/api/host.d.ts +3 -2
- package/dist/api/host.js +9 -2
- package/dist/api/run.js +8 -1
- package/dist/tools/connection.d.ts +48 -0
- package/dist/tools/connection.js +85 -0
- package/dist/tools/engine-tools.d.ts +10 -5
- package/dist/tools/engine-tools.js +18 -2
- package/dist/tools/plan.d.ts +61 -0
- package/dist/tools/plan.js +142 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.30.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d48b6ef: An agent keeps a durable plan (A2A profile v2, `progress/v1`; A2A-E10).
|
|
8
|
+
|
|
9
|
+
- **`plan.updated`**, a new durable session event: `{ steps: [{ label, state, note? }] }`, the agent's whole plan each time, never a diff. `state` is `pending`, `active`, `done`, `blocked` or `skipped`; at most 20 steps, labels of at most 120 and notes of at most 280 characters (`PLAN_LIMITS`, `PLAN_STEP_STATES`, `PlanUpdatedPayloadSchema` in `@nylorun/core/contracts`). The Runtime records and serves it like any public event, with the harness as its writer (evidence `claimed`), and the OpenAPI document lists it.
|
|
10
|
+
- **`update_plan`**, a built-in tool of our engine, off by default. A version opts in with `harness.loop.plan: true` (in an agent folder, `loop: { plan: true }` in `AGENT.md`'s frontmatter); the session's root agent then gets the tool, unless it declares its own tool of that name. A call takes `{ steps: [...] }`, cuts long labels and notes (ending in `…`) and steps past 20 rather than refusing them, claims one `plan.updated` and answers `Plan updated`. A malformed plan is a failed result the model sees.
|
|
11
|
+
- **Harness API**: `plan.updated` is a claim a harness may make (`HARNESS_CLAIMS`), additive within v5. The JSON Schema document is now published as `https://docs.nylorun.com/schemas/harness-api/v5.1.json`; `v5.json` is retired.
|
|
12
|
+
- The agent folder compiler takes `loop.plan` (true or false) and suggests it for a close typo.
|
|
13
|
+
|
|
14
|
+
- d48b6ef: An agent asks for an app to be connected (A2A profile v2, `interactions/v1` kind `connection`).
|
|
15
|
+
|
|
16
|
+
- **`request_connection`**, a built-in tool of our engine, off by default. A version opts in with `harness.loop.connections: true` (in an agent folder, `loop: { connections: true }` in `AGENT.md`); the session's root agent then gets the tool, unless it declares its own tool of that name.
|
|
17
|
+
- A call takes `{ app, reason }` (app cut at 80 characters, reason at 280, never refused for length) and pauses the turn on an interaction: kind `response`, prompt `Connect <app>: <reason>`, `metadata: { kind: "connection", app, reason }`, which the session's `waits` carry. Answered with `respond`, `true` or `{ connected: true }` gives the model `Connected: <app>`; any other value `Not connected: <app>`.
|
|
18
|
+
- The agent folder compiler takes `loop.connections` (true or false).
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Pin core to the tested release.
|
|
23
|
+
- Updated dependencies [d48b6ef]
|
|
24
|
+
- Updated dependencies [d48b6ef]
|
|
25
|
+
- Updated dependencies [d48b6ef]
|
|
26
|
+
- Updated dependencies [d48b6ef]
|
|
27
|
+
- Updated dependencies [d48b6ef]
|
|
28
|
+
- @nylorun/core@0.32.0-beta
|
|
29
|
+
|
|
3
30
|
## 0.29.7-beta
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/api/host.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ export interface EngineConfig extends EngineToolOptions {
|
|
|
36
36
|
/**
|
|
37
37
|
* The host of one run. A `harness` tool call is one of our engine's own tools, run here: the skill
|
|
38
38
|
* tools over `definition.file`, the artifact tools over the artifact seam and `executors.files`,
|
|
39
|
-
* `tool_search` over the run's MCP tools (`mcp`)
|
|
40
|
-
*
|
|
39
|
+
* `tool_search` over the run's MCP tools (`mcp`), `update_plan` as a `plan.updated` claim,
|
|
40
|
+
* `request_connection` as an interaction. Every other tool call goes to `executors.tool`, which
|
|
41
|
+
* routes it by its target.
|
|
41
42
|
*/
|
|
42
43
|
export declare function apiHost(channel: HarnessChannel, executors: HarnessExecutors, run: HarnessRun, engine: EngineConfig, mcp?: McpToolSet): DurableHost;
|
package/dist/api/host.js
CHANGED
|
@@ -22,12 +22,15 @@ import { isArtifactTool, runArtifactTool } from "../tools/artifacts.js";
|
|
|
22
22
|
import { isSkillTool, mountSkills, runSkillTool } from "../tools/skills.js";
|
|
23
23
|
import { StepBudget, jsonBytes, mayNeedShaping, shapeToolOutcome, spillKey, } from "../tools/results.js";
|
|
24
24
|
import { isToolSearch, runToolSearch } from "../tools/tool-search.js";
|
|
25
|
+
import { isPlanTool, runPlanTool } from "../tools/plan.js";
|
|
26
|
+
import { isConnectionTool, runConnectionTool } from "../tools/connection.js";
|
|
25
27
|
import { runAbortKind } from "./abort.js";
|
|
26
28
|
/**
|
|
27
29
|
* The host of one run. A `harness` tool call is one of our engine's own tools, run here: the skill
|
|
28
30
|
* tools over `definition.file`, the artifact tools over the artifact seam and `executors.files`,
|
|
29
|
-
* `tool_search` over the run's MCP tools (`mcp`)
|
|
30
|
-
*
|
|
31
|
+
* `tool_search` over the run's MCP tools (`mcp`), `update_plan` as a `plan.updated` claim,
|
|
32
|
+
* `request_connection` as an interaction. Every other tool call goes to `executors.tool`, which
|
|
33
|
+
* routes it by its target.
|
|
31
34
|
*/
|
|
32
35
|
export function apiHost(channel, executors, run, engine, mcp) {
|
|
33
36
|
const recorded = new Map(run.start.outcomes.map((outcome) => [outcome.effectId, outcome]));
|
|
@@ -172,6 +175,10 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
172
175
|
const engineTool = (effect) => {
|
|
173
176
|
if (isToolSearch(effect))
|
|
174
177
|
return Promise.resolve(runToolSearch(effect, mcp?.deferredOf(effect.agent?.id) ?? [], engine.mcpTools));
|
|
178
|
+
if (isPlanTool(effect))
|
|
179
|
+
return runPlanTool(effect, { channel, run, signal });
|
|
180
|
+
if (isConnectionTool(effect))
|
|
181
|
+
return Promise.resolve(runConnectionTool(effect));
|
|
175
182
|
if (isArtifactTool(effect.toolName))
|
|
176
183
|
return runArtifactTool(effect, {
|
|
177
184
|
channel,
|
package/dist/api/run.js
CHANGED
|
@@ -61,11 +61,18 @@ export async function runTurn(ctx, run) {
|
|
|
61
61
|
// the root only, and its index pinned at the head of the conversation.
|
|
62
62
|
const memory = start.engine === "agent" ? start.memory : undefined;
|
|
63
63
|
const rootId = start.manifest.id;
|
|
64
|
+
// The agent's plan and connection requests (A2A profile v2): the version's
|
|
65
|
+
// `harness.loop.plan` and `harness.loop.connections`, for the root agent.
|
|
66
|
+
const loop = start.engine === "agent"
|
|
67
|
+
? start.loop
|
|
68
|
+
: undefined;
|
|
69
|
+
const plan = loop?.plan === true;
|
|
70
|
+
const connections = loop?.connections === true;
|
|
64
71
|
const engineTools = (agent) => engineToolsFor(agent, start.agent, ctx.engine, memory && {
|
|
65
72
|
access: memory.access,
|
|
66
73
|
...(memory.instructions === undefined ? {} : { instructions: memory.instructions }),
|
|
67
74
|
root: agent.id === rootId,
|
|
68
|
-
});
|
|
75
|
+
}, plan && agent.id === rootId, connections && agent.id === rootId);
|
|
69
76
|
const mcp = start.engine === "agent" && start.mcp
|
|
70
77
|
? mcpToolSet(start.mcp, start.manifest, {
|
|
71
78
|
config: ctx.engine.mcpTools,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DurableSessionTool, HostEffect } from "../run/durable.js";
|
|
2
|
+
/** The tool's name. */
|
|
3
|
+
export declare const REQUEST_CONNECTION_TOOL = "request_connection";
|
|
4
|
+
/** The most characters of the app's name and of the reason. */
|
|
5
|
+
export declare const CONNECTION_LIMITS: Readonly<{
|
|
6
|
+
appChars: 80;
|
|
7
|
+
reasonChars: 280;
|
|
8
|
+
}>;
|
|
9
|
+
/** The tool, and the text the model reads with it. */
|
|
10
|
+
export declare function connectionTool(): {
|
|
11
|
+
tool: DurableSessionTool;
|
|
12
|
+
instructions: string;
|
|
13
|
+
};
|
|
14
|
+
/** True when `effect` is a call of `request_connection` (ours: a `harness` call). */
|
|
15
|
+
export declare function isConnectionTool(effect: HostEffect): boolean;
|
|
16
|
+
/** Whether an answer says the app is connected: `true`, or `{ connected: true }`. */
|
|
17
|
+
export declare function connectedIn(value: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Runs a call of `request_connection`: the interaction to wait on, or, once answered (the effect's
|
|
20
|
+
* `context.resume`), what the answer says.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runConnectionTool(effect: HostEffect): {
|
|
23
|
+
readonly kind: "failed";
|
|
24
|
+
readonly code: "connection.invalid_input";
|
|
25
|
+
readonly message: "Give app, the app to connect, and reason, why you need it.";
|
|
26
|
+
readonly output?: undefined;
|
|
27
|
+
readonly interaction?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
readonly code?: undefined;
|
|
30
|
+
readonly message?: undefined;
|
|
31
|
+
readonly kind: "completed";
|
|
32
|
+
readonly output: string;
|
|
33
|
+
readonly interaction?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
readonly code?: undefined;
|
|
36
|
+
readonly message?: undefined;
|
|
37
|
+
readonly output?: undefined;
|
|
38
|
+
readonly kind: "interaction-required";
|
|
39
|
+
readonly interaction: {
|
|
40
|
+
readonly kind: "response";
|
|
41
|
+
readonly prompt: `Connect ${string}: ${string}`;
|
|
42
|
+
readonly metadata: {
|
|
43
|
+
readonly kind: "connection";
|
|
44
|
+
readonly app: string;
|
|
45
|
+
readonly reason: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { cut } from "./plan.js";
|
|
2
|
+
/** The tool's name. */
|
|
3
|
+
export const REQUEST_CONNECTION_TOOL = "request_connection";
|
|
4
|
+
/** The most characters of the app's name and of the reason. */
|
|
5
|
+
export const CONNECTION_LIMITS = Object.freeze({ appChars: 80, reasonChars: 280 });
|
|
6
|
+
const HARNESS = Object.freeze({ kind: "harness" });
|
|
7
|
+
const DESCRIPTION = [
|
|
8
|
+
"Ask the person or agent who gave you this task to connect an app you need and cannot reach, such as their GitHub, Linear or Google Drive, then wait for their answer.",
|
|
9
|
+
"Give the app's name and the reason, in a sentence they can act on.",
|
|
10
|
+
"It answers Connected: <app> once they connected it, so try again; or Not connected: <app>, so go on without it or say what you could not do.",
|
|
11
|
+
"Use it only when a tool says the app is not connected or its credential is missing; never to ask anything else.",
|
|
12
|
+
].join(" ");
|
|
13
|
+
const INPUT_SCHEMA = {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
app: {
|
|
17
|
+
type: "string",
|
|
18
|
+
minLength: 1,
|
|
19
|
+
description: `The app to connect, by its name (at most ${CONNECTION_LIMITS.appChars} characters).`,
|
|
20
|
+
},
|
|
21
|
+
reason: {
|
|
22
|
+
type: "string",
|
|
23
|
+
minLength: 1,
|
|
24
|
+
description: `Why you need it, in a sentence (at most ${CONNECTION_LIMITS.reasonChars} characters).`,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
required: ["app", "reason"],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
};
|
|
30
|
+
const INSTRUCTIONS = "When a tool fails because an app is not connected or its credential is missing, ask for it with request_connection, then try again once it is connected.";
|
|
31
|
+
/** The tool, and the text the model reads with it. */
|
|
32
|
+
export function connectionTool() {
|
|
33
|
+
return {
|
|
34
|
+
tool: {
|
|
35
|
+
name: REQUEST_CONNECTION_TOOL,
|
|
36
|
+
description: DESCRIPTION,
|
|
37
|
+
inputSchema: INPUT_SCHEMA,
|
|
38
|
+
target: HARNESS,
|
|
39
|
+
},
|
|
40
|
+
instructions: INSTRUCTIONS,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** True when `effect` is a call of `request_connection` (ours: a `harness` call). */
|
|
44
|
+
export function isConnectionTool(effect) {
|
|
45
|
+
return effect.target?.kind === "harness" && effect.toolName === REQUEST_CONNECTION_TOOL;
|
|
46
|
+
}
|
|
47
|
+
/** Whether an answer says the app is connected: `true`, or `{ connected: true }`. */
|
|
48
|
+
export function connectedIn(value) {
|
|
49
|
+
if (value === true)
|
|
50
|
+
return true;
|
|
51
|
+
return (typeof value === "object" &&
|
|
52
|
+
value !== null &&
|
|
53
|
+
value.connected === true);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs a call of `request_connection`: the interaction to wait on, or, once answered (the effect's
|
|
57
|
+
* `context.resume`), what the answer says.
|
|
58
|
+
*/
|
|
59
|
+
export function runConnectionTool(effect) {
|
|
60
|
+
const input = (effect.input ?? {});
|
|
61
|
+
const app = typeof input.app === "string" ? input.app.trim() : "";
|
|
62
|
+
const reason = typeof input.reason === "string" ? input.reason.trim() : "";
|
|
63
|
+
if (app === "" || reason === "")
|
|
64
|
+
return {
|
|
65
|
+
kind: "failed",
|
|
66
|
+
code: "connection.invalid_input",
|
|
67
|
+
message: "Give app, the app to connect, and reason, why you need it.",
|
|
68
|
+
};
|
|
69
|
+
const named = cut(app, CONNECTION_LIMITS.appChars);
|
|
70
|
+
const why = cut(reason, CONNECTION_LIMITS.reasonChars);
|
|
71
|
+
const resume = effect.context?.resume;
|
|
72
|
+
if (resume?.kind === "response")
|
|
73
|
+
return {
|
|
74
|
+
kind: "completed",
|
|
75
|
+
output: connectedIn(resume.value) ? `Connected: ${named}` : `Not connected: ${named}`,
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
kind: "interaction-required",
|
|
79
|
+
interaction: {
|
|
80
|
+
kind: "response",
|
|
81
|
+
prompt: `Connect ${named}: ${why}`,
|
|
82
|
+
metadata: { kind: "connection", app: named, reason: why },
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* - instructions: the skills' usage and catalog; the sandbox note; the skills' folder note;
|
|
8
8
|
* the artifact notes;
|
|
9
9
|
* - tools: the six sandbox tools; the skill tools; `save_artifact`; `read_artifact`;
|
|
10
|
-
* `schedule_wake` when the session's version sets `runtime.selfWake` (track T4);
|
|
11
|
-
* when it sets `harness.memory` (track T5)
|
|
10
|
+
* `schedule_wake` when the session's version sets `runtime.selfWake` (track T4); `memory`
|
|
11
|
+
* when it sets `harness.memory` (track T5); and, for the root agent, `update_plan` when it sets
|
|
12
|
+
* `harness.loop.plan` and `request_connection` when it sets `harness.loop.connections` (A2A
|
|
13
|
+
* profile v2).
|
|
12
14
|
*
|
|
13
15
|
* They come after the agent's own and before the session's MCP tools (`mcpToolSet`), and are
|
|
14
16
|
* not hashed.
|
|
@@ -43,8 +45,11 @@ export interface EngineTools {
|
|
|
43
45
|
/**
|
|
44
46
|
* Our engine's tools and text for `agent`, in a session on Agent `runsOn` (`turn.start.agent`)
|
|
45
47
|
* with its memory (`turn.start.memory`). `memory.root` is false for an agent used as a tool,
|
|
46
|
-
* which may only view memory.
|
|
48
|
+
* which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
|
|
49
|
+
* the version sets `harness.loop.plan` (`turn.start.loop.plan`); `connections` offers
|
|
50
|
+
* `request_connection` alike (`harness.loop.connections`). An agent whose own tools name one of
|
|
51
|
+
* them keeps its own.
|
|
47
52
|
*/
|
|
48
|
-
export declare function engineToolsFor(agent: Pick<AgentManifest, "skills">, runsOn: TurnAgent | undefined, options: Pick<EngineToolOptions, "artifactPageBytes" | "sandboxTools" | "skillReadBytes">, memory?: Pick<TurnMemory, "access" | "instructions"> & {
|
|
53
|
+
export declare function engineToolsFor(agent: Pick<AgentManifest, "skills" | "tools">, runsOn: TurnAgent | undefined, options: Pick<EngineToolOptions, "artifactPageBytes" | "sandboxTools" | "skillReadBytes">, memory?: Pick<TurnMemory, "access" | "instructions"> & {
|
|
49
54
|
readonly root: boolean;
|
|
50
|
-
}): EngineTools;
|
|
55
|
+
}, plan?: boolean, connections?: boolean): EngineTools;
|
|
@@ -3,12 +3,17 @@ import { sandboxInstructions, sandboxTools } from "./sandbox.js";
|
|
|
3
3
|
import { skillCatalogText, skillFolderNote, skillTools } from "./skills.js";
|
|
4
4
|
import { wakeTool } from "./wake.js";
|
|
5
5
|
import { memoryTool } from "./memory.js";
|
|
6
|
+
import { planTool, UPDATE_PLAN_TOOL } from "./plan.js";
|
|
7
|
+
import { connectionTool, REQUEST_CONNECTION_TOOL } from "./connection.js";
|
|
6
8
|
/**
|
|
7
9
|
* Our engine's tools and text for `agent`, in a session on Agent `runsOn` (`turn.start.agent`)
|
|
8
10
|
* with its memory (`turn.start.memory`). `memory.root` is false for an agent used as a tool,
|
|
9
|
-
* which may only view memory.
|
|
11
|
+
* which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
|
|
12
|
+
* the version sets `harness.loop.plan` (`turn.start.loop.plan`); `connections` offers
|
|
13
|
+
* `request_connection` alike (`harness.loop.connections`). An agent whose own tools name one of
|
|
14
|
+
* them keeps its own.
|
|
10
15
|
*/
|
|
11
|
-
export function engineToolsFor(agent, runsOn, options, memory) {
|
|
16
|
+
export function engineToolsFor(agent, runsOn, options, memory, plan = false, connections = false) {
|
|
12
17
|
const skills = Object.values(agent.skills ?? {});
|
|
13
18
|
const workspace = runsOn?.sandbox?.workspace;
|
|
14
19
|
const sandboxed = workspace !== undefined;
|
|
@@ -29,6 +34,15 @@ export function engineToolsFor(agent, runsOn, options, memory) {
|
|
|
29
34
|
const remember = memory ? memoryTool(memory, memory.root) : undefined;
|
|
30
35
|
if (remember)
|
|
31
36
|
instructions.push(remember.instructions);
|
|
37
|
+
// The agent's plan (A2A profile v2, `progress/v1`).
|
|
38
|
+
const own = (name) => (agent.tools ?? []).some((tool) => tool.name === name);
|
|
39
|
+
const planning = plan && !own(UPDATE_PLAN_TOOL) ? planTool() : undefined;
|
|
40
|
+
if (planning)
|
|
41
|
+
instructions.push(planning.instructions);
|
|
42
|
+
// The apps the agent asks to have connected (A2A profile v2, `interactions/v1` kind `connection`).
|
|
43
|
+
const connecting = connections && !own(REQUEST_CONNECTION_TOOL) ? connectionTool() : undefined;
|
|
44
|
+
if (connecting)
|
|
45
|
+
instructions.push(connecting.instructions);
|
|
32
46
|
return {
|
|
33
47
|
tools: [
|
|
34
48
|
...(sandboxed ? sandboxTools(options.sandboxTools, workspace) : []),
|
|
@@ -36,6 +50,8 @@ export function engineToolsFor(agent, runsOn, options, memory) {
|
|
|
36
50
|
...artifactToolsFor(sandboxed, { pageBytes: options.artifactPageBytes }),
|
|
37
51
|
...(wake ? [wake.tool] : []),
|
|
38
52
|
...(remember ? [remember.tool] : []),
|
|
53
|
+
...(planning ? [planning.tool] : []),
|
|
54
|
+
...(connecting ? [connecting.tool] : []),
|
|
39
55
|
],
|
|
40
56
|
instructions,
|
|
41
57
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `update_plan` (A2A profile v2, `progress/v1`): the agent keeps its plan, a short list of steps
|
|
3
|
+
* with their states, which callers see while it works. Offered to the session's root agent when
|
|
4
|
+
* the version the session runs sets `harness.loop.plan: true` (`turn.start.loop.plan`; in an agent
|
|
5
|
+
* folder, `loop: { plan: true }` in `AGENT.md`). It runs here (`harness`): each call claims one
|
|
6
|
+
* durable `plan.updated` event with the whole plan, never a diff, over the Harness API's `event`
|
|
7
|
+
* request. A replayed call answers its recorded outcome and claims nothing again.
|
|
8
|
+
*
|
|
9
|
+
* Long input is cut, never refused: at most `PLAN_LIMITS.steps` steps (the first ones), a label of
|
|
10
|
+
* at most `labelChars` and a note of at most `noteChars`, each cut ending in `…`.
|
|
11
|
+
*/
|
|
12
|
+
import { type PlanStep } from "@nylorun/core/contracts";
|
|
13
|
+
import { type HarnessChannel } from "@nylorun/core/harness-api";
|
|
14
|
+
import type { DurableSessionTool, HostEffect } from "../run/durable.js";
|
|
15
|
+
import type { HarnessRun } from "../api/executors.js";
|
|
16
|
+
/** The tool's name. */
|
|
17
|
+
export declare const UPDATE_PLAN_TOOL = "update_plan";
|
|
18
|
+
/** What a call answers. */
|
|
19
|
+
export declare const PLAN_UPDATED = "Plan updated";
|
|
20
|
+
/** The tool, and the text the model reads with it. */
|
|
21
|
+
export declare function planTool(): {
|
|
22
|
+
tool: DurableSessionTool;
|
|
23
|
+
instructions: string;
|
|
24
|
+
};
|
|
25
|
+
/** True when `effect` is a call of `update_plan` (ours: a `harness` call). */
|
|
26
|
+
export declare function isPlanTool(effect: HostEffect): boolean;
|
|
27
|
+
/** `text` cut to at most `max` UTF-16 units, ending in `…` when cut, never inside a surrogate pair. */
|
|
28
|
+
export declare function cut(text: string, max: number): string;
|
|
29
|
+
/** The plan a call's input states, cut to the limits; a string naming the problem when it is not one. */
|
|
30
|
+
export declare function planOf(input: unknown): {
|
|
31
|
+
steps: PlanStep[];
|
|
32
|
+
dropped: number;
|
|
33
|
+
} | string;
|
|
34
|
+
/** What a call of `update_plan` runs with. */
|
|
35
|
+
export interface PlanToolContext {
|
|
36
|
+
readonly channel: Pick<HarnessChannel, "request">;
|
|
37
|
+
readonly run: HarnessRun;
|
|
38
|
+
readonly signal: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runs a call of `update_plan`: claims `plan.updated` with the whole plan for the run's turn, and
|
|
42
|
+
* answers `Plan updated`. A malformed plan, or a claim the Runtime refuses (one that does not
|
|
43
|
+
* know `plan.updated`), is a failed outcome the model sees; a run this harness no longer holds
|
|
44
|
+
* throws.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runPlanTool(effect: HostEffect, context: PlanToolContext): Promise<{
|
|
47
|
+
readonly kind: "failed";
|
|
48
|
+
readonly code: "plan.invalid_input";
|
|
49
|
+
readonly message: string;
|
|
50
|
+
readonly output?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: "failed";
|
|
53
|
+
readonly code: "plan.not_recorded";
|
|
54
|
+
readonly message: `The plan was not recorded: ${string}`;
|
|
55
|
+
readonly output?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
readonly code?: undefined;
|
|
58
|
+
readonly message?: undefined;
|
|
59
|
+
readonly kind: "completed";
|
|
60
|
+
readonly output: string;
|
|
61
|
+
}>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `update_plan` (A2A profile v2, `progress/v1`): the agent keeps its plan, a short list of steps
|
|
3
|
+
* with their states, which callers see while it works. Offered to the session's root agent when
|
|
4
|
+
* the version the session runs sets `harness.loop.plan: true` (`turn.start.loop.plan`; in an agent
|
|
5
|
+
* folder, `loop: { plan: true }` in `AGENT.md`). It runs here (`harness`): each call claims one
|
|
6
|
+
* durable `plan.updated` event with the whole plan, never a diff, over the Harness API's `event`
|
|
7
|
+
* request. A replayed call answers its recorded outcome and claims nothing again.
|
|
8
|
+
*
|
|
9
|
+
* Long input is cut, never refused: at most `PLAN_LIMITS.steps` steps (the first ones), a label of
|
|
10
|
+
* at most `labelChars` and a note of at most `noteChars`, each cut ending in `…`.
|
|
11
|
+
*/
|
|
12
|
+
import { PLAN_LIMITS, PLAN_STEP_STATES, } from "@nylorun/core/contracts";
|
|
13
|
+
import { HarnessApiError } from "@nylorun/core/harness-api";
|
|
14
|
+
/** The tool's name. */
|
|
15
|
+
export const UPDATE_PLAN_TOOL = "update_plan";
|
|
16
|
+
/** What a call answers. */
|
|
17
|
+
export const PLAN_UPDATED = "Plan updated";
|
|
18
|
+
const HARNESS = Object.freeze({ kind: "harness" });
|
|
19
|
+
const DESCRIPTION = [
|
|
20
|
+
"Keep your plan for this task: a short list of steps, each with a state, which the person or agent who asked sees while you work.",
|
|
21
|
+
"Pass the whole plan each time, never only the changes: the steps in order, each with a label (a few words) and a state (pending, active, done, blocked or skipped), and optionally a note (a short fact, such as why a step is blocked).",
|
|
22
|
+
`At most ${PLAN_LIMITS.steps} steps; a label is cut at ${PLAN_LIMITS.labelChars} characters and a note at ${PLAN_LIMITS.noteChars}.`,
|
|
23
|
+
"Never put tool arguments, results, secrets or file contents in a label or note.",
|
|
24
|
+
].join(" ");
|
|
25
|
+
const INPUT_SCHEMA = {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
steps: {
|
|
29
|
+
type: "array",
|
|
30
|
+
description: `The whole plan, in order: at most ${PLAN_LIMITS.steps} steps.`,
|
|
31
|
+
items: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
label: {
|
|
35
|
+
type: "string",
|
|
36
|
+
minLength: 1,
|
|
37
|
+
description: `What the step does, in a few words (at most ${PLAN_LIMITS.labelChars} characters).`,
|
|
38
|
+
},
|
|
39
|
+
state: { type: "string", enum: [...PLAN_STEP_STATES], description: "The step's state." },
|
|
40
|
+
note: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: `A short fact about the step (at most ${PLAN_LIMITS.noteChars} characters).`,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ["label", "state"],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["steps"],
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
};
|
|
53
|
+
const INSTRUCTIONS = "For work of several steps, keep your plan with update_plan: set it when you start, and call it again, with the whole plan, as each step starts, finishes or is blocked.";
|
|
54
|
+
/** The tool, and the text the model reads with it. */
|
|
55
|
+
export function planTool() {
|
|
56
|
+
return {
|
|
57
|
+
tool: {
|
|
58
|
+
name: UPDATE_PLAN_TOOL,
|
|
59
|
+
description: DESCRIPTION,
|
|
60
|
+
inputSchema: INPUT_SCHEMA,
|
|
61
|
+
target: HARNESS,
|
|
62
|
+
},
|
|
63
|
+
instructions: INSTRUCTIONS,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** True when `effect` is a call of `update_plan` (ours: a `harness` call). */
|
|
67
|
+
export function isPlanTool(effect) {
|
|
68
|
+
return effect.target?.kind === "harness" && effect.toolName === UPDATE_PLAN_TOOL;
|
|
69
|
+
}
|
|
70
|
+
/** `text` cut to at most `max` UTF-16 units, ending in `…` when cut, never inside a surrogate pair. */
|
|
71
|
+
export function cut(text, max) {
|
|
72
|
+
if (text.length <= max)
|
|
73
|
+
return text;
|
|
74
|
+
let end = max - 1;
|
|
75
|
+
const last = text.charCodeAt(end - 1);
|
|
76
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
77
|
+
end -= 1;
|
|
78
|
+
return `${text.slice(0, end)}…`;
|
|
79
|
+
}
|
|
80
|
+
const STATES = new Set(PLAN_STEP_STATES);
|
|
81
|
+
/** The plan a call's input states, cut to the limits; a string naming the problem when it is not one. */
|
|
82
|
+
export function planOf(input) {
|
|
83
|
+
const steps = input?.steps;
|
|
84
|
+
if (!Array.isArray(steps))
|
|
85
|
+
return "Give steps: the whole plan, as a list of { label, state, note? }.";
|
|
86
|
+
const plan = [];
|
|
87
|
+
for (const [index, raw] of steps.slice(0, PLAN_LIMITS.steps).entries()) {
|
|
88
|
+
const step = (raw ?? {});
|
|
89
|
+
const label = typeof step.label === "string" ? step.label.trim() : "";
|
|
90
|
+
if (label === "")
|
|
91
|
+
return `Step ${index + 1} has no label.`;
|
|
92
|
+
if (typeof step.state !== "string" || !STATES.has(step.state))
|
|
93
|
+
return `Step ${index + 1}'s state is one of ${PLAN_STEP_STATES.join(", ")}.`;
|
|
94
|
+
if (step.note !== undefined && typeof step.note !== "string")
|
|
95
|
+
return `Step ${index + 1}'s note is text.`;
|
|
96
|
+
const note = typeof step.note === "string" ? step.note.trim() : "";
|
|
97
|
+
plan.push({
|
|
98
|
+
label: cut(label, PLAN_LIMITS.labelChars),
|
|
99
|
+
state: step.state,
|
|
100
|
+
...(note === "" ? {} : { note: cut(note, PLAN_LIMITS.noteChars) }),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { steps: plan, dropped: Math.max(0, steps.length - PLAN_LIMITS.steps) };
|
|
104
|
+
}
|
|
105
|
+
/** Answers that say the run is no longer this harness's to go on with. */
|
|
106
|
+
const LOST = new Set(["ownership_lost", "run_not_held", "turn_cancelled"]);
|
|
107
|
+
/**
|
|
108
|
+
* Runs a call of `update_plan`: claims `plan.updated` with the whole plan for the run's turn, and
|
|
109
|
+
* answers `Plan updated`. A malformed plan, or a claim the Runtime refuses (one that does not
|
|
110
|
+
* know `plan.updated`), is a failed outcome the model sees; a run this harness no longer holds
|
|
111
|
+
* throws.
|
|
112
|
+
*/
|
|
113
|
+
export async function runPlanTool(effect, context) {
|
|
114
|
+
const plan = planOf(effect.input);
|
|
115
|
+
if (typeof plan === "string")
|
|
116
|
+
return { kind: "failed", code: "plan.invalid_input", message: plan };
|
|
117
|
+
const { channel, run, signal } = context;
|
|
118
|
+
try {
|
|
119
|
+
await channel.request("event", {
|
|
120
|
+
runId: run.runId,
|
|
121
|
+
sessionId: run.grant.sessionId,
|
|
122
|
+
turnId: run.grant.turnId,
|
|
123
|
+
type: "plan.updated",
|
|
124
|
+
payload: { steps: plan.steps },
|
|
125
|
+
}, signal);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (signal.aborted || !(error instanceof HarnessApiError) || LOST.has(error.code))
|
|
129
|
+
throw error;
|
|
130
|
+
return {
|
|
131
|
+
kind: "failed",
|
|
132
|
+
code: "plan.not_recorded",
|
|
133
|
+
message: `The plan was not recorded: ${error.message}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
kind: "completed",
|
|
138
|
+
output: plan.dropped === 0
|
|
139
|
+
? PLAN_UPDATED
|
|
140
|
+
: `${PLAN_UPDATED}: only the first ${PLAN_LIMITS.steps} steps were kept.`,
|
|
141
|
+
};
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nylorun/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0-beta",
|
|
4
4
|
"description": "Nylorun's TypeScript agent execution engine. See github.com/nylorun/agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"zod": "^4.6.7"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@nylorun/core": "0.
|
|
80
|
+
"@nylorun/core": "0.32.0-beta"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"zod": "^4.6.7"
|