@nylorun/agents 0.14.0-beta → 0.16.1-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 +121 -0
- package/README.md +223 -128
- package/dist/access.d.ts +6 -26
- package/dist/access.js +1 -26
- package/dist/files.d.ts +31 -0
- package/dist/files.js +60 -0
- package/dist/http.d.ts +0 -5
- package/dist/http.js +0 -8
- package/dist/index.d.ts +8 -13
- package/dist/index.js +4 -6
- package/dist/plugins/load.d.ts +3 -2
- package/dist/plugins/load.js +40 -100
- package/dist/plugins/plugin.d.ts +6 -1
- package/dist/plugins/plugin.js +20 -7
- package/dist/reads.d.ts +17 -0
- package/dist/reads.js +17 -0
- package/dist/sandboxes.d.ts +29 -0
- package/dist/sandboxes.js +10 -1
- package/dist/session-client.d.ts +91 -114
- package/dist/session-client.js +79 -109
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/load.d.ts +14 -3
- package/dist/skills/load.js +50 -32
- package/dist/skills/skills.d.ts +6 -4
- package/dist/skills/skills.js +17 -10
- package/package.json +3 -3
- package/dist/action-handler.d.ts +0 -63
- package/dist/action-handler.js +0 -279
- package/dist/delivery-token.d.ts +0 -62
- package/dist/delivery-token.js +0 -159
- package/dist/execute-action.d.ts +0 -16
- package/dist/execute-action.js +0 -288
- package/dist/plugins/launch.d.ts +0 -17
- package/dist/plugins/launch.js +0 -71
- package/dist/sandbox/client.d.ts +0 -63
- package/dist/sandbox/client.js +0 -29
- package/dist/sandbox/index.d.ts +0 -2
- package/dist/sandbox/index.js +0 -1
- package/dist/served-definitions.d.ts +0 -20
- package/dist/served-definitions.js +0 -100
package/README.md
CHANGED
|
@@ -1,49 +1,85 @@
|
|
|
1
1
|
# @nylorun/agents
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Runtime API client package: definition authoring and a session client. The Tenant's
|
|
4
|
+
settings, models, vaults, signing keys and application keys are the Management
|
|
5
|
+
API's, through [`@nylorun/admin`](../admin/README.md). Depends only on `@nylorun/core` among Nylorun
|
|
5
6
|
packages. A developer application's production tree should contain only this
|
|
6
7
|
package and `@nylorun/core` from Nylorun. Vocabulary:
|
|
7
8
|
[runtime/src/CONTEXT.md](../runtime/src/CONTEXT.md).
|
|
8
9
|
|
|
9
|
-
## Application entry
|
|
10
|
+
## Application entry: save your agents
|
|
10
11
|
|
|
11
12
|
```ts
|
|
12
13
|
// src/main.ts
|
|
13
|
-
import {
|
|
14
|
-
import { createActionHandler } from "@nylorun/agents";
|
|
14
|
+
import { createClient } from "@nylorun/agents";
|
|
15
15
|
import { agents } from "../agents/index.js";
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
createServer(actions.node).listen(3001); // or actions.fetch in Hono, Next.js, Workers, Bun
|
|
20
|
-
await actions.register({ url });
|
|
17
|
+
const client = createClient();
|
|
18
|
+
for (const agent of agents) await client.saveAgent(agent);
|
|
21
19
|
```
|
|
22
20
|
|
|
23
|
-
The Runtime
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
21
|
+
The Runtime runs each agent from its manifest and the files saved with it (skills), and
|
|
22
|
+
never calls your code during a session. Your services are reached as tools: [HTTP
|
|
23
|
+
tools](#http-tools) and remote MCP servers. `saveAgent` refuses, before sending anything, an
|
|
24
|
+
agent with a tool that would run your code (`tool({ run })`) or a flow agent with a tool
|
|
25
|
+
stage: make it an `http()` tool or serve it from a remote MCP server. `tool({ run })` still
|
|
26
|
+
runs in the local engine (`@nylorun/harness/run`). `implementationVersion` defaults to
|
|
27
|
+
`NYLORUN_IMPLEMENTATION_VERSION`, else `dev`.
|
|
28
|
+
|
|
29
|
+
`createClient()` finds the Runtime through the two `NYLORUN_*` variables or the Project link
|
|
30
|
+
that `npx nylorun start` writes; with neither, it fails with `connection_missing` and names
|
|
31
|
+
those steps. Action endpoints (`createActionHandler`), and before them `connectAgents` and
|
|
32
|
+
executors, were removed; see [MIGRATION.md](../MIGRATION.md#action-endpoints-are-removed).
|
|
33
|
+
|
|
34
|
+
## HTTP tools
|
|
35
|
+
|
|
36
|
+
A tool can be one HTTP request to your service, made by the Runtime itself: no code of
|
|
37
|
+
yours runs during the session.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { Agent, http } from "@nylorun/agents";
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
|
|
43
|
+
const refundOrder = http({
|
|
44
|
+
name: "refund_order",
|
|
45
|
+
description: "Refund an order.",
|
|
46
|
+
input: z.object({ orderId: z.string(), amount: z.number() }), // or a JSON Schema object
|
|
47
|
+
output: z.object({ refundId: z.string() }), // optional
|
|
48
|
+
url: "https://billing.example.com/refunds",
|
|
49
|
+
method: "POST", // default; or PUT, PATCH
|
|
50
|
+
credential: "billing", // optional: a vault credential bound to this URL
|
|
51
|
+
timeoutMs: 20_000, // default 60000, at most 300000
|
|
52
|
+
approval: "always", // optional: each call waits for session.approve()
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const support = Agent({ id: "support" }).tools(refundOrder);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The tool goes into the manifest as `http` (and `approval`), and the Runtime's
|
|
59
|
+
Tool Gate sends the model's input as the JSON body, under the Host's address
|
|
60
|
+
policy (`NYLORUN_ENDPOINT_*`), with `content-type: application/json`,
|
|
61
|
+
`Nylorun-Session-Id`, `Nylorun-Turn-Id`, `Nylorun-Agent-Id` and an
|
|
62
|
+
`Idempotency-Key` that is the same when the Runtime re-sends the call after a
|
|
63
|
+
restart, so your service can drop duplicates. A `2xx` JSON answer is the output
|
|
64
|
+
(text when it is not JSON and the tool has no `output`), checked against
|
|
65
|
+
`output`. Any other status (with the start of its body), a timeout, a refused
|
|
66
|
+
address or a mismatched output is a tool error the model sees. A call whose
|
|
67
|
+
answer was lost with the gateway is `uncertain` and never sent again.
|
|
68
|
+
|
|
69
|
+
`credential` works as for a remote MCP server: the session's attached vaults
|
|
70
|
+
must hold a credential bound to the tool's exact URL (a `credentialSelections`
|
|
71
|
+
entry whose `serverName` is the `credential` picks one when several are), else
|
|
72
|
+
the operator's credential resolver is asked; without one the call fails before
|
|
73
|
+
it is sent. `approval: "always"` pauses the turn for `session.approve()`; a
|
|
74
|
+
denied call never runs and the model sees the denial. A remote MCP server takes
|
|
75
|
+
`approval: "always"` too, for every one of its tools:
|
|
76
|
+
`.mcp({ shop: { type: "streamable-http", url, approval: "always" } })`.
|
|
77
|
+
An HTTP tool is also a flow stage (see [Flow agents](#flow-agents)), and runs
|
|
78
|
+
only on the Runtime (a local `run()` reports `http.runtime-only`).
|
|
43
79
|
|
|
44
80
|
## Connection resolution
|
|
45
81
|
|
|
46
|
-
`resolveConnection` / `createClient()
|
|
82
|
+
`resolveConnection` / `createClient()`:
|
|
47
83
|
|
|
48
84
|
1. Explicit `{ url, key }`
|
|
49
85
|
2. Environment — if `NYLORUN_RUNTIME_URL` or `NYLORUN_SERVER_KEY` is set, both
|
|
@@ -59,22 +95,20 @@ Runtime serves one Tenant, so nothing names it: the `tenant` option is gone
|
|
|
59
95
|
is ignored.
|
|
60
96
|
|
|
61
97
|
```ts
|
|
62
|
-
import { Agent,
|
|
98
|
+
import { Agent, createClient, http } from "@nylorun/agents";
|
|
63
99
|
import { z } from "zod";
|
|
64
100
|
|
|
65
101
|
const assistant = Agent({ id: "assistant", name: "Assistant" })
|
|
66
102
|
.instructions("Use the available tools.")
|
|
67
103
|
.tools(
|
|
68
|
-
|
|
104
|
+
http({
|
|
69
105
|
name: "lookup",
|
|
70
106
|
input: z.object({ id: z.string() }),
|
|
71
|
-
|
|
72
|
-
return { id, owner: ctx.info };
|
|
73
|
-
},
|
|
107
|
+
url: "https://items.example.com/lookup",
|
|
74
108
|
}),
|
|
75
109
|
);
|
|
76
110
|
|
|
77
|
-
// Explicit
|
|
111
|
+
// Explicit Runtime API client (options or env / link via createClient()).
|
|
78
112
|
const client = createClient({
|
|
79
113
|
url: process.env.NYLORUN_RUNTIME_URL,
|
|
80
114
|
key: process.env.NYLORUN_SERVER_KEY,
|
|
@@ -86,20 +120,6 @@ const session = await client.createSession({
|
|
|
86
120
|
});
|
|
87
121
|
await session.input("Look up item 123", { idempotencyKey: requestId });
|
|
88
122
|
const history = await session.history();
|
|
89
|
-
|
|
90
|
-
// A process that only serves Actions holds no key: it reads the Tenant's public keys.
|
|
91
|
-
const actions = createActionHandler({
|
|
92
|
-
agents: [assistant],
|
|
93
|
-
implementationVersion: "app-1",
|
|
94
|
-
runtime: { url: process.env.NYLORUN_RUNTIME_URL! },
|
|
95
|
-
url: "https://app.example.com/nylorun/actions",
|
|
96
|
-
onError: console.error,
|
|
97
|
-
});
|
|
98
|
-
app.post("/nylorun/actions", actions.node);
|
|
99
|
-
// A deploy step with the application key registers the URL once:
|
|
100
|
-
await createActionHandler({ agents: [assistant], client }).register({
|
|
101
|
-
url: "https://app.example.com/nylorun/actions",
|
|
102
|
-
});
|
|
103
123
|
```
|
|
104
124
|
|
|
105
125
|
```sh
|
|
@@ -107,7 +127,7 @@ eval "$(npx @nylorun/cli env)"
|
|
|
107
127
|
# → NYLORUN_RUNTIME_URL, NYLORUN_SERVER_KEY
|
|
108
128
|
```
|
|
109
129
|
|
|
110
|
-
Every request sets `Nylorun-Protocol` (
|
|
130
|
+
Every request sets `Nylorun-Protocol` (8) and no `Nylorun-Tenant`: the Runtime
|
|
111
131
|
serves one Tenant. Before the first authenticated
|
|
112
132
|
request, `Transport` fetches `/health` once, checks protocol compatibility, and
|
|
113
133
|
throws `IncompatibleRuntimeError` / `incompatible_host` when the Host range or
|
|
@@ -125,7 +145,9 @@ const assistant = Agent({ id: "assistant", name: "Order assistant" })
|
|
|
125
145
|
.skills("./assistant-skills");
|
|
126
146
|
```
|
|
127
147
|
|
|
128
|
-
Each subdirectory under the catalog must contain a `SKILL.md` with YAML frontmatter (`name`, `description`) per [Agent Skills](https://agentskills.io/home).
|
|
148
|
+
Each subdirectory under the catalog must contain a `SKILL.md` with YAML frontmatter (`name`, `description`) per [Agent Skills](https://agentskills.io/home). Every file of a skill's folder, binary included (not `.git/`, `node_modules/`, OS files like `.DS_Store`, or `.env` and `.env.*` files, which hold secrets), is part of the definition: the manifest names each one by path and SHA-256 (`skills.<name>.files`), at most 500 files of 10 MiB each. `saveAgent` uploads the files the Runtime does not hold (`client.files`, `PUT /v1/files/sha256:<hex>`) before it puts the definition, which the Runtime refuses while it names a file it lacks (`400 definition_files_missing`).
|
|
149
|
+
|
|
150
|
+
The Runtime serves the skills itself, with no call to your process: `load_skill` returns a skill's `SKILL.md` body and the paths of its other files, and `read_skill_resource` returns a text file. A session with a sandbox also has each skill's files read-only under `/skills/<name>/`, so the model can run a skill's scripts with `bash`. Run without a Runtime, the skill tools only say so.
|
|
129
151
|
|
|
130
152
|
Declare MCP servers with `.mcp(...)` (same map shape as agent-plugins `mcpServers`):
|
|
131
153
|
|
|
@@ -139,7 +161,7 @@ const assistant = Agent({ id: "assistant", name: "Assistant" })
|
|
|
139
161
|
});
|
|
140
162
|
```
|
|
141
163
|
|
|
142
|
-
Each key names a server; its `name` defaults to the key and, when given, must equal it. Repeated `.mcp()` calls add servers to the same capability.
|
|
164
|
+
Each key names a server; its `name` defaults to the key and, when given, must equal it. Repeated `.mcp()` calls add servers to the same capability. Nylorun accepts remote servers only: `streamable-http` and `sse` ([Agent Plugins MCP servers](https://agent-plugins.org/plugin-authors/mcp-servers)); a `stdio` server is refused, so run it behind an HTTP transport and declare its URL. Attach an Agent Plugin package with `.plugin(path)`: its skills and remote MCP servers join the agent, and a stdio server in its `mcp.json` throws.
|
|
143
165
|
|
|
144
166
|
Give a session a sandbox when you open it. The agent declares nothing, so the same agent runs with or without one, in any Tenant:
|
|
145
167
|
|
|
@@ -154,7 +176,7 @@ const session = await client.createSession({
|
|
|
154
176
|
});
|
|
155
177
|
```
|
|
156
178
|
|
|
157
|
-
The model gets `bash`, `read`, `write`, `edit`, `grep` and `glob` on a persistent `/workspace`. These tools run in the Runtime, not in your process
|
|
179
|
+
The model gets `bash`, `read`, `write`, `edit`, `grep` and `glob` on a persistent `/workspace`. These tools run in the Runtime, not in your process. The Runtime decides where the sandbox runs: today an emulated shell in the Runtime process, which is not a VM boundary and takes no `image`.
|
|
158
180
|
|
|
159
181
|
`sandbox` takes `false` for none, `{ id }` to attach a sandbox resource (below), or an inline sandbox as above; omit it for the Tenant's default. `{ session }`, sharing another session's sandbox, still works and is deprecated. The Runtime checks it against the Tenant's limits (`GET`/`PUT /v1/tenant/sandbox`: a network ceiling, a resource maximum, the idle timeout) and answers `400` with every problem it finds. A caller acting for a user (`app.as(...)`) can't define one inline; it gets the Tenant's default or `false`. Private networks, loopback, the host and cloud metadata endpoints are always blocked.
|
|
160
182
|
|
|
@@ -196,91 +218,161 @@ const support = Agent({ id: "support" })
|
|
|
196
218
|
.subagents(researcher);
|
|
197
219
|
```
|
|
198
220
|
|
|
199
|
-
The tool is named after the agent's `id` and takes `{ task: string }`; the agent's `description` (required) is what the parent's model reads to decide when to delegate. The child starts with a fresh context: it sees its own instructions and the task, nothing of the parent's conversation, and only its final text (or `outputSchema` result) comes back. It keeps its own tools,
|
|
221
|
+
The tool is named after the agent's `id` and takes `{ task: string }`; the agent's `description` (required) is what the parent's model reads to decide when to delegate. The child starts with a fresh context: it sees its own instructions and the task, nothing of the parent's conversation, and only its final text (or `outputSchema` result) comes back. It keeps its own tools, skills and MCP servers, saved with the parent, and shares the session's sandbox. Several delegation calls in one model response run in parallel. An empty answer, a failure (with the child's last text marked as evidence) or a cancelled child reaches the parent's model as a failed tool result, never as success. The Runtime emits `delegation.started` and `delegation.completed`; `session.history({ agent })` filters by `delegationId` (one child invocation) or by path such as `support/researcher` (every concurrent child that shares that path).
|
|
200
222
|
|
|
201
|
-
A flow agent can be a subagent too: `.subagents(researchFlow)` with a `description` like any other. Its manifest is inlined in the parent's, so it is saved with the parent
|
|
223
|
+
A flow agent can be a subagent too: `.subagents(researchFlow)` with a `description` like any other. Its manifest is inlined in the parent's, so it is saved with the parent. When the model calls it, the flow runs on the Runtime in its own linked session (a fresh one per call, linked from the parent's with a `node.agent` event at `support/<flow id>`), its agents in theirs, and the flow's output comes back as the tool result; a failed flow is a failed tool result. Cancelling the parent cancels the flow. Flow agents as subagents run on the Runtime only, not in a local `run()`. An approval asked for inside the flow waits on the flow's own session.
|
|
202
224
|
|
|
203
|
-
Delegate when the parent should keep the answer. When a specialist should own the rest of the conversation,
|
|
225
|
+
Delegate when the parent should keep the answer. When a specialist should own the rest of the conversation, send the next message with a turn manifest that has the specialist's instructions instead. This version is one level deep and non-interactive: a delegated agent cannot use agents as tools, and its tools cannot declare `approval` (keep those on the parent). In the local engine (`@nylorun/harness/run`), a delegated agent's `tool({ run })` tools start with empty `ctx.state`, can read `ctx.agent` (`{ id, path, delegationId }`), and fail with `delegation.interaction-unsupported` on `ctx.ask`, `ctx.approve`, `ctx.sleep` or `ctx.waitFor`. Delegation is not an approval boundary; approvals live on tools.
|
|
204
226
|
|
|
205
227
|
## Flow agents
|
|
206
228
|
|
|
207
|
-
An agent's body is either a ReAct loop (the model decides) or a flow (
|
|
208
|
-
decides). A flow agent is built from stages
|
|
209
|
-
|
|
210
|
-
`
|
|
211
|
-
and `
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
229
|
+
An agent's body is either a ReAct loop (the model decides) or a flow (its manifest
|
|
230
|
+
decides). A flow agent is built from stages and is registered, saved and opened as a
|
|
231
|
+
session like any agent: put it in `export const agents`, `saveAgent(flowAgent)`, then
|
|
232
|
+
`createSession({ agentId })` and `session.input(value)`. `input` sends string values as
|
|
233
|
+
`content` and other JSON as `data`. On the wire a flow agent is a workflow manifest v3
|
|
234
|
+
(`kind: "workflow"`, `workflowSchemaVersion: 3`) that embeds the agents it runs, so one
|
|
235
|
+
document and one manifest hash cover the whole flow; its agents are not listed on their own.
|
|
236
|
+
|
|
237
|
+
A flow runs no code of yours: the first stage gets the flow's input, and every later stage
|
|
238
|
+
gets the previous stage's output. So each agent returns, through its `.output()` schema,
|
|
239
|
+
what the next stage needs.
|
|
215
240
|
|
|
216
241
|
```ts
|
|
217
|
-
import { Agent,
|
|
242
|
+
import { Agent, VerdictSchema, http } from "@nylorun/agents";
|
|
218
243
|
import { z } from "zod";
|
|
219
244
|
|
|
220
245
|
const planner = Agent({ id: "planner" })
|
|
221
|
-
.instructions("Return {
|
|
222
|
-
.output(z.object({
|
|
246
|
+
.instructions("Return { items: string[] }, one task each.")
|
|
247
|
+
.output(z.object({ items: z.array(z.string()) }));
|
|
223
248
|
|
|
224
249
|
const coder = Agent({ id: "coder" })
|
|
225
250
|
.instructions("Implement one task. Return { summary }.")
|
|
226
251
|
.output(z.object({ summary: z.string() }));
|
|
227
252
|
|
|
228
|
-
const
|
|
229
|
-
|
|
253
|
+
const reviewer = Agent({ id: "reviewer" })
|
|
254
|
+
.instructions("Pass the response when its summary says what changed.")
|
|
255
|
+
.output(VerdictSchema);
|
|
256
|
+
|
|
257
|
+
const prWriter = Agent({ id: "pr-writer" })
|
|
258
|
+
.instructions("Return the summaries you are given as { summaries }.")
|
|
259
|
+
.output(z.object({ summaries: z.array(z.string()) }));
|
|
260
|
+
|
|
261
|
+
// Your service serves POST /pull-requests and answers { url }.
|
|
262
|
+
const openPr = http({
|
|
263
|
+
name: "open_pr",
|
|
230
264
|
input: z.object({ summaries: z.array(z.string()) }),
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
},
|
|
265
|
+
output: z.object({ url: z.string() }),
|
|
266
|
+
url: "https://ci.example.com/pull-requests",
|
|
267
|
+
credential: "github",
|
|
235
268
|
});
|
|
236
269
|
|
|
237
270
|
export const shipFeature = Agent({ id: "ship-feature" })
|
|
238
|
-
.
|
|
239
|
-
.map(
|
|
240
|
-
|
|
241
|
-
verify: ({ output }) => (output.summary ? { pass: true } : { pass: false, feedback: "Say what you changed." }),
|
|
242
|
-
max: 2,
|
|
243
|
-
}),
|
|
244
|
-
{ id: "implement", input: ({ input }) => input.tasks },
|
|
245
|
-
)
|
|
246
|
-
.step(openPr, { input: ({ input }) => ({ summaries: input.map((item) => item.summary) }) });
|
|
271
|
+
.pipe(planner)
|
|
272
|
+
.map(Agent({ id: "code" }).loop(coder, { verify: reviewer, max: 2 }), { id: "implement" })
|
|
273
|
+
.pipe(prWriter, openPr);
|
|
247
274
|
|
|
248
275
|
export const agents = [shipFeature];
|
|
249
276
|
```
|
|
250
277
|
|
|
278
|
+
A flow stage cannot take `approval` yet (`flow.approval-unsupported`). To have a person
|
|
279
|
+
approve opening the PR, give the HTTP tool to an agent as the last stage instead: that
|
|
280
|
+
agent's turn pauses until the call is approved, and the flow session's `pending()` lists
|
|
281
|
+
the wait:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
const prOpener = Agent({ id: "pr-opener" })
|
|
285
|
+
.instructions("Open one pull request with open_pr from the summaries you are given.")
|
|
286
|
+
.tools(
|
|
287
|
+
http({
|
|
288
|
+
name: "open_pr",
|
|
289
|
+
description: "Open a pull request with the given summaries.",
|
|
290
|
+
input: z.object({ summaries: z.array(z.string()) }),
|
|
291
|
+
url: "https://ci.example.com/pull-requests",
|
|
292
|
+
credential: "github",
|
|
293
|
+
approval: "always",
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// …
|
|
298
|
+
.pipe(prWriter, prOpener);
|
|
299
|
+
```
|
|
300
|
+
|
|
251
301
|
| Stage | Role |
|
|
252
302
|
| --- | --- |
|
|
253
|
-
| **`.
|
|
254
|
-
| **`.switch({ ...cases, default? }
|
|
303
|
+
| **`.pipe(a, b, …)`** | Run agents, tools or `flow()`s in order; each one's output is the next one's input |
|
|
304
|
+
| **`.switch({ ...cases, default? })`** | Run the case the previous output names: a string, or its `route` field |
|
|
255
305
|
| **`.parallel(branches)`** | Fixed named branches at once, same input; output is an object |
|
|
256
|
-
| **`.map(each)`** | Run `each` once per item of the
|
|
257
|
-
| **`.loop(body, { verify, max
|
|
306
|
+
| **`.map(each)`** | Run `each` once per item of the previous output: an array, or its `items`; output is an array |
|
|
307
|
+
| **`.loop(body, { verify, max })`** | Run `body`, ask `verify` (an agent, or `http({ url })`), run again with its feedback until it passes, at most `max` times |
|
|
308
|
+
|
|
309
|
+
Every stage takes `{ id }` to name it (`.loop` takes it beside `verify` and `max`).
|
|
310
|
+
`flow()` builds a sequence with no id for a case, branch, map item or loop body that
|
|
311
|
+
is more than one step. A verifier agent gets `{ task, response, iteration }` and returns
|
|
312
|
+
a verdict, `{ pass, feedback? }` (`VerdictSchema`), with feedback when it fails; the
|
|
313
|
+
verdict is recorded as a `loop.verified` event. An agent after the first stage also
|
|
314
|
+
sees the flow's input, as the original request, before its own input. Types flow from
|
|
315
|
+
each stage's `.output()` schema to the flow agent's output. `.step(x, { id })` is a
|
|
316
|
+
deprecated alias for `.pipe(x.withId(id))`.
|
|
317
|
+
|
|
318
|
+
An [HTTP tool](#http-tools) is a stage too: in `.pipe()`, a case, a Map item or a Loop
|
|
319
|
+
body. Its input is the previous output, which must match the tool's `input` (an
|
|
320
|
+
object); a mismatch the build can see, such as an agent with no `.output()` before it,
|
|
321
|
+
is refused (`flow.input-mismatch`), and any other fails the stage when it runs
|
|
322
|
+
(`tool.invalid-input`). The Runtime makes the request as for an agent's HTTP tool, with
|
|
323
|
+
`Nylorun-Agent-Id` set to the flow agent's id and `credential` taken from the flow
|
|
324
|
+
session's vaults; its answer is the next stage's input. A failure status, a timeout or
|
|
325
|
+
an answer that does not match `output` fails the stage with its code (`http.status`,
|
|
326
|
+
`http.timeout`, `tool.invalid-output`, …). A Loop body that starts with an HTTP stage
|
|
327
|
+
is retried with the Loop's input, not the feedback. `approval: "always"` is not
|
|
328
|
+
supported on a flow stage yet (`flow.approval-unsupported`).
|
|
329
|
+
|
|
330
|
+
A Loop may be judged by your service instead of an agent: `http({ url, method?,
|
|
331
|
+
credential?, timeoutMs? })`, with no name or input, is an HTTP verifier. The Runtime
|
|
332
|
+
sends `{ input, output, iteration }` (the Loop's input, the attempt's output, its
|
|
333
|
+
number) and reads a verdict, `{ pass, feedback? }`, from the answer; anything else, or a
|
|
334
|
+
failed request, fails the Loop (`loop.verify-failed`). Its verdicts are recorded as
|
|
335
|
+
`loop.verified`, as an agent's are.
|
|
258
336
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
337
|
+
```ts
|
|
338
|
+
import { Agent, http } from "@nylorun/agents";
|
|
339
|
+
import { z } from "zod";
|
|
340
|
+
|
|
341
|
+
const order = Agent({ id: "order" })
|
|
342
|
+
.instructions("Name the order to refund as { orderId }.")
|
|
343
|
+
.output(z.object({ orderId: z.string() }));
|
|
344
|
+
|
|
345
|
+
const refund = http({
|
|
346
|
+
name: "refund",
|
|
347
|
+
input: z.object({ orderId: z.string() }),
|
|
348
|
+
output: z.object({ refundId: z.string() }),
|
|
349
|
+
url: "https://billing.example.com/refunds",
|
|
350
|
+
credential: "billing",
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const fixer = Agent({ id: "fixer" }).instructions("Fix the failing test.");
|
|
354
|
+
|
|
355
|
+
export const refunds = Agent({ id: "refunds" }).pipe(order, refund);
|
|
356
|
+
export const fixTests = Agent({ id: "fix-tests" }).loop(fixer, {
|
|
357
|
+
verify: http({ url: "https://ci.example.com/verify", credential: "ci" }),
|
|
358
|
+
max: 3,
|
|
359
|
+
});
|
|
360
|
+
```
|
|
265
361
|
|
|
266
362
|
Agents inside a flow keep their own sessions, linked from the flow's session and
|
|
267
|
-
named by the agent:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
`.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
Name the stages you may reorder.
|
|
275
|
-
|
|
276
|
-
`Chain`, `Switch`, `Parallel`, `Map` and `Loop` still build workflow manifest v1
|
|
277
|
-
directly and run as before; a flow agent can't be a child of them.
|
|
363
|
+
named by the agent: its id (or `.withId("…")`), with `[i]` for each Map item and a
|
|
364
|
+
nested flow agent's id in front of its own agents'. Control stages add nothing, so
|
|
365
|
+
wrapping a step in `.loop()` or moving it between cases keeps its session. An agent
|
|
366
|
+
may appear once per flow; use it again under a new id with `writer.withId("final-writer")`
|
|
367
|
+
(`flow.duplicate-leaf`). A code tool stage (`.pipe(tool({ run }))`) runs only in the local
|
|
368
|
+
engine: the Runtime runs no code of yours, so `saveAgent` refuses a flow agent with one. Use
|
|
369
|
+
an HTTP stage instead.
|
|
278
370
|
|
|
279
371
|
The agents in a flow share one sandbox: open the flow's session with it,
|
|
280
|
-
`createSession({ …, sandbox: { … } })`, and every agent
|
|
281
|
-
|
|
372
|
+
`createSession({ …, sandbox: { … } })`, and every agent in the flow uses it. Share it
|
|
373
|
+
with other sessions by opening them all on one sandbox resource
|
|
282
374
|
(`sandbox: { id }`, see `client.sandboxes`), and call
|
|
283
|
-
built-ins via `session.sandbox` (application)
|
|
375
|
+
built-ins via `session.sandbox` (application).
|
|
284
376
|
Observe with `session.observe({ follow: true })` to merge linked agent streams;
|
|
285
377
|
`pending()` lists waits across the tree. Studio renders the manifest tree and
|
|
286
378
|
live node status. Source examples:
|
|
@@ -293,15 +385,15 @@ Use `session.observe({ cursor, signal })` for resumable canonical events, `sessi
|
|
|
293
385
|
|
|
294
386
|
Connection defaults follow `resolveConnection` (options → environment → Project
|
|
295
387
|
link). Implementation version defaults from `NYLORUN_IMPLEMENTATION_VERSION`,
|
|
296
|
-
then `dev`.
|
|
297
|
-
|
|
298
|
-
Agents do not hash the manifest, and an in-flight action is still delivered after
|
|
299
|
-
the registered digest changes. Model selection and model credentials belong to
|
|
388
|
+
then `dev`. Agents do not hash the manifest; the Runtime pins the digest of the
|
|
389
|
+
definition a session opens with. Model selection and model credentials belong to
|
|
300
390
|
the Tenant.
|
|
301
391
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
392
|
+
The Runtime makes a lost HTTP tool call `uncertain` instead of repeating its external effect.
|
|
393
|
+
In the local engine (`@nylorun/harness/run`), `tool({ run })` tools receive state, info,
|
|
394
|
+
identity, resume, signal, approval/response helpers and memoized `step`. Arbitrary middleware
|
|
395
|
+
closures are rejected for durable definitions. Agent definitions have no `.run()`; explicit
|
|
396
|
+
local execution is available through `@nylorun/harness/run`.
|
|
305
397
|
|
|
306
398
|
## AG-UI
|
|
307
399
|
|
|
@@ -377,7 +469,7 @@ no reasoning, state, activity or subagent events, and an agent used as a tool
|
|
|
377
469
|
shows only its result; frontend tools in `RunAgentInput.tools` are rejected
|
|
378
470
|
(`400`); one text part per user message; earlier messages cannot be edited or
|
|
379
471
|
regenerated. A browser reaches the Runtime only with a trusted issuer's token,
|
|
380
|
-
never with a
|
|
472
|
+
never with a key.
|
|
381
473
|
|
|
382
474
|
## A2A
|
|
383
475
|
|
|
@@ -495,12 +587,12 @@ completes.
|
|
|
495
587
|
## Acting for a person (app servers)
|
|
496
588
|
|
|
497
589
|
A server that signs people in and calls the Runtime for them (an "app server")
|
|
498
|
-
keeps
|
|
590
|
+
keeps its application key to itself and names the person on each call:
|
|
499
591
|
|
|
500
592
|
```ts
|
|
501
593
|
import { createClient } from "@nylorun/agents";
|
|
502
594
|
|
|
503
|
-
const app = createClient(); // the
|
|
595
|
+
const app = createClient(); // the application key, on the server only
|
|
504
596
|
|
|
505
597
|
// Per request, after your own sign-in:
|
|
506
598
|
const person = app.as(`app:${user.id}`, { scopes: ["sessions:own"] });
|
|
@@ -519,22 +611,25 @@ compatibility check, so calling `as()` per request is cheap.
|
|
|
519
611
|
| --- | --- |
|
|
520
612
|
| `sessions:own` | The person's own sessions: create, list, read, stream, message, approve, respond, cancel; and their artifacts |
|
|
521
613
|
| `agents:read` | Listing the Tenant's agents |
|
|
522
|
-
| `agents:write` | Saving agents; listing agents
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
the
|
|
527
|
-
|
|
528
|
-
|
|
614
|
+
| `agents:write` | Saving agents; listing agents |
|
|
615
|
+
|
|
616
|
+
No scope reaches the sandbox tool routes; call them without `as()`. `tenant:settings` is retired (protocol 8): it grants
|
|
617
|
+
nothing, and no subject reaches the Management API (`/v1/tenant/*`). Vaults are
|
|
618
|
+
the installation's, created through the Management API with a management key
|
|
619
|
+
(`admin.vaults.create({ scope: "installation", … })` in
|
|
620
|
+
[`@nylorun/admin`](../admin/README.md)); a session attaches them with
|
|
621
|
+
`vaultIds`, and a person's own credentials come from your credential resolver
|
|
529
622
|
([DEPLOYMENT.md](../DEPLOYMENT.md#credentials)). A subject is 1–200 visible ASCII
|
|
530
623
|
characters (spaces only inside) and `host` is reserved. Your server must drop
|
|
531
624
|
any `Nylorun-*` header its own clients send, and only an application key can act
|
|
532
625
|
for a subject.
|
|
533
626
|
|
|
534
|
-
The Tenant's signing keys sign
|
|
535
|
-
`app.access.
|
|
536
|
-
|
|
537
|
-
|
|
627
|
+
The Tenant's signing keys sign capability links and run tokens.
|
|
628
|
+
`app.access.jwks()` reads the public keys (`GET /v1/access/jwks`, no key
|
|
629
|
+
needed). Listing, rotating
|
|
630
|
+
and revoking them is management: `admin.signingKeys.list()`, `.rotate()`
|
|
631
|
+
(`{ force: true }` for incidents) and `.revoke(kid)` in `@nylorun/admin`, or
|
|
632
|
+
`nylo access signing-keys …` from the terminal.
|
|
538
633
|
|
|
539
634
|
## In the browser
|
|
540
635
|
|
package/dist/access.d.ts
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Tenant's
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The Tenant's public keys, which verify the tokens it signs (capability links, run tokens).
|
|
3
|
+
* Listing, rotating and revoking signing keys is the Management API's (`admin.signingKeys` in
|
|
4
|
+
* `@nylorun/admin`, protocol 8).
|
|
5
5
|
*/
|
|
6
|
-
import type { Jwks
|
|
7
|
-
import {
|
|
8
|
-
export declare class SigningKeysClient {
|
|
9
|
-
private readonly transport;
|
|
10
|
-
constructor(transport: Transport);
|
|
11
|
-
list(options?: {
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
}): Promise<SigningKeyView[]>;
|
|
14
|
-
/**
|
|
15
|
-
* standby → current → previous → revoked, and a new standby. Refused while the previous key
|
|
16
|
-
* may still verify live tokens; `force` skips that and ends those tokens.
|
|
17
|
-
*/
|
|
18
|
-
rotate(options?: {
|
|
19
|
-
force?: boolean;
|
|
20
|
-
signal?: AbortSignal;
|
|
21
|
-
}): Promise<SigningKeyView[]>;
|
|
22
|
-
/** Revokes a previous or standby key; the current key must be rotated first. */
|
|
23
|
-
revoke(keyId: string, options?: {
|
|
24
|
-
signal?: AbortSignal;
|
|
25
|
-
}): Promise<SigningKeyView>;
|
|
26
|
-
}
|
|
6
|
+
import type { Jwks } from "@nylorun/core/contracts";
|
|
7
|
+
import type { Transport } from "./http.js";
|
|
27
8
|
export declare class AccessClient {
|
|
28
9
|
private readonly transport;
|
|
29
|
-
readonly signingKeys: SigningKeysClient;
|
|
30
10
|
constructor(transport: Transport);
|
|
31
|
-
/** The public keys that verify the Tenant
|
|
11
|
+
/** The public keys that verify the tokens the Tenant signs. */
|
|
32
12
|
jwks(options?: {
|
|
33
13
|
signal?: AbortSignal;
|
|
34
14
|
}): Promise<Jwks>;
|
package/dist/access.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import { id, segment } from "./http.js";
|
|
2
|
-
export class SigningKeysClient {
|
|
3
|
-
transport;
|
|
4
|
-
constructor(transport) {
|
|
5
|
-
this.transport = transport;
|
|
6
|
-
}
|
|
7
|
-
async list(options = {}) {
|
|
8
|
-
const reply = await this.transport.json("/v1/access/signing-keys", "GET", undefined, options.signal);
|
|
9
|
-
return reply.keys;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* standby → current → previous → revoked, and a new standby. Refused while the previous key
|
|
13
|
-
* may still verify live tokens; `force` skips that and ends those tokens.
|
|
14
|
-
*/
|
|
15
|
-
async rotate(options = {}) {
|
|
16
|
-
const reply = await this.transport.json("/v1/access/signing-keys/rotate", "POST", { requestId: id(), ...(options.force ? { force: true } : {}) }, options.signal);
|
|
17
|
-
return reply.keys;
|
|
18
|
-
}
|
|
19
|
-
/** Revokes a previous or standby key; the current key must be rotated first. */
|
|
20
|
-
async revoke(keyId, options = {}) {
|
|
21
|
-
return this.transport.json(`/v1/access/signing-keys/${segment(keyId)}/revoke`, "POST", { requestId: id() }, options.signal);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
1
|
export class AccessClient {
|
|
25
2
|
transport;
|
|
26
|
-
signingKeys;
|
|
27
3
|
constructor(transport) {
|
|
28
4
|
this.transport = transport;
|
|
29
|
-
this.signingKeys = new SigningKeysClient(transport);
|
|
30
5
|
}
|
|
31
|
-
/** The public keys that verify the Tenant
|
|
6
|
+
/** The public keys that verify the tokens the Tenant signs. */
|
|
32
7
|
async jwks(options = {}) {
|
|
33
8
|
return this.transport.json("/v1/access/jwks", "GET", undefined, options.signal);
|
|
34
9
|
}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Definition files (track R2 M4): `client.files`. A definition names the files it needs by the
|
|
3
|
+
* SHA-256 of their bytes (a skill's folder, `SkillManifest.files`); the Runtime holds each one
|
|
4
|
+
* once, uploaded with `PUT /v1/files/sha256:<hex>`, and refuses a definition naming a file it
|
|
5
|
+
* does not hold (`400 definition_files_missing`). `saveAgent` uploads an agent's files itself.
|
|
6
|
+
*/
|
|
7
|
+
import { type DefinitionFileView } from "@nylorun/core/contracts";
|
|
8
|
+
import type { SkillFileSource } from "@nylorun/core/define";
|
|
9
|
+
import { type Transport } from "./http.js";
|
|
10
|
+
/** `sha256:<hex>` of `bytes`. */
|
|
11
|
+
export declare function definitionFileHash(bytes: Uint8Array): Promise<string>;
|
|
12
|
+
export declare class FilesClient {
|
|
13
|
+
private readonly transport;
|
|
14
|
+
constructor(transport: Transport);
|
|
15
|
+
/** Whether the Runtime holds the file `sha256` (`sha256:<hex>`) names. */
|
|
16
|
+
has(sha256: string, options?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Uploads one file, at most 10 MiB. The Runtime checks its bytes hash to `sha256` (default:
|
|
21
|
+
* their hash) and keeps a file it already holds as it is.
|
|
22
|
+
*/
|
|
23
|
+
upload(bytes: Uint8Array, options?: {
|
|
24
|
+
sha256?: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<DefinitionFileView>;
|
|
27
|
+
/** Uploads each of `files` the Runtime does not hold yet. */
|
|
28
|
+
ensure(files: ReadonlyMap<string, SkillFileSource>, options?: {
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
}
|