@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/README.md CHANGED
@@ -1,49 +1,85 @@
1
1
  # @nylorun/agents
2
2
 
3
- Tenant API client package: definition authoring, a session client, and the
4
- Action endpoint that runs your tools (`createActionHandler`). Depends only on `@nylorun/core` among Nylorun
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 (preferred): an Action endpoint
10
+ ## Application entry: save your agents
10
11
 
11
12
  ```ts
12
13
  // src/main.ts
13
- import { createServer } from "node:http";
14
- import { createActionHandler } from "@nylorun/agents";
14
+ import { createClient } from "@nylorun/agents";
15
15
  import { agents } from "../agents/index.js";
16
16
 
17
- const url = process.env.NYLORUN_ACTIONS_URL ?? "http://localhost:3001/nylorun/actions";
18
- const actions = createActionHandler({ agents, url });
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 delivers each tool call, hook and workflow function of these agents
24
- to `url`, signed with a short-lived **delivery token** that the handler checks
25
- (Tenant, URL, Action, generation and body) before any code runs. `register`
26
- saves the definitions, registers the URL and pings it through the Runtime. A
27
- process that only serves Actions needs no key: pass `runtime: { url }` and it
28
- reads the Tenant's public keys. Mark a long tool
29
- `tool({ …, background: true })`: the handler answers at once, heartbeats and
30
- posts the result. `npx @nylorun/cli endpoints` shows each endpoint and how its
31
- deliveries are doing.
32
-
33
- The URL must be one the Runtime can reach: `localhost` on a local Tenant
34
- (its Runtime runs in Docker and maps `localhost` to this machine), a public URL
35
- in production, or a tunnel (ngrok, Cloudflare Tunnel) for a remote Runtime.
36
-
37
- `connectAgents` and executors were removed in protocol 3: mount
38
- `createActionHandler` instead (see [MIGRATION.md](../MIGRATION.md)). The handler
39
- finds the Runtime through the two `NYLORUN_*` variables or the Project link
40
- that `npx nylorun start` writes; with neither, `register` fails with
41
- `connection_missing` and names those steps. See [MIGRATION.md](../MIGRATION.md#runtime-clients-and-admin-api-breaking-beta)
42
- for upgrading from `nylorun serve`.
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()` / `createActionHandler({ agents })`:
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, createActionHandler, createClient, tool } from "@nylorun/agents";
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
- tool({
104
+ http({
69
105
  name: "lookup",
70
106
  input: z.object({ id: z.string() }),
71
- async run({ id }, ctx) {
72
- return { id, owner: ctx.info };
73
- },
107
+ url: "https://items.example.com/lookup",
74
108
  }),
75
109
  );
76
110
 
77
- // Explicit Tenant API client (options or env / link via createClient()).
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` (6) and no `Nylorun-Tenant`: the Runtime
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). Supporting files (for example `references/`) are available through `read_skill_resource` after `load_skill`. The helper sets both the manifest skill catalog and the on-disk skill records so you do not duplicate content.
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. Transports follow [Agent Plugins MCP servers](https://agent-plugins.org/plugin-authors/mcp-servers): `stdio`, `streamable-http`, and `sse`. Attach an Agent Plugin package with `.plugin(path)`.
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, so sandbox-only agents need no Action endpoint. 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`.
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, hooks, skills and MCP servers, served by the Action endpoint you already mount for the parent (`createActionHandler({ agents: [support] })` serves both), shares the session's sandbox, and starts with empty `ctx.state`. Tools can read `ctx.agent` (`{ id, path, delegationId }`). 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).
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 and served by the parent's Action endpoint. 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.
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, switch capabilities with a `.beforeModel()` patch instead. This version is one level deep and non-interactive: a delegated agent cannot use agents as tools, its tools cannot declare `approval` (keep those on the parent), and `ctx.ask`, `ctx.approve`, `ctx.sleep` or `ctx.waitFor` inside it fail with `delegation.interaction-unsupported`. Delegation is not an approval boundary; approvals live on tools.
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 (your code
208
- decides). A flow agent is built from stages, each shaped `.stage(whatRuns, { how })`,
209
- and is registered, saved and opened as a session like any agent: put it in
210
- `export const agents`, `saveAgent(flowAgent)`, then `createSession({ agentId })`
211
- and `session.input(value)`. `input` sends string values as `content` and other JSON
212
- as `data`. On the wire a flow agent is a workflow manifest v2 (`kind: "workflow"`,
213
- `workflowSchemaVersion: 2`) that embeds the agents it runs, so one document and one
214
- manifest hash cover the whole flow; its agents are not listed on their own.
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, tool } from "@nylorun/agents";
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 { tasks: string[] }.")
222
- .output(z.object({ tasks: z.array(z.string()) }));
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 openPr = tool({
229
- name: "open-pr",
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
- async run({ summaries }, ctx) {
232
- if (!(await ctx.approve("Open the PR?"))) throw new Error("Rejected");
233
- return { opened: true, count: summaries.length };
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
- .step(planner)
239
- .map(
240
- Agent({ id: "code" }).loop(coder, {
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
- | **`.step(x, { id?, input? })`** | Run one agent, tool or `flow()`; its output is the next stage's input |
254
- | **`.switch({ ...cases, default? }, { on })`** | `on({ input })` returns a case name; exactly that case runs |
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 input, which must be an array; output is an array |
257
- | **`.loop(body, { verify, max?, decide? })`** | Run, verify, run again with the feedback until it passes; needs `max` or `decide` |
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
- Every function receives one object: `{ input, results, flowInput }`. `input` is
260
- what the stage received, `results` holds earlier steps' outputs by step id, and
261
- `flowInput` is the agent's own input. The `input` option computes a stage's input;
262
- the `id` option names a step. `flow()` builds a sequence with no id for a case,
263
- branch, map item or loop body that is more than one step. Types flow from each
264
- step's `.output()` schema to the next stage's `input`.
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: a step's id (the agent's id, or `{ id }`), with `[i]` for each
268
- Map item and a nested flow agent's id in front of its own agents'. Control stages
269
- add nothing, so wrapping a step in `.loop()` or moving it between cases keeps its
270
- session. An agent may appear once per flow; use it again under a new id with
271
- `.step(writer, { id: "final-writer" })` or `writer.withId("…")`
272
- (`flow.duplicate-leaf`). Functions are bound under stage keys: a stage's `id`, or
273
- its position such as `@1.default.1`, plus `:input`, `:on`, `:verify` or `:decide`.
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, tool step and `verify` in the
281
- flow uses it. Share it with other sessions by opening them all on one sandbox resource
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) or `ctx.sandbox` (a tool).
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`. `register` saves the definitions and registers one endpoint per
297
- served agent with the application key; serving deliveries needs no key.
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
- After registration, the Runtime POSTs each Action to the endpoint with a delivery token signed by the Tenant's key; the handler verifies it before any code runs and answers with the outcome. A background tool answers `202`, heartbeats with the newest token and posts its result. A cancel aborts the request, which reaches the tool as `ctx.signal`; JavaScript cannot forcibly terminate a function that ignores its signal. The host makes lost in-flight deliveries uncertain instead of automatically repeating external effects.
303
-
304
- Tools receive state, info, identity, resume, signal, approval/response helpers and memoized `step`. Step outcomes survive a persisted wait result; they do not establish exactly-once external effects after an unacknowledged crash. `sleep` and `waitFor` currently return inspectable deferred outcomes; automatic timer/event wakeups remain runtime implementation work. Remote `onModelCall` convenience and progress-event transport are not supplied in this pass. Arbitrary middleware closures are rejected for durable definitions; use `before`/`after` hooks. The Action endpoint runs every capability registered at a hook point in one action. Agent definitions have no `.run()`; explicit local execution is available through `@nylorun/harness/run`.
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 Tenant key.
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 the Tenant key to itself and names the person on each call:
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 Tenant key, on the server only
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, models and providers |
523
- | `tenant:settings` | The Tenant's status, model provider and sandbox settings |
524
-
525
- No scope reaches Tenant reset, config seed, Action endpoints, actions, vaults or
526
- the sandbox tool routes; call those without `as()`. Vaults are the
527
- installation's (`createVault({ scope: "installation", … })`); a person's own
528
- credentials come from your credential resolver
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 delivery tokens and capability links:
535
- `app.access.signingKeys.list()`, `.rotate()` (`{ force: true }` for incidents),
536
- `.revoke(kid)` and `app.access.jwks()`, or `nylo access signing-keys …` from the
537
- terminal.
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 signing keys and public keys, for app servers on the application key. The
3
- * Runtime signs delivery tokens (Action endpoints) and capability links with them; an Action
4
- * endpoint verifies delivery tokens with the public keys (`jwks`).
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, SigningKeyView } from "@nylorun/core/contracts";
7
- import { type Transport } from "./http.js";
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's delivery tokens. */
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's delivery tokens. */
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
  }
@@ -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
+ }