@nylorun/core 0.33.0-beta → 0.34.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 +79 -0
- package/dist/compatibility.d.ts +17 -1
- package/dist/compatibility.js +16 -0
- package/dist/contracts.d.ts +438 -11
- package/dist/contracts.js +196 -16
- package/dist/define.d.ts +1 -1
- package/dist/define.js +1 -1
- package/dist/definition/assemble.d.ts +2 -1
- package/dist/definition/assemble.js +1 -0
- package/dist/definition/from.js +1 -0
- package/dist/definition/manifest.d.ts +2 -1
- package/dist/definition/manifest.js +1 -0
- package/dist/definition/sections.d.ts +1 -1
- package/dist/definition/sections.js +5 -1
- package/dist/definition/variant.d.ts +16 -1
- package/dist/definition/variant.js +81 -3
- package/dist/engine/blocks.d.ts +52 -0
- package/dist/engine/blocks.js +155 -0
- package/dist/engine/explain.d.ts +36 -0
- package/dist/engine/explain.js +108 -0
- package/dist/engine/features.d.ts +28 -0
- package/dist/engine/features.js +34 -0
- package/dist/engine/index.d.ts +14 -0
- package/dist/engine/index.js +14 -0
- package/dist/engine/mcp.d.ts +119 -0
- package/dist/engine/mcp.js +267 -0
- package/dist/engine/names.d.ts +12 -0
- package/dist/engine/names.js +25 -0
- package/dist/engine/preview.d.ts +88 -0
- package/dist/engine/preview.js +119 -0
- package/dist/engine/projection.d.ts +61 -0
- package/dist/engine/projection.js +100 -0
- package/dist/engine/tools.d.ts +108 -0
- package/dist/engine/tools.js +460 -0
- package/dist/folder/compile.d.ts +11 -4
- package/dist/folder/compile.js +123 -13
- package/dist/folder/context.d.ts +5 -0
- package/dist/folder/decompile.js +22 -1
- package/dist/folder/engine.d.ts +70 -0
- package/dist/folder/engine.js +210 -0
- package/dist/folder/nested.js +1 -0
- package/dist/folder/schemas.js +42 -3
- package/dist/harness-api/harness-api.schema.json +11 -4
- package/dist/harness-api/json-schema.js +5 -2
- package/dist/harness-api/messages.d.ts +4 -2
- package/dist/harness-api/messages.js +4 -1
- package/dist/harness-api/schema.d.ts +9 -4
- package/dist/harness-api/schema.js +11 -2
- package/dist/manifest-schemas.js +8 -4
- package/dist/schemas/agent-folder/agent-md.schema.json +79 -3
- package/dist/schemas/agent-folder/runtime.schema.json +13 -1
- package/dist/schemas/agent-manifest.schema.json +139 -1
- package/dist/schemas/harness-manifest.schema.json +124 -1
- package/dist/schemas/runtime-manifest.schema.json +13 -1
- package/dist/types/manifest.d.ts +47 -0
- package/package.json +5 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ARTIFACTS_READ_TEXT, ARTIFACTS_SAVE_TEXT, CONNECTION_TEXT, ENGINE_BLOCK_VERSIONS, MEMORY_DATA_RULE, MEMORY_READ_ONLY_DATA_RULE, OUTPUTS_AFTER_SAVE_TEXT, OUTPUTS_TEXT, PLAN_TEXT, SKILLS_USAGE, WAKE_TEXT, formatSkillCatalog, memoryRules, sandboxNote, skillFolderNote, } from "./blocks.js";
|
|
2
|
+
import { engineFeaturesOf } from "./features.js";
|
|
3
|
+
import { DEFAULT_SANDBOX_TOOL_LIMITS, REQUEST_CONNECTION_TOOL, UPDATE_PLAN_TOOL, artifactTools, connectionToolOf, memoryToolOf, planToolOf, sandboxTools, skillTools, wakeToolOf, } from "./tools.js";
|
|
4
|
+
/** The default of the harness's `artifactPageBytes` setting: one `read_artifact` page. */
|
|
5
|
+
export const DEFAULT_ARTIFACT_PAGE_BYTES = 32 * 1024;
|
|
6
|
+
/** The most bytes of one skill file the skill tools read into the model's context by default. */
|
|
7
|
+
export const DEFAULT_SKILL_READ_BYTES = 10 * 1024 * 1024;
|
|
8
|
+
/** Our engine's tool limits when the harness sets none. */
|
|
9
|
+
export const DEFAULT_ENGINE_TOOL_LIMITS = Object.freeze({
|
|
10
|
+
artifactPageBytes: DEFAULT_ARTIFACT_PAGE_BYTES,
|
|
11
|
+
sandboxTools: DEFAULT_SANDBOX_TOOL_LIMITS,
|
|
12
|
+
skillReadBytes: DEFAULT_SKILL_READ_BYTES,
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Our engine's tools and text for `agent`, in a session on Agent `runsOn` (`turn.start.agent`)
|
|
16
|
+
* with its memory (`turn.start.memory`). `memory.root` is false for an agent used as a tool,
|
|
17
|
+
* which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
|
|
18
|
+
* the version sets `harness.loop.plan`; `connections` offers `request_connection` alike
|
|
19
|
+
* (`harness.loop.connections`). An agent whose own tools name one of them keeps its own. What the
|
|
20
|
+
* agent declares (`agent.engine`) decides the rest; a block it replaces is in its words.
|
|
21
|
+
*/
|
|
22
|
+
export function engineProjection(agent, runsOn, options, memory, plan = false, connections = false) {
|
|
23
|
+
const skills = Object.values(agent.skills ?? {});
|
|
24
|
+
const workspace = runsOn?.sandbox?.workspace;
|
|
25
|
+
const features = engineFeaturesOf(agent.engine, { computer: workspace !== undefined });
|
|
26
|
+
const replaced = agent.engine?.instructions ?? {};
|
|
27
|
+
const sandboxed = features.sandbox.length > 0;
|
|
28
|
+
const instructions = [];
|
|
29
|
+
const blocks = [];
|
|
30
|
+
const use = (name) => blocks.push({ name, version: ENGINE_BLOCK_VERSIONS[name] });
|
|
31
|
+
const text = (name, engine) => replaced[name] ?? engine;
|
|
32
|
+
if (skills.length > 0) {
|
|
33
|
+
use("skills");
|
|
34
|
+
instructions.push(text("skills", SKILLS_USAGE), formatSkillCatalog(skills.map(({ name, description }) => ({ name, description }))));
|
|
35
|
+
}
|
|
36
|
+
if (sandboxed) {
|
|
37
|
+
use("sandbox");
|
|
38
|
+
instructions.push(text("sandbox", sandboxNote(workspace)));
|
|
39
|
+
if (skills.length > 0) {
|
|
40
|
+
use("skill_folder");
|
|
41
|
+
const own = replaced.skill_folder;
|
|
42
|
+
instructions.push(own === undefined ? skillFolderNote(skills) : `${own}\n${skillFolderNote(skills)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// The artifact notes: saving, the outputs folder, and reading.
|
|
46
|
+
const saving = features.artifactsSave ? text("artifacts_save", ARTIFACTS_SAVE_TEXT) : undefined;
|
|
47
|
+
const outputs = features.outputs ? text("outputs", saving === undefined ? OUTPUTS_TEXT : OUTPUTS_AFTER_SAVE_TEXT) : undefined;
|
|
48
|
+
if (saving !== undefined)
|
|
49
|
+
use("artifacts_save");
|
|
50
|
+
if (outputs !== undefined)
|
|
51
|
+
use("outputs");
|
|
52
|
+
if (saving !== undefined || outputs !== undefined)
|
|
53
|
+
instructions.push([saving, outputs].filter((item) => item !== undefined).join(" "));
|
|
54
|
+
if (features.artifactsRead) {
|
|
55
|
+
use("artifacts_read");
|
|
56
|
+
instructions.push(text("artifacts_read", ARTIFACTS_READ_TEXT));
|
|
57
|
+
}
|
|
58
|
+
// A session that may book its own next turn (track T4, D77).
|
|
59
|
+
const wake = runsOn?.selfWake === true;
|
|
60
|
+
if (wake) {
|
|
61
|
+
use("wake");
|
|
62
|
+
instructions.push(text("wake", WAKE_TEXT));
|
|
63
|
+
}
|
|
64
|
+
// The Agent's memory (track T5, D72).
|
|
65
|
+
const writes = memory !== undefined && memory.root && memory.access === "read_write";
|
|
66
|
+
if (memory) {
|
|
67
|
+
use("memory");
|
|
68
|
+
const own = replaced.memory;
|
|
69
|
+
// The rule that text from outside is data stays, whatever the folder's wording (ADR-100).
|
|
70
|
+
const rules = own === undefined ? memoryRules(writes, memory.index !== false) : `${own}\n${writes ? MEMORY_DATA_RULE : MEMORY_READ_ONLY_DATA_RULE}`;
|
|
71
|
+
instructions.push([rules, ...(memory.instructions ? [`Memory instructions for this agent:\n${memory.instructions}`] : [])].join("\n\n"));
|
|
72
|
+
}
|
|
73
|
+
// The agent's plan (A2A profile v2, `progress/v1`).
|
|
74
|
+
const own = (name) => (agent.tools ?? []).some((tool) => tool.name === name);
|
|
75
|
+
const planning = plan && !own(UPDATE_PLAN_TOOL);
|
|
76
|
+
if (planning) {
|
|
77
|
+
use("plan");
|
|
78
|
+
instructions.push(text("plan", PLAN_TEXT));
|
|
79
|
+
}
|
|
80
|
+
// The apps the agent asks to have connected (A2A profile v2, `interactions/v1` kind `connection`).
|
|
81
|
+
const connecting = connections && !own(REQUEST_CONNECTION_TOOL);
|
|
82
|
+
if (connecting) {
|
|
83
|
+
use("connection");
|
|
84
|
+
instructions.push(text("connection", CONNECTION_TEXT));
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
tools: [
|
|
88
|
+
...(sandboxed ? sandboxTools(options.sandboxTools, workspace, features.sandbox) : []),
|
|
89
|
+
...skillTools(skills),
|
|
90
|
+
...artifactTools({ read: features.artifactsRead, save: features.artifactsSave, sandboxed }, { pageBytes: options.artifactPageBytes }),
|
|
91
|
+
...(wake ? [wakeToolOf()] : []),
|
|
92
|
+
...(memory ? [memoryToolOf(writes)] : []),
|
|
93
|
+
...(planning ? [planToolOf()] : []),
|
|
94
|
+
...(connecting ? [connectionToolOf()] : []),
|
|
95
|
+
],
|
|
96
|
+
instructions,
|
|
97
|
+
blocks,
|
|
98
|
+
features,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type SandboxToolName } from "../utils/sandbox.js";
|
|
2
|
+
import type { JsonObject } from "../types/shared.js";
|
|
3
|
+
import type { SkillManifest } from "../types/manifest.js";
|
|
4
|
+
import type { EffectTarget } from "../harness-api/messages.js";
|
|
5
|
+
/**
|
|
6
|
+
* A tool our engine adds to an agent for one execution (one of our engine's own, a session's MCP
|
|
7
|
+
* tool). It is not part of the hashed manifest.
|
|
8
|
+
*/
|
|
9
|
+
export interface EngineTool {
|
|
10
|
+
/** The agent used as a tool that owns this tool; absent for the root agent. */
|
|
11
|
+
readonly agentId?: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly inputSchema: JsonObject;
|
|
15
|
+
readonly outputSchema?: JsonObject;
|
|
16
|
+
/**
|
|
17
|
+
* Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
|
|
18
|
+
* with `tool_call`, which makes the call as this tool's own.
|
|
19
|
+
*/
|
|
20
|
+
readonly deferred?: boolean;
|
|
21
|
+
/** Text the model reads, after the engine's, while this tool is advertised. */
|
|
22
|
+
readonly instructions?: readonly string[];
|
|
23
|
+
/** What runs its calls: their effects' `target` (an MCP tool's identity, our engine's `harness`). */
|
|
24
|
+
readonly target?: EffectTarget;
|
|
25
|
+
}
|
|
26
|
+
/** What the sandbox tools hold a call to: the harness's configuration of them. */
|
|
27
|
+
export interface SandboxToolLimits {
|
|
28
|
+
/** The characters of `bash` stdout and stderr each keeps, its middle cut past it. */
|
|
29
|
+
readonly outputChars: number;
|
|
30
|
+
/** Seconds a `bash` command runs when it names no `timeout`. */
|
|
31
|
+
readonly defaultTimeoutS: number;
|
|
32
|
+
/** The longest `timeout` a `bash` command may name, in seconds. */
|
|
33
|
+
readonly maxTimeoutS: number;
|
|
34
|
+
/** Lines `read` returns when it names no `limit`. */
|
|
35
|
+
readonly readLines: number;
|
|
36
|
+
/** The most lines one `read` may ask for. */
|
|
37
|
+
readonly maxReadLines: number;
|
|
38
|
+
/** The characters of one line `read` and `grep` show, the rest cut. */
|
|
39
|
+
readonly lineChars: number;
|
|
40
|
+
/** Matches `grep` returns when it names no `max_results`. */
|
|
41
|
+
readonly grepResults: number;
|
|
42
|
+
/** The most matches one `grep` may ask for. */
|
|
43
|
+
readonly maxGrepResults: number;
|
|
44
|
+
/** The most paths `glob` returns. */
|
|
45
|
+
readonly globResults: number;
|
|
46
|
+
/** The most files `glob` looks through. */
|
|
47
|
+
readonly globScan: number;
|
|
48
|
+
}
|
|
49
|
+
/** The sandbox tools' limits when the harness sets none. */
|
|
50
|
+
export declare const DEFAULT_SANDBOX_TOOL_LIMITS: SandboxToolLimits;
|
|
51
|
+
/** The limits in force: `set`, with the default for each it leaves out. */
|
|
52
|
+
export declare function sandboxToolLimitsOf(set?: Partial<SandboxToolLimits>): SandboxToolLimits;
|
|
53
|
+
/**
|
|
54
|
+
* The sandbox tools, in the order the model reads them, with `workspace` named in their text
|
|
55
|
+
* and `limits` in their schemas: all six, or those `names` lists (ADR-100, `engine.sandbox`),
|
|
56
|
+
* still in our order. Each is a `sandbox` effect named by its operation.
|
|
57
|
+
*/
|
|
58
|
+
export declare function sandboxTools(limits: SandboxToolLimits, workspace: string, names?: readonly SandboxToolName[]): EngineTool[];
|
|
59
|
+
/** `save_artifact` (with `save`) and `read_artifact` (with `read`), which takes `path` with a sandbox. */
|
|
60
|
+
export declare function artifactTools(offer: {
|
|
61
|
+
readonly read: boolean;
|
|
62
|
+
readonly save: boolean;
|
|
63
|
+
readonly sandboxed: boolean;
|
|
64
|
+
}, options: {
|
|
65
|
+
readonly pageBytes: number;
|
|
66
|
+
}): EngineTool[];
|
|
67
|
+
/** Loads a skill's `SKILL.md`. */
|
|
68
|
+
export declare const LOAD_SKILL_TOOL = "load_skill";
|
|
69
|
+
/** Reads one resource file of a skill. */
|
|
70
|
+
export declare const READ_SKILL_RESOURCE_TOOL = "read_skill_resource";
|
|
71
|
+
/**
|
|
72
|
+
* `load_skill` for the agent's skills, and `read_skill_resource` when a skill has files besides
|
|
73
|
+
* `SKILL.md`. Empty for an agent without skills. Each runs in the harness.
|
|
74
|
+
*/
|
|
75
|
+
export declare function skillTools(skills: readonly SkillManifest[]): EngineTool[];
|
|
76
|
+
/** The memory tool's name. */
|
|
77
|
+
export declare const MEMORY_TOOL = "memory";
|
|
78
|
+
/** `memory`: view, and the writes when the agent may write. A `runtime` effect, operation `memory`. */
|
|
79
|
+
export declare function memoryToolOf(writes: boolean): EngineTool;
|
|
80
|
+
/** The self-wake tool's name. */
|
|
81
|
+
export declare const SCHEDULE_WAKE_TOOL = "schedule_wake";
|
|
82
|
+
/** `schedule_wake` (track T4): a `runtime` effect. */
|
|
83
|
+
export declare function wakeToolOf(): EngineTool;
|
|
84
|
+
/** The plan tool's name. */
|
|
85
|
+
export declare const UPDATE_PLAN_TOOL = "update_plan";
|
|
86
|
+
/** `update_plan` (A2A profile v2, `progress/v1`): runs in the harness. */
|
|
87
|
+
export declare function planToolOf(): EngineTool;
|
|
88
|
+
/** The connection tool's name. */
|
|
89
|
+
export declare const REQUEST_CONNECTION_TOOL = "request_connection";
|
|
90
|
+
/** The most characters of the app's name and of the reason. */
|
|
91
|
+
export declare const CONNECTION_LIMITS: Readonly<{
|
|
92
|
+
appChars: 80;
|
|
93
|
+
reasonChars: 280;
|
|
94
|
+
}>;
|
|
95
|
+
/** `request_connection` (A2A profile v2, `interactions/v1` kind `connection`): runs in the harness. */
|
|
96
|
+
export declare function connectionToolOf(): EngineTool;
|
|
97
|
+
/** Finds deferred tools by a query (BM25 over their names and descriptions). */
|
|
98
|
+
export declare const TOOL_SEARCH_TOOL = "tool_search";
|
|
99
|
+
/** Runs a deferred tool by name, as a call of that tool. */
|
|
100
|
+
export declare const TOOL_CALL_TOOL = "tool_call";
|
|
101
|
+
/**
|
|
102
|
+
* `tool_search` (ours, `harness`) and `tool_call`, as our engine gives them to an agent with
|
|
103
|
+
* deferred tools. `tool_call` makes the effect of the tool it names; it is never one itself.
|
|
104
|
+
*/
|
|
105
|
+
export declare function deferredToolsTools(config: {
|
|
106
|
+
readonly toolSearchDefaultLimit: number;
|
|
107
|
+
readonly toolSearchMaxLimit: number;
|
|
108
|
+
}): readonly EngineTool[];
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Our engine's own tools as the model reads them (protocol 15, ADR-100): each tool's name,
|
|
3
|
+
* description, input schema and the effect its calls make. Our harness runs them
|
|
4
|
+
* (`@nylorun/harness`); the compiler and the SDK's `previewTurn` read the same definitions, so
|
|
5
|
+
* what a preview shows is what a session is offered. Their schemas reach the model: change them
|
|
6
|
+
* deliberately.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { ARTIFACT_NAME_MAX, PLAN_LIMITS, PLAN_STEP_STATES } from "../contracts.js";
|
|
10
|
+
import { MEMORY_ROOT } from "../utils/memory.js";
|
|
11
|
+
import { SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
12
|
+
import { SKILL_ENTRY } from "../utils/definition-files.js";
|
|
13
|
+
import { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL } from "../utils/runtime-tools.js";
|
|
14
|
+
import { tool } from "../definition/helpers.js";
|
|
15
|
+
import { normalizedSchemasFor } from "../definition/schema.js";
|
|
16
|
+
import { ToolError } from "../definition/tool-error.js";
|
|
17
|
+
const SCHEMA = "http://json-schema.org/draft-07/schema#";
|
|
18
|
+
const HARNESS = Object.freeze({ kind: "harness" });
|
|
19
|
+
const SANDBOX = Object.freeze({ kind: "sandbox" });
|
|
20
|
+
/** The sandbox tools' limits when the harness sets none. */
|
|
21
|
+
export const DEFAULT_SANDBOX_TOOL_LIMITS = Object.freeze({
|
|
22
|
+
outputChars: 30_000,
|
|
23
|
+
defaultTimeoutS: 120,
|
|
24
|
+
maxTimeoutS: 600,
|
|
25
|
+
readLines: 2000,
|
|
26
|
+
maxReadLines: 5000,
|
|
27
|
+
lineChars: 2000,
|
|
28
|
+
grepResults: 200,
|
|
29
|
+
maxGrepResults: 1000,
|
|
30
|
+
globResults: 500,
|
|
31
|
+
globScan: 20_000,
|
|
32
|
+
});
|
|
33
|
+
/** The limits in force: `set`, with the default for each it leaves out. */
|
|
34
|
+
export function sandboxToolLimitsOf(set) {
|
|
35
|
+
return Object.freeze({ ...DEFAULT_SANDBOX_TOOL_LIMITS, ...definedOf(set ?? {}) });
|
|
36
|
+
}
|
|
37
|
+
const object = (properties, required) => ({
|
|
38
|
+
$schema: SCHEMA,
|
|
39
|
+
type: "object",
|
|
40
|
+
properties,
|
|
41
|
+
required: [...required],
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
});
|
|
44
|
+
const pathField = { type: "string", minLength: 1 };
|
|
45
|
+
/**
|
|
46
|
+
* The sandbox tools, in the order the model reads them, with `workspace` named in their text
|
|
47
|
+
* and `limits` in their schemas: all six, or those `names` lists (ADR-100, `engine.sandbox`),
|
|
48
|
+
* still in our order. Each is a `sandbox` effect named by its operation.
|
|
49
|
+
*/
|
|
50
|
+
export function sandboxTools(limits, workspace, names = SANDBOX_TOOL_NAMES) {
|
|
51
|
+
const relative = `Relative paths resolve under ${workspace}.`;
|
|
52
|
+
const tools = [
|
|
53
|
+
{
|
|
54
|
+
name: "bash",
|
|
55
|
+
description: `Run a bash command in the sandbox. The working directory is ${workspace}. ` +
|
|
56
|
+
"Returns exitCode, stdout and stderr; a non-zero exit code is a normal result, not an error. " +
|
|
57
|
+
"Long output is truncated in the middle.",
|
|
58
|
+
inputSchema: object({
|
|
59
|
+
command: { type: "string", minLength: 1, description: "The command line to run with bash." },
|
|
60
|
+
timeout: {
|
|
61
|
+
description: `Seconds before the command is killed. Default ${limits.defaultTimeoutS}, maximum ${limits.maxTimeoutS}.`,
|
|
62
|
+
type: "integer",
|
|
63
|
+
minimum: 1,
|
|
64
|
+
maximum: limits.maxTimeoutS,
|
|
65
|
+
},
|
|
66
|
+
}, ["command"]),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "read",
|
|
70
|
+
description: `Read a text file from the sandbox. ${relative} Returns numbered lines. ` +
|
|
71
|
+
"Use offset and limit to page through large files.",
|
|
72
|
+
inputSchema: object({
|
|
73
|
+
path: pathField,
|
|
74
|
+
offset: {
|
|
75
|
+
description: "First line to return, 1-based.",
|
|
76
|
+
type: "integer",
|
|
77
|
+
minimum: 1,
|
|
78
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
79
|
+
},
|
|
80
|
+
limit: {
|
|
81
|
+
description: `Maximum number of lines. Default ${limits.readLines}.`,
|
|
82
|
+
type: "integer",
|
|
83
|
+
minimum: 1,
|
|
84
|
+
maximum: limits.maxReadLines,
|
|
85
|
+
},
|
|
86
|
+
}, ["path"]),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "write",
|
|
90
|
+
description: `Create or overwrite a text file in the sandbox. ${relative} Parent directories are created.`,
|
|
91
|
+
inputSchema: object({ path: pathField, content: { type: "string" } }, ["path", "content"]),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "edit",
|
|
95
|
+
description: `Replace text in a sandbox file. ${relative} old_string must match exactly and be unique ` +
|
|
96
|
+
"unless replace_all is true.",
|
|
97
|
+
inputSchema: object({
|
|
98
|
+
path: pathField,
|
|
99
|
+
old_string: { type: "string", minLength: 1 },
|
|
100
|
+
new_string: { type: "string" },
|
|
101
|
+
replace_all: { type: "boolean" },
|
|
102
|
+
}, ["path", "old_string", "new_string"]),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "grep",
|
|
106
|
+
description: `Search file contents in the sandbox with an extended regular expression. ${relative} ` +
|
|
107
|
+
"Returns matching lines as path:line:text.",
|
|
108
|
+
inputSchema: object({
|
|
109
|
+
pattern: { type: "string", minLength: 1 },
|
|
110
|
+
path: { description: `Directory or file to search. Default ${workspace}.`, ...pathField },
|
|
111
|
+
glob: { description: 'Only search files whose name matches, e.g. "*.py".', ...pathField },
|
|
112
|
+
ignore_case: { type: "boolean" },
|
|
113
|
+
max_results: {
|
|
114
|
+
description: `Default ${limits.grepResults}.`,
|
|
115
|
+
type: "integer",
|
|
116
|
+
minimum: 1,
|
|
117
|
+
maximum: limits.maxGrepResults,
|
|
118
|
+
},
|
|
119
|
+
}, ["pattern"]),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "glob",
|
|
123
|
+
description: `Find files in the sandbox by glob pattern, e.g. "**/*.csv". ${relative} Returns matching paths.`,
|
|
124
|
+
inputSchema: object({
|
|
125
|
+
pattern: { type: "string", minLength: 1 },
|
|
126
|
+
path: { description: `Directory to search. Default ${workspace}.`, ...pathField },
|
|
127
|
+
}, ["pattern"]),
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
return tools.filter((item) => names.includes(item.name)).map((item) => ({ ...item, target: SANDBOX }));
|
|
131
|
+
}
|
|
132
|
+
// --- The artifact tools ----------------------------------------------------------------------
|
|
133
|
+
const SAVE_DESCRIPTION = `Save a file as an artifact of this session, for the user to download. Give path (a file in the sandbox; relative paths resolve under ${SANDBOX_WORKSPACE}) or content (text), not both. ` +
|
|
134
|
+
"Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.";
|
|
135
|
+
const SAVE_SCHEMA = {
|
|
136
|
+
$schema: SCHEMA,
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
path: { description: "A file in the sandbox.", type: "string", minLength: 1 },
|
|
140
|
+
content: { description: "Text to save instead of a file.", type: "string" },
|
|
141
|
+
name: {
|
|
142
|
+
description: "The artifact's name. Default: the file's name.",
|
|
143
|
+
type: "string",
|
|
144
|
+
minLength: 1,
|
|
145
|
+
maxLength: ARTIFACT_NAME_MAX,
|
|
146
|
+
},
|
|
147
|
+
contentType: {
|
|
148
|
+
description: "The media type, e.g. image/png. Default: from the name's extension.",
|
|
149
|
+
type: "string",
|
|
150
|
+
minLength: 1,
|
|
151
|
+
},
|
|
152
|
+
artifactId: { description: "Save a new version of this artifact.", type: "string", minLength: 1 },
|
|
153
|
+
},
|
|
154
|
+
additionalProperties: false,
|
|
155
|
+
};
|
|
156
|
+
function readDescription(pageBytes, sandboxed) {
|
|
157
|
+
return (`Read an artifact of this session, such as a tool result marked truncated or a file from an earlier turn. A text file returns up to ${pageBytes} bytes from offset, ` +
|
|
158
|
+
"with nextOffset while more remains: pass it as offset to read on. An image or another file you can read is shown to you." +
|
|
159
|
+
(sandboxed
|
|
160
|
+
? ` Pass path to copy the whole artifact into the sandbox instead (relative paths resolve under ${SANDBOX_WORKSPACE}), for a command to use.`
|
|
161
|
+
: ""));
|
|
162
|
+
}
|
|
163
|
+
function readSchema(pageBytes, sandboxed) {
|
|
164
|
+
return {
|
|
165
|
+
$schema: SCHEMA,
|
|
166
|
+
type: "object",
|
|
167
|
+
properties: {
|
|
168
|
+
artifactId: { type: "string", minLength: 1, description: "The artifact to read, e.g. a truncated result's artifactId." },
|
|
169
|
+
version: {
|
|
170
|
+
description: "The version to read. Default: the latest.",
|
|
171
|
+
type: "integer",
|
|
172
|
+
minimum: 1,
|
|
173
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
174
|
+
},
|
|
175
|
+
offset: {
|
|
176
|
+
description: "The byte to start at. Default 0.",
|
|
177
|
+
type: "integer",
|
|
178
|
+
minimum: 0,
|
|
179
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
180
|
+
},
|
|
181
|
+
length: {
|
|
182
|
+
description: `How many bytes to read. Default and most: ${pageBytes}.`,
|
|
183
|
+
type: "integer",
|
|
184
|
+
minimum: 1,
|
|
185
|
+
maximum: pageBytes,
|
|
186
|
+
},
|
|
187
|
+
...(sandboxed
|
|
188
|
+
? {
|
|
189
|
+
path: {
|
|
190
|
+
description: "Copy the artifact to this file in the sandbox instead of reading it.",
|
|
191
|
+
type: "string",
|
|
192
|
+
minLength: 1,
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
: {}),
|
|
196
|
+
},
|
|
197
|
+
required: ["artifactId"],
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** `save_artifact` (with `save`) and `read_artifact` (with `read`), which takes `path` with a sandbox. */
|
|
202
|
+
export function artifactTools(offer, options) {
|
|
203
|
+
return [
|
|
204
|
+
...(offer.save ? [{ name: SAVE_ARTIFACT_TOOL, description: SAVE_DESCRIPTION, inputSchema: SAVE_SCHEMA, target: HARNESS }] : []),
|
|
205
|
+
...(offer.read
|
|
206
|
+
? [
|
|
207
|
+
{
|
|
208
|
+
name: READ_ARTIFACT_TOOL,
|
|
209
|
+
description: readDescription(options.pageBytes, offer.sandboxed),
|
|
210
|
+
inputSchema: readSchema(options.pageBytes, offer.sandboxed),
|
|
211
|
+
target: HARNESS,
|
|
212
|
+
},
|
|
213
|
+
]
|
|
214
|
+
: []),
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
// --- The skill tools -------------------------------------------------------------------------
|
|
218
|
+
/** Loads a skill's `SKILL.md`. */
|
|
219
|
+
export const LOAD_SKILL_TOOL = "load_skill";
|
|
220
|
+
/** Reads one resource file of a skill. */
|
|
221
|
+
export const READ_SKILL_RESOURCE_TOOL = "read_skill_resource";
|
|
222
|
+
/**
|
|
223
|
+
* `load_skill` for the agent's skills, and `read_skill_resource` when a skill has files besides
|
|
224
|
+
* `SKILL.md`. Empty for an agent without skills. Each runs in the harness.
|
|
225
|
+
*/
|
|
226
|
+
export function skillTools(skills) {
|
|
227
|
+
if (skills.length === 0)
|
|
228
|
+
return [];
|
|
229
|
+
const names = skills.map((skill) => skill.name).sort();
|
|
230
|
+
const name = names.length === 1 ? { type: "string", const: names[0] } : { type: "string", enum: names };
|
|
231
|
+
const tools = [
|
|
232
|
+
{
|
|
233
|
+
name: LOAD_SKILL_TOOL,
|
|
234
|
+
description: "Load the full instructions for a named skill. Call this before following a skill.",
|
|
235
|
+
inputSchema: { $schema: SCHEMA, type: "object", properties: { name }, required: ["name"], additionalProperties: false },
|
|
236
|
+
target: HARNESS,
|
|
237
|
+
},
|
|
238
|
+
];
|
|
239
|
+
if (skills.some((skill) => Object.keys(skill.files).some((path) => path !== SKILL_ENTRY)))
|
|
240
|
+
tools.push({
|
|
241
|
+
name: READ_SKILL_RESOURCE_TOOL,
|
|
242
|
+
description: "Read one text resource from a skill after load_skill.",
|
|
243
|
+
inputSchema: {
|
|
244
|
+
$schema: SCHEMA,
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: { name, path: { type: "string", minLength: 1 } },
|
|
247
|
+
required: ["name", "path"],
|
|
248
|
+
additionalProperties: false,
|
|
249
|
+
},
|
|
250
|
+
target: HARNESS,
|
|
251
|
+
});
|
|
252
|
+
return tools;
|
|
253
|
+
}
|
|
254
|
+
// --- memory ----------------------------------------------------------------------------------
|
|
255
|
+
/** The memory tool's name. */
|
|
256
|
+
export const MEMORY_TOOL = "memory";
|
|
257
|
+
const RUNTIME_MEMORY = Object.freeze({ kind: "runtime", operation: "memory" });
|
|
258
|
+
const MEMORY_WRITES = ["create", "str_replace", "insert", "delete", "rename"];
|
|
259
|
+
/** `memory`: view, and the writes when the agent may write. A `runtime` effect, operation `memory`. */
|
|
260
|
+
export function memoryToolOf(writes) {
|
|
261
|
+
return {
|
|
262
|
+
name: MEMORY_TOOL,
|
|
263
|
+
description: [
|
|
264
|
+
`Read${writes ? " and edit" : ""} your persistent memory directory, ${MEMORY_ROOT}. Files there survive across sessions.`,
|
|
265
|
+
"Commands:",
|
|
266
|
+
"- view: show a directory listing, or a file's contents with line numbers. Params: path, optional view_range [start, end] (end -1 means to the end).",
|
|
267
|
+
...(writes
|
|
268
|
+
? [
|
|
269
|
+
"- create: create a file, or replace an existing one. Params: path, file_text.",
|
|
270
|
+
"- str_replace: replace text that appears exactly once in a file. Params: path, old_str, new_str (omit new_str to delete old_str).",
|
|
271
|
+
"- insert: insert text after a line number (0 inserts at the top). Params: path, insert_line, insert_text.",
|
|
272
|
+
"- delete: delete a file or directory. Params: path.",
|
|
273
|
+
"- rename: rename or move a file or directory; never overwrites. Params: old_path, new_path.",
|
|
274
|
+
]
|
|
275
|
+
: []),
|
|
276
|
+
`All paths are under ${MEMORY_ROOT} and memory files end in .md.`,
|
|
277
|
+
].join("\n"),
|
|
278
|
+
inputSchema: {
|
|
279
|
+
type: "object",
|
|
280
|
+
properties: {
|
|
281
|
+
command: { type: "string", enum: writes ? ["view", ...MEMORY_WRITES] : ["view"], description: "The operation to perform." },
|
|
282
|
+
path: {
|
|
283
|
+
type: "string",
|
|
284
|
+
description: writes ? `Path under ${MEMORY_ROOT}. Used by view, create, str_replace, insert and delete.` : `Path under ${MEMORY_ROOT}.`,
|
|
285
|
+
},
|
|
286
|
+
view_range: {
|
|
287
|
+
type: "array",
|
|
288
|
+
items: { type: "integer" },
|
|
289
|
+
minItems: 2,
|
|
290
|
+
maxItems: 2,
|
|
291
|
+
description: "view only: [start_line, end_line], 1-indexed; end_line -1 means to the end.",
|
|
292
|
+
},
|
|
293
|
+
...(writes
|
|
294
|
+
? {
|
|
295
|
+
file_text: { type: "string", description: "create only: the full file contents." },
|
|
296
|
+
old_str: { type: "string", description: "str_replace only: text that appears exactly once in the file." },
|
|
297
|
+
new_str: { type: "string", description: "str_replace only: the replacement text." },
|
|
298
|
+
insert_line: { type: "integer", description: "insert only: insert after this line; 0 inserts at the top." },
|
|
299
|
+
insert_text: { type: "string", description: "insert only: the text to insert." },
|
|
300
|
+
old_path: { type: "string", description: "rename only: the current path." },
|
|
301
|
+
new_path: { type: "string", description: "rename only: the new path." },
|
|
302
|
+
}
|
|
303
|
+
: {}),
|
|
304
|
+
},
|
|
305
|
+
required: ["command"],
|
|
306
|
+
additionalProperties: false,
|
|
307
|
+
},
|
|
308
|
+
target: RUNTIME_MEMORY,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// --- schedule_wake ---------------------------------------------------------------------------
|
|
312
|
+
/** The self-wake tool's name. */
|
|
313
|
+
export const SCHEDULE_WAKE_TOOL = "schedule_wake";
|
|
314
|
+
const RUNTIME_WAKE = Object.freeze({ kind: "runtime", operation: "schedule_wake" });
|
|
315
|
+
/** `schedule_wake` (track T4): a `runtime` effect. */
|
|
316
|
+
export function wakeToolOf() {
|
|
317
|
+
return {
|
|
318
|
+
name: SCHEDULE_WAKE_TOOL,
|
|
319
|
+
description: "Book this session's next turn for later, when nobody may be here to ask: give `in` (a duration such as 30m, 2h or 1d) or `at` (an RFC 3339 time with an offset), and a `note` that will be your message at that turn. A session holds one booking: a new one replaces it, and `cancel: true` removes it. Returns when it is booked for.",
|
|
320
|
+
inputSchema: {
|
|
321
|
+
type: "object",
|
|
322
|
+
properties: {
|
|
323
|
+
in: { type: "string", pattern: "^[1-9][0-9]*(s|m|h|d)$", description: "How long from now: 30m, 2h, 1d." },
|
|
324
|
+
at: { type: "string", description: "An RFC 3339 time with an offset, such as 2026-11-01T09:00:00+05:30." },
|
|
325
|
+
note: { type: "string", minLength: 1, description: "What to do then, in your own words: your message at that turn." },
|
|
326
|
+
cancel: { type: "boolean", description: "Remove the session's booking instead." },
|
|
327
|
+
},
|
|
328
|
+
additionalProperties: false,
|
|
329
|
+
},
|
|
330
|
+
target: RUNTIME_WAKE,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
// --- update_plan -----------------------------------------------------------------------------
|
|
334
|
+
/** The plan tool's name. */
|
|
335
|
+
export const UPDATE_PLAN_TOOL = "update_plan";
|
|
336
|
+
/** `update_plan` (A2A profile v2, `progress/v1`): runs in the harness. */
|
|
337
|
+
export function planToolOf() {
|
|
338
|
+
return {
|
|
339
|
+
name: UPDATE_PLAN_TOOL,
|
|
340
|
+
description: [
|
|
341
|
+
"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.",
|
|
342
|
+
"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).",
|
|
343
|
+
`At most ${PLAN_LIMITS.steps} steps; a label is cut at ${PLAN_LIMITS.labelChars} characters and a note at ${PLAN_LIMITS.noteChars}.`,
|
|
344
|
+
"Never put tool arguments, results, secrets or file contents in a label or note.",
|
|
345
|
+
].join(" "),
|
|
346
|
+
inputSchema: {
|
|
347
|
+
type: "object",
|
|
348
|
+
properties: {
|
|
349
|
+
steps: {
|
|
350
|
+
type: "array",
|
|
351
|
+
description: `The whole plan, in order: at most ${PLAN_LIMITS.steps} steps.`,
|
|
352
|
+
items: {
|
|
353
|
+
type: "object",
|
|
354
|
+
properties: {
|
|
355
|
+
label: {
|
|
356
|
+
type: "string",
|
|
357
|
+
minLength: 1,
|
|
358
|
+
description: `What the step does, in a few words (at most ${PLAN_LIMITS.labelChars} characters).`,
|
|
359
|
+
},
|
|
360
|
+
state: { type: "string", enum: [...PLAN_STEP_STATES], description: "The step's state." },
|
|
361
|
+
note: { type: "string", description: `A short fact about the step (at most ${PLAN_LIMITS.noteChars} characters).` },
|
|
362
|
+
},
|
|
363
|
+
required: ["label", "state"],
|
|
364
|
+
additionalProperties: false,
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
required: ["steps"],
|
|
369
|
+
additionalProperties: false,
|
|
370
|
+
},
|
|
371
|
+
target: HARNESS,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
// --- request_connection ----------------------------------------------------------------------
|
|
375
|
+
/** The connection tool's name. */
|
|
376
|
+
export const REQUEST_CONNECTION_TOOL = "request_connection";
|
|
377
|
+
/** The most characters of the app's name and of the reason. */
|
|
378
|
+
export const CONNECTION_LIMITS = Object.freeze({ appChars: 80, reasonChars: 280 });
|
|
379
|
+
/** `request_connection` (A2A profile v2, `interactions/v1` kind `connection`): runs in the harness. */
|
|
380
|
+
export function connectionToolOf() {
|
|
381
|
+
return {
|
|
382
|
+
name: REQUEST_CONNECTION_TOOL,
|
|
383
|
+
description: [
|
|
384
|
+
"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.",
|
|
385
|
+
"Give the app's name and the reason, in a sentence they can act on.",
|
|
386
|
+
"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.",
|
|
387
|
+
"Use it only when a tool says the app is not connected or its credential is missing; never to ask anything else.",
|
|
388
|
+
].join(" "),
|
|
389
|
+
inputSchema: {
|
|
390
|
+
type: "object",
|
|
391
|
+
properties: {
|
|
392
|
+
app: {
|
|
393
|
+
type: "string",
|
|
394
|
+
minLength: 1,
|
|
395
|
+
description: `The app to connect, by its name (at most ${CONNECTION_LIMITS.appChars} characters).`,
|
|
396
|
+
},
|
|
397
|
+
reason: {
|
|
398
|
+
type: "string",
|
|
399
|
+
minLength: 1,
|
|
400
|
+
description: `Why you need it, in a sentence (at most ${CONNECTION_LIMITS.reasonChars} characters).`,
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
required: ["app", "reason"],
|
|
404
|
+
additionalProperties: false,
|
|
405
|
+
},
|
|
406
|
+
target: HARNESS,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
// --- tool_search and tool_call ---------------------------------------------------------------
|
|
410
|
+
/** Finds deferred tools by a query (BM25 over their names and descriptions). */
|
|
411
|
+
export const TOOL_SEARCH_TOOL = "tool_search";
|
|
412
|
+
/** Runs a deferred tool by name, as a call of that tool. */
|
|
413
|
+
export const TOOL_CALL_TOOL = "tool_call";
|
|
414
|
+
async function runsInHarness() {
|
|
415
|
+
throw new ToolError("tools.runtime-only", "tool_search and tool_call run in Nylorun's harness. Connect the agent to a Runtime to use them.");
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* `tool_search` (ours, `harness`) and `tool_call`, as our engine gives them to an agent with
|
|
419
|
+
* deferred tools. `tool_call` makes the effect of the tool it names; it is never one itself.
|
|
420
|
+
*/
|
|
421
|
+
export function deferredToolsTools(config) {
|
|
422
|
+
const search = tool({
|
|
423
|
+
name: TOOL_SEARCH_TOOL,
|
|
424
|
+
description: "Search the tools not in your tool list by name and description. Returns the best matches, each with its name, description and inputSchema. Run one with tool_call.",
|
|
425
|
+
inputSchema: z.object({
|
|
426
|
+
query: z.string().min(1).describe("Words of what the tool does, or of its name."),
|
|
427
|
+
limit: z
|
|
428
|
+
.number()
|
|
429
|
+
.int()
|
|
430
|
+
.min(1)
|
|
431
|
+
.max(config.toolSearchMaxLimit)
|
|
432
|
+
.optional()
|
|
433
|
+
.describe(`How many tools to return. Default ${config.toolSearchDefaultLimit}.`),
|
|
434
|
+
}),
|
|
435
|
+
effects: "read",
|
|
436
|
+
execute: runsInHarness,
|
|
437
|
+
});
|
|
438
|
+
const call = tool({
|
|
439
|
+
name: TOOL_CALL_TOOL,
|
|
440
|
+
description: "Run a tool tool_search found, by its name. arguments must match that tool's inputSchema; the result is the tool's own.",
|
|
441
|
+
inputSchema: z.object({
|
|
442
|
+
name: z.string().min(1).describe("The tool's name, as tool_search returned it."),
|
|
443
|
+
arguments: z.record(z.string(), z.unknown()).optional().describe("The tool's arguments, matching its inputSchema. Default {}."),
|
|
444
|
+
}),
|
|
445
|
+
effects: "write",
|
|
446
|
+
execute: runsInHarness,
|
|
447
|
+
});
|
|
448
|
+
return [search, call].map((item, index) => {
|
|
449
|
+
const schemas = normalizedSchemasFor(item);
|
|
450
|
+
const manifest = {
|
|
451
|
+
name: item.name,
|
|
452
|
+
...(item.description === undefined ? {} : { description: item.description }),
|
|
453
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
454
|
+
};
|
|
455
|
+
return index === 0 ? { ...manifest, target: HARNESS } : manifest;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
function definedOf(value) {
|
|
459
|
+
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
|
|
460
|
+
}
|