@mantyx/sdk 2026.11.10 → 2026.11.12
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 +24 -0
- package/README.md +75 -3
- package/dist/a2a-server.cjs +4 -0
- package/dist/a2a-server.d.ts +5 -1
- package/dist/a2a-server.js +5 -1
- package/dist/{chunk-LISLOB7S.js → chunk-EXTS5Q3T.js} +315 -70
- package/dist/client.d.ts +308 -63
- package/dist/computer-use.d.ts +3 -3
- package/dist/index.cjs +316 -72
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -4
- package/dist/tools.d.ts +46 -10
- package/dist/version.d.ts +1 -1
- package/docs/agent-runs-protocol.md +88 -40
- package/docs/wire-protocol.md +33 -71
- package/package.json +4 -4
package/dist/tools.d.ts
CHANGED
|
@@ -79,13 +79,42 @@ export interface LocalToolResult {
|
|
|
79
79
|
* values are JSON-serialized by the SDK before being posted back.
|
|
80
80
|
*/
|
|
81
81
|
export type LocalToolOutput = string | LocalToolResult;
|
|
82
|
+
/**
|
|
83
|
+
* Grouping and tool-search options every tool helper accepts
|
|
84
|
+
* ({@link defineLocalTool}, {@link mantyxA2A}, {@link defineLocalA2A},
|
|
85
|
+
* {@link mantyxMcp}, {@link defineLocalMcp}). Both are optional and omitted
|
|
86
|
+
* from the wire when unset.
|
|
87
|
+
*/
|
|
88
|
+
export interface ToolGroupingOptions {
|
|
89
|
+
/**
|
|
90
|
+
* Group the tool belongs to; must match `^[a-zA-Z0-9_]{1,64}$`. Direct
|
|
91
|
+
* OpenAI receives native `namespace` tools; other providers see
|
|
92
|
+
* `[namespace]` at the start of the tool description. Describe namespaces
|
|
93
|
+
* for the model with the agent's `toolNamespaces`. On MCP refs it
|
|
94
|
+
* applies to every tool the server exposes; with `toolSearch` on, MCP tools
|
|
95
|
+
* default to the server's name as namespace.
|
|
96
|
+
*/
|
|
97
|
+
namespace?: string;
|
|
98
|
+
/**
|
|
99
|
+
* With the agent's `toolSearch` on, keep this
|
|
100
|
+
* tool's definition in every request instead of deferring it behind the
|
|
101
|
+
* search. Mark the few tools the agent uses on most turns. On MCP refs it
|
|
102
|
+
* applies to every tool the server exposes. No effect without `toolSearch`.
|
|
103
|
+
*/
|
|
104
|
+
alwaysLoaded?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/** The grouping fields as carried on a tool ref. See {@link ToolGroupingOptions}. */
|
|
107
|
+
export interface ToolGrouping {
|
|
108
|
+
readonly namespace?: string;
|
|
109
|
+
readonly alwaysLoaded?: boolean;
|
|
110
|
+
}
|
|
82
111
|
/**
|
|
83
112
|
* Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
|
|
84
113
|
* pre-shaped JSON Schema object. Used for both `parameters` and the new
|
|
85
114
|
* `outputSchema` field — same conversion path either way.
|
|
86
115
|
*/
|
|
87
116
|
export type LocalToolSchemaInput = ZodLikeObject | Record<string, unknown>;
|
|
88
|
-
export interface LocalTool<TArgs = Record<string, unknown>> {
|
|
117
|
+
export interface LocalTool<TArgs = Record<string, unknown>> extends ToolGrouping {
|
|
89
118
|
readonly kind: "local";
|
|
90
119
|
readonly name: string;
|
|
91
120
|
readonly description: string;
|
|
@@ -129,7 +158,7 @@ export interface LocalTool<TArgs = Record<string, unknown>> {
|
|
|
129
158
|
readonly retain: boolean;
|
|
130
159
|
readonly execute: (args: TArgs) => Promise<LocalToolOutput> | LocalToolOutput;
|
|
131
160
|
}
|
|
132
|
-
export interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
|
|
161
|
+
export interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> extends ToolGroupingOptions {
|
|
133
162
|
/** Lowercase alphanumeric + underscore, max 64 chars. */
|
|
134
163
|
name: string;
|
|
135
164
|
description?: string;
|
|
@@ -165,7 +194,7 @@ export declare function defineLocalTool<T extends ZodLikeObject | undefined>(opt
|
|
|
165
194
|
* MANTYX dials `agentCardUrl` over A2A's `message/send` RPC and forwards the
|
|
166
195
|
* remote agent's reply as the tool result.
|
|
167
196
|
*/
|
|
168
|
-
export interface A2AToolRef {
|
|
197
|
+
export interface A2AToolRef extends ToolGrouping {
|
|
169
198
|
readonly kind: "a2a";
|
|
170
199
|
readonly name: string;
|
|
171
200
|
readonly description?: string;
|
|
@@ -173,7 +202,7 @@ export interface A2AToolRef {
|
|
|
173
202
|
readonly headers?: Record<string, string>;
|
|
174
203
|
readonly contextId?: string;
|
|
175
204
|
}
|
|
176
|
-
export interface MantyxA2AOptions {
|
|
205
|
+
export interface MantyxA2AOptions extends ToolGroupingOptions {
|
|
177
206
|
/** Tool name surfaced to the model; must match `^[a-zA-Z0-9_]{1,64}$`. */
|
|
178
207
|
name: string;
|
|
179
208
|
description?: string;
|
|
@@ -199,7 +228,7 @@ export declare function mantyxA2A(opts: MantyxA2AOptions): A2AToolRef;
|
|
|
199
228
|
* the tool ref for the rest of the process lifetime. Re-construct the ref
|
|
200
229
|
* to force a refetch.
|
|
201
230
|
*/
|
|
202
|
-
export interface LocalA2ATool {
|
|
231
|
+
export interface LocalA2ATool extends ToolGrouping {
|
|
203
232
|
readonly kind: "a2a_local";
|
|
204
233
|
readonly name: string;
|
|
205
234
|
/** Where the SDK fetches the Agent Card from. Cached after the first hit. */
|
|
@@ -225,7 +254,7 @@ export interface ResolvedAgentCard {
|
|
|
225
254
|
/** Anything else the peer publishes; forwarded verbatim onto the wire. */
|
|
226
255
|
readonly [k: string]: unknown;
|
|
227
256
|
}
|
|
228
|
-
export interface DefineLocalA2AOptions {
|
|
257
|
+
export interface DefineLocalA2AOptions extends ToolGroupingOptions {
|
|
229
258
|
/** Tool name surfaced to the model. Must match `^[a-zA-Z0-9_]{1,64}$`. */
|
|
230
259
|
name: string;
|
|
231
260
|
/**
|
|
@@ -246,14 +275,14 @@ export declare function defineLocalA2A(opts: DefineLocalA2AOptions): LocalA2AToo
|
|
|
246
275
|
* Reference to a remote MCP server (Streamable HTTP) discovered + proxied by
|
|
247
276
|
* MANTYX. Each tool in the catalog is exposed to the model as `<name>_<tool>`.
|
|
248
277
|
*/
|
|
249
|
-
export interface McpToolRef {
|
|
278
|
+
export interface McpToolRef extends ToolGrouping {
|
|
250
279
|
readonly kind: "mcp";
|
|
251
280
|
readonly name: string;
|
|
252
281
|
readonly url: string;
|
|
253
282
|
readonly headers?: Record<string, string>;
|
|
254
283
|
readonly toolFilter?: string[];
|
|
255
284
|
}
|
|
256
|
-
export interface MantyxMcpOptions {
|
|
285
|
+
export interface MantyxMcpOptions extends ToolGroupingOptions {
|
|
257
286
|
/** Server label; used to prefix every discovered tool. */
|
|
258
287
|
name: string;
|
|
259
288
|
/** Streamable HTTP MCP endpoint. */
|
|
@@ -301,7 +330,7 @@ export interface LocalMcpStdioTransport {
|
|
|
301
330
|
* Connections are reused across runs and across messages within a session
|
|
302
331
|
* and closed on `runAgent` completion / `session.end()`.
|
|
303
332
|
*/
|
|
304
|
-
export interface LocalMcpServer {
|
|
333
|
+
export interface LocalMcpServer extends ToolGrouping {
|
|
305
334
|
readonly kind: "mcp_local";
|
|
306
335
|
readonly name: string;
|
|
307
336
|
/** One-of with {@link stdio} — the transport spec is mutually exclusive. */
|
|
@@ -357,7 +386,7 @@ export interface McpClientLike {
|
|
|
357
386
|
[k: string]: unknown;
|
|
358
387
|
}>;
|
|
359
388
|
}
|
|
360
|
-
export interface DefineLocalMcpOptions {
|
|
389
|
+
export interface DefineLocalMcpOptions extends ToolGroupingOptions {
|
|
361
390
|
/**
|
|
362
391
|
* Server label echoed back as `mcpServer` on every `local_tool_call`. The
|
|
363
392
|
* SDK auto-prefixes each discovered tool's wire-level `name` with
|
|
@@ -390,6 +419,13 @@ export type ToolRef = LocalTool | A2AToolRef | LocalA2ATool | McpToolRef | Local
|
|
|
390
419
|
export declare function isLocalTool(t: ToolRef): t is LocalTool;
|
|
391
420
|
export declare function isLocalA2ATool(t: ToolRef): t is LocalA2ATool;
|
|
392
421
|
export declare function isLocalMcpServer(t: ToolRef): t is LocalMcpServer;
|
|
422
|
+
/** @internal Throws when `namespace` is not a valid namespace name. */
|
|
423
|
+
export declare function assertToolNamespace(namespace: string, label?: string): void;
|
|
424
|
+
/** @internal The grouping fields of a tool ref as the wire names them; unset ones are left out. */
|
|
425
|
+
export declare function toolGroupingWire(t: ToolGrouping): {
|
|
426
|
+
namespace?: string;
|
|
427
|
+
alwaysLoaded?: boolean;
|
|
428
|
+
};
|
|
393
429
|
/**
|
|
394
430
|
* Compose the wire-level (model-facing) tool name for a `mcp_local` entry.
|
|
395
431
|
* The SDK auto-prefixes every discovered tool's bare name with the server
|
package/dist/version.d.ts
CHANGED
|
@@ -459,7 +459,7 @@ selector grammar as `modelId`. TypeScript uses `fallbackModelId`, Python uses
|
|
|
459
459
|
`fallback_model_id`, and Go uses `FallbackModelID`. The fallback must resolve
|
|
460
460
|
to a different provider/model pair from the primary.
|
|
461
461
|
|
|
462
|
-
During agent execution (including
|
|
462
|
+
During agent execution (including resumes after a worker shutdown), after normal
|
|
463
463
|
retries are exhausted, MANTYX switches the failed model invocation
|
|
464
464
|
for retryable overload, provider server, unreachable-provider, or upstream
|
|
465
465
|
timeout errors. It does not switch for authentication, invalid requests, quota
|
|
@@ -559,8 +559,8 @@ Rules:
|
|
|
559
559
|
- They stay in effect for the whole run: context compaction that drops or
|
|
560
560
|
summarizes the run's user message keeps the instructions, and they count
|
|
561
561
|
toward the context budget.
|
|
562
|
-
- A run that resumes after
|
|
563
|
-
|
|
562
|
+
- A run that resumes after a worker shutdown keeps the instructions it
|
|
563
|
+
started with, in the same placement.
|
|
564
564
|
- File attachments on the user message are unaffected.
|
|
565
565
|
|
|
566
566
|
SDKs: TypeScript `turnInstructions` / `turnInstructionsAuthority` (run spec,
|
|
@@ -812,6 +812,36 @@ Per-run lifecycle:
|
|
|
812
812
|
Older SDKs that ignore the `kind` discriminator still see a normal
|
|
813
813
|
`local_tool_call` and can match on `name` alone.
|
|
814
814
|
|
|
815
|
+
### 4.3.1 Tool namespaces and tool search
|
|
816
|
+
|
|
817
|
+
Every tool ref kind accepts two optional fields, and the agent spec two more:
|
|
818
|
+
|
|
819
|
+
| Field | Where | Notes |
|
|
820
|
+
| --------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
821
|
+
| `namespace` | any tool ref | Group the tool belongs to (match `/^[a-zA-Z0-9_]{1,64}$/`). On an MCP ref it applies to every tool of the server. Direct OpenAI receives native `namespace` tools; every other provider sees `[namespace]` at the start of the tool's description. With `toolSearch`, MCP tools without a namespace use the server's `name`. |
|
|
822
|
+
| `alwaysLoaded` | any tool ref | With `toolSearch`, keep this tool's full definition in every request instead of deferring it. Mark the few tools the agent uses on most turns. On an MCP ref it applies to every tool of the server. Ignored without `toolSearch`. |
|
|
823
|
+
| `toolSearch` | agent spec | Opt in to tool search (default off). Tools not marked `alwaysLoaded` are deferred and the model searches for the ones it needs. `spawn_subagent` is always loaded. |
|
|
824
|
+
| `toolNamespaces` | agent spec | `[{ name, description }]` (up to 64): what each namespace is for, shown to the model. A namespace without one is described by its tool names. |
|
|
825
|
+
|
|
826
|
+
Where tool search runs:
|
|
827
|
+
|
|
828
|
+
| Provider (as MANTYX calls it) | Tool search | Namespaces |
|
|
829
|
+
| --------------------------------------------- | ---------------------------------------------------- | ---------------------------------- |
|
|
830
|
+
| OpenAI, direct (Responses API, GPT-5.4+) | Native: `tool_search` + `defer_loading` | Native `namespace` tools |
|
|
831
|
+
| Anthropic API | Native: `tool_search_tool_bm25` + `defer_loading` | In the description |
|
|
832
|
+
| Gemini 3+ (Interactions API) | Native (preview): `tool_search` + `defer_loading` | In the description |
|
|
833
|
+
| Gemini 2.5 and older, Bedrock, OpenRouter and other gateways | Not supported: every tool is sent as usual | In the description |
|
|
834
|
+
|
|
835
|
+
MANTYX calls Gemini 3 and later through Google's Interactions API, the only
|
|
836
|
+
Gemini API with tool retrieval. Older Gemini models are called through
|
|
837
|
+
`generateContent` and receive every tool.
|
|
838
|
+
|
|
839
|
+
A model that rejects tool search or namespaces is remembered for the worker
|
|
840
|
+
process and gets the plain tool list instead. On the loop benchmark with
|
|
841
|
+
about 150 tools, OpenAI tool search cut wrong-tool calls and input tokens
|
|
842
|
+
but completed slightly fewer goals: mark the tools an agent needs on most
|
|
843
|
+
turns `alwaysLoaded`.
|
|
844
|
+
|
|
815
845
|
### 4.4 `reasoningLevel` (provider thinking strength)
|
|
816
846
|
|
|
817
847
|
`reasoningLevel` controls how much extended-thinking / reasoning effort the
|
|
@@ -829,7 +859,7 @@ For direct OpenAI reasoning runs, MANTYX keeps `store: false` and carries the
|
|
|
829
859
|
Responses API's encrypted reasoning items across tool turns. Long-running
|
|
830
860
|
OpenAI contexts can additionally use provider-native compaction, which replaces
|
|
831
861
|
the earlier in-run prefix with an opaque retained-context item instead of
|
|
832
|
-
silently dropping it. These opaque items survive
|
|
862
|
+
silently dropping it. These opaque items survive shutdown checkpoints,
|
|
833
863
|
but are intentionally not persisted into the next separate user message.
|
|
834
864
|
OpenRouter, Grok, and generic OpenAI-compatible providers do not receive these
|
|
835
865
|
OpenAI-specific request fields.
|
|
@@ -915,7 +945,7 @@ are used only when OpenRouter does not report a cost.
|
|
|
915
945
|
`newLoop` is an optional boolean on run creation, session creation, and session
|
|
916
946
|
message requests. Omission keeps the legacy loop for new runs/sessions. A message
|
|
917
947
|
inherits its session's setting; an explicit `false` overrides it for that message
|
|
918
|
-
only. Checkpoints retain the selected mode through
|
|
948
|
+
only. Checkpoints retain the selected mode through worker restarts.
|
|
919
949
|
The chat `/api/chat` and `/api/chat/stream` request bodies also accept this flag
|
|
920
950
|
per message (multipart accepts the strings `"true"` and `"false"`).
|
|
921
951
|
|
|
@@ -960,8 +990,7 @@ With `newLoop: true`:
|
|
|
960
990
|
- Recovery from an empty assistant turn allows further tool work instead of
|
|
961
991
|
instructing the model to finalize immediately.
|
|
962
992
|
|
|
963
|
-
|
|
964
|
-
remain in force. This mode does not introduce a code workbench, persistent
|
|
993
|
+
Explicit guard settings and maximum tool-turn limits remain in force. This mode does not introduce a code workbench, persistent
|
|
965
994
|
specialist sessions, or provider-native history across separate user messages.
|
|
966
995
|
Provider-native compaction retains its separate explicit setting.
|
|
967
996
|
Completion verification still depends on the host's guard and available evidence;
|
|
@@ -1064,10 +1093,6 @@ SDK result/error fields are optional so they remain compatible with older
|
|
|
1064
1093
|
servers. A strict compatibility test should require `schemaEnforced: true` and
|
|
1065
1094
|
`unconstrainedFallbackOccurred: false`.
|
|
1066
1095
|
|
|
1067
|
-
`plan: { planOnly: true }` skips the agent execution loop, so it cannot enforce
|
|
1068
|
-
a run-level output schema. Combining plan-only execution with strict
|
|
1069
|
-
enforcement terminates as `structured_output_not_supported`.
|
|
1070
|
-
|
|
1071
1096
|
**Inheritance for sessions:**
|
|
1072
1097
|
|
|
1073
1098
|
- `POST /agent-sessions { outputSchema }` — sets the session-default,
|
|
@@ -1260,7 +1285,7 @@ including `on_track` checks — so SDK clients can render supervisor activity.
|
|
|
1260
1285
|
When `action` is `redirect` or `finalize`, the pipeline has already applied
|
|
1261
1286
|
the verdict by the time the event arrives.
|
|
1262
1287
|
|
|
1263
|
-
### 4.9 `plan` (task plan
|
|
1288
|
+
### 4.9 `plan` (task plan)
|
|
1264
1289
|
|
|
1265
1290
|
`plan` turns on the **task plan**, a live checklist the agent maintains as
|
|
1266
1291
|
it works. It is **opt-in** on API/ephemeral runs,
|
|
@@ -1279,9 +1304,6 @@ separate tracker LLM call.
|
|
|
1279
1304
|
"steps": ["Snapshot current schema", "Apply migration", "Backfill rows", "Verify counts"]
|
|
1280
1305
|
}
|
|
1281
1306
|
|
|
1282
|
-
"plan": { "planOnly": true } // produce the plan, do NOT run the agent
|
|
1283
|
-
"plan": { "planOnly": true, "steps": ["…", "…"] } // plan-only with a caller-provided checklist
|
|
1284
|
-
|
|
1285
1307
|
"plan": false // (or omit) no planning — a plain run
|
|
1286
1308
|
```
|
|
1287
1309
|
|
|
@@ -1291,19 +1313,18 @@ separate tracker LLM call.
|
|
|
1291
1313
|
| `true` / `"auto"` | Exposes `update_task_plan`; the executing agent decides during its normal first turn whether multi-step tracking is useful. No separate planning LLM call. |
|
|
1292
1314
|
| `"required"` | Requires `update_task_plan` before substantive tools and rejects premature final answers while required steps remain unfinished (bounded continuation guard). |
|
|
1293
1315
|
| `{ mode?, steps, brief? }` | Seeds an authoritative checklist. `mode` defaults to `auto`; use `required` to enforce initialization/execution. |
|
|
1294
|
-
| `{ planOnly: true, steps? }` | Produce the plan (classifier when `steps` omitted, otherwise the provided checklist) and **terminate without executing the agent loop**. The terminal `result` carries `data.plan` (see §7). |
|
|
1295
1316
|
|
|
1296
1317
|
| Field | Type | Required | Notes |
|
|
1297
1318
|
| ---------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------- |
|
|
1298
|
-
| `planOnly` | boolean | no | When `true`, the run stops after producing the plan. |
|
|
1299
1319
|
| `mode` | string | no | `off`, `auto`, or `required`. Defaults to `auto`. |
|
|
1300
1320
|
| `brief` | string | no | One-line objective for a caller-provided plan. Clamped server-side. |
|
|
1301
1321
|
| `steps` | string[] | no | Caller-provided checklist titles. Empty/omitted ⇒ auto-classify. Count + per-step length clamped server-side. |
|
|
1302
1322
|
|
|
1303
|
-
Plan-only runs
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1323
|
+
Plan-only runs (`planOnly: true`, which produce a plan and stop without
|
|
1324
|
+
running the agent; the terminal `result` carries it under `data.plan`) are
|
|
1325
|
+
**deprecated**. Current SDKs no longer offer them; the server still honors
|
|
1326
|
+
the flag so older SDK versions keep working, and may drop it in a future
|
|
1327
|
+
protocol version.
|
|
1307
1328
|
|
|
1308
1329
|
**Inheritance for sessions.**
|
|
1309
1330
|
|
|
@@ -1312,6 +1333,21 @@ runs do not use the classifier/tracker path.
|
|
|
1312
1333
|
- `POST /agent-sessions/:id/messages { plan }` — optional per-message override;
|
|
1313
1334
|
applies to that one run only and does not mutate the session's stored value.
|
|
1314
1335
|
|
|
1336
|
+
### 4.9.1 `subagents` (delegate to sub-agents)
|
|
1337
|
+
|
|
1338
|
+
`subagents: true` lets the agent start copies of itself; `{ agents: [{ name,
|
|
1339
|
+
description, systemPrompt, modelId?, tools?, … }] }` defines named sub-agents
|
|
1340
|
+
with their own instructions, model and tools (`tools` entries are names of the
|
|
1341
|
+
parent's tools or full tool refs); `{ self, agents, maxPerRun, maxConcurrent }`
|
|
1342
|
+
combines both. The run gets a built-in `spawn_subagent({ agent?, description,
|
|
1343
|
+
prompt })` tool. Each call starts a linked child run on a fresh context and
|
|
1344
|
+
returns its final report as the tool result; children cannot spawn children.
|
|
1345
|
+
The parent stream gains `subagent_started` (with `agent`) and `subagent_result`
|
|
1346
|
+
events, and a sub-agent's local tool calls are mirrored onto it as
|
|
1347
|
+
`local_tool_call` with `subagentRunId` (post their results to the parent run as
|
|
1348
|
+
usual). Accepted on `POST /agent-runs` and `POST /agent-sessions`. Full
|
|
1349
|
+
reference: [`docs/subagents.md`](subagents.md).
|
|
1350
|
+
|
|
1315
1351
|
### 4.10 `metadata` (developer-supplied KV for filtering)
|
|
1316
1352
|
|
|
1317
1353
|
`metadata` is a flat string→string KV that is **persisted alongside the run /
|
|
@@ -1453,6 +1489,20 @@ spec, plus the cost-attribution triple `tokens` / `turns` / `model` —
|
|
|
1453
1489
|
see §7.1) without subscribing to live events. Useful for polling long
|
|
1454
1490
|
runs or attributing spend after the SSE stream was already consumed.
|
|
1455
1491
|
|
|
1492
|
+
A run's `status` is one of:
|
|
1493
|
+
|
|
1494
|
+
| Status | Meaning |
|
|
1495
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1496
|
+
| `queued` | Accepted, waiting for a worker. |
|
|
1497
|
+
| `running` | A worker is executing the agent loop. |
|
|
1498
|
+
| `awaiting_local_tool` | Suspended until the client posts the result of a client-resolved tool (§8). The SSE stream stays open, and the run continues on the same stream as soon as `POST .../tool-results` arrives. Not terminal: keep reading the stream. |
|
|
1499
|
+
| `succeeded` | Terminal: the stream ended with a `result` event. |
|
|
1500
|
+
| `failed` | Terminal: the stream ended with an `error` event (or a non-success `result`). |
|
|
1501
|
+
| `cancelled` | Terminal: the stream ended with a `cancelled` event. |
|
|
1502
|
+
|
|
1503
|
+
Clients should treat unknown status values as non-terminal and keep
|
|
1504
|
+
following the stream.
|
|
1505
|
+
|
|
1456
1506
|
## 6. Sessions
|
|
1457
1507
|
|
|
1458
1508
|
```
|
|
@@ -1623,15 +1673,17 @@ data: <utf-8 JSON>
|
|
|
1623
1673
|
// Gemini `includeThoughts`, OpenAI `reasoning_content` on reasoning models).
|
|
1624
1674
|
{ "seq": 2, "type": "thinking_delta", "data": { "text": "First, I should…" } }
|
|
1625
1675
|
|
|
1626
|
-
// completed assistant message (text + any tool calls about to execute)
|
|
1627
|
-
|
|
1676
|
+
// completed assistant message (text + any tool calls about to execute).
|
|
1677
|
+
// `usage` is this LLM call's tokens (same shape as the terminal `tokens`), so a
|
|
1678
|
+
// live view can add up a run's usage before the terminal event carries the total.
|
|
1679
|
+
{ "seq": 3, "type": "assistant_message", "data": { "text": "...", "toolCalls": [...],
|
|
1680
|
+
"usage": { "inputTokens": 1200, "cachedTokens": 800, "reasoningTokens": 0, "outputTokens": 90 } } }
|
|
1628
1681
|
|
|
1629
1682
|
// server-side tool call/result (informational; SDK does not act on these)
|
|
1630
1683
|
{ "seq": 4, "type": "tool_call", "data": { "toolUseId": "...", "name": "...", "input": {...} } }
|
|
1631
1684
|
{ "seq": 5, "type": "tool_result", "data": { "toolUseId": "...", "name": "...", "ok": true, "summary": "..." } }
|
|
1632
1685
|
|
|
1633
|
-
// files a server-
|
|
1634
|
-
// `storageKey` → fetch via the admin download route; inline base64 `data` (dev fallback) is redacted from the stream.
|
|
1686
|
+
// historical only (replays of old runs): files a removed server-executed tool produced; no longer emitted.
|
|
1635
1687
|
{ "seq": 5, "type": "tool_files", "data": { "name": "render_chart", "files": [ { "filename": "chart.png", "mimeType": "image/png", "sizeBytes": 20480, "storageKey": "chat-attachments/<tenant>/tool-results/<tool>/<uuid>.png" } ] } }
|
|
1636
1688
|
|
|
1637
1689
|
// LOCAL tool call — SDK MUST POST a tool-result for the same toolUseId.
|
|
@@ -1721,17 +1773,6 @@ data: <utf-8 JSON>
|
|
|
1721
1773
|
"turns": 2,
|
|
1722
1774
|
"model": { "id": "platform:demo", "provider": "anthropic", "vendorModelId": "claude-opus-4-7" }
|
|
1723
1775
|
} }
|
|
1724
|
-
// plan-only terminal result (see §4.9): the agent loop did NOT run. `data.plan`
|
|
1725
|
-
// carries the structured checklist; `turns` is 0 and `tokens` are zeroed
|
|
1726
|
-
// (classifier usage is metered separately under the `task_planning` surface).
|
|
1727
|
-
{ "seq": 5, "type": "result", "data": {
|
|
1728
|
-
"subtype": "success",
|
|
1729
|
-
"text": "Compare Q3 vs Q4 revenue.\n\n1. Pull revenue\n2. Compute deltas",
|
|
1730
|
-
"plan": { "brief": "Compare Q3 vs Q4 revenue.", "steps": [ { "title": "Pull revenue", "status": "pending" }, { "title": "Compute deltas", "status": "pending" } ] },
|
|
1731
|
-
"tokens": { "inputTokens": 0, "cachedTokens": 0, "reasoningTokens": 0, "outputTokens": 0 },
|
|
1732
|
-
"turns": 0,
|
|
1733
|
-
"model": { "id": "platform:demo", "provider": "openai", "vendorModelId": "gpt-5.4-mini" }
|
|
1734
|
-
} }
|
|
1735
1776
|
{ "seq": 8, "type": "cancelled", "data": {} }
|
|
1736
1777
|
```
|
|
1737
1778
|
|
|
@@ -1836,6 +1877,11 @@ Content-Type: application/json
|
|
|
1836
1877
|
already satisfied, or the run has terminated. `409 run_terminal` if the run
|
|
1837
1878
|
has already produced a `result` event.
|
|
1838
1879
|
|
|
1880
|
+
While a `local_tool_call` is unanswered the run reports status
|
|
1881
|
+
`awaiting_local_tool`. The SSE stream stays open (only `: ping` keep-alive
|
|
1882
|
+
comments arrive meanwhile) and the run continues on the same stream once the
|
|
1883
|
+
result is posted; there is no separate resume call.
|
|
1884
|
+
|
|
1839
1885
|
`result` MUST be a string; SDKs serialize structured outputs as JSON before
|
|
1840
1886
|
posting. Errors are surfaced to the model as a tool-error response.
|
|
1841
1887
|
|
|
@@ -1908,9 +1954,12 @@ listing has no `agentId` or `targetKinds` filter.
|
|
|
1908
1954
|
|
|
1909
1955
|
Developer API requests use fixed 60-second sliding windows keyed by workspace
|
|
1910
1956
|
and credential. New run starts have their own bucket (default 120/min);
|
|
1911
|
-
tool
|
|
1957
|
+
local-tool results have their own (default 6,000/min, never below the
|
|
1958
|
+
workspace's lifecycle value); feedback and cancellation use the lifecycle
|
|
1912
1959
|
bucket (default 600/min); other mutations default to 120/min. Platform
|
|
1913
|
-
operators can override
|
|
1960
|
+
operators can override the run-start, lifecycle and mutation maxima per
|
|
1961
|
+
workspace. The SDKs retry a tool result that gets a 429 with backoff; a
|
|
1962
|
+
result that never lands leaves the run waiting until the local-tool timeout. Reads, status checks,
|
|
1914
1963
|
and SSE opens/reconnects use a separate high transport limit and never consume
|
|
1915
1964
|
run-start capacity.
|
|
1916
1965
|
|
|
@@ -2004,11 +2053,10 @@ A reference SDK should:
|
|
|
2004
2053
|
log line, telemetry). Do **not** abort the run on these events; the run
|
|
2005
2054
|
continues through `result` / `error` / `cancelled` as usual.
|
|
2006
2055
|
- Accept `plan` from the caller (`off` / `auto` / `required`, the boolean
|
|
2007
|
-
compatibility aliases, or `{ mode?, steps?, brief
|
|
2056
|
+
compatibility aliases, or `{ mode?, steps?, brief? }`) and pass
|
|
2008
2057
|
it through unchanged (see §4.9). Render `task_plan.data.plan` as the
|
|
2009
2058
|
canonical checklist. Apply snapshots idempotently by `planId` + `revision`
|
|
2010
2059
|
and use run-event `seq` to order multiple transitions in one revision.
|
|
2011
|
-
For `planOnly` runs read the final checklist from `result.data.plan`.
|
|
2012
2060
|
- On terminal `result`, resolve the call. On `error` subtype, throw.
|
|
2013
2061
|
4. Re-emit assistant deltas/events as a stream/iterator for callers who care
|
|
2014
2062
|
about live output.
|
package/docs/wire-protocol.md
CHANGED
|
@@ -426,13 +426,13 @@ The vocabulary (`EphemeralEventType` in `bus.ts`):
|
|
|
426
426
|
| `assistant_delta` | M → SDK | Many | Streamed assistant text token / chunk. |
|
|
427
427
|
| `thinking_delta` | M → SDK | Many (iff `reasoningLevel > 0`) | Streamed extended-thinking text (provider redacts when policy requires). |
|
|
428
428
|
| `tool_result` | M → SDK | Per server-resolved tool call | Informational — tells the SDK that MANTYX ran a server-resolved tool (`a2a`, `mcp`) and got a result. The SDK does not need to act on it. |
|
|
429
|
-
| `tool_files` | M → SDK |
|
|
429
|
+
| `tool_files` | M → SDK | Historical: no longer emitted | Only in replays of old runs (see §4.2.1): file metadata a removed server-executed tool kind produced. Inline bytes are redacted from the stream; download via the admin route. SDKs may ignore it. |
|
|
430
430
|
| `local_tool_call` | M → SDK | Per client-resolved tool call | **Action required.** SDK must POST a tool-result. |
|
|
431
431
|
| `local_tool_result_in` | M → SDK | Per client-resolved tool call | Informational mirror of the tool-result the SDK just posted, persisted for observability. Re-emitted to late subscribers so they can replay the conversation. Any `files` carry only metadata on the wire (base64 `data` is redacted). |
|
|
432
432
|
| `loop_detected` | M → SDK | 0–2× per run (soft nudge + optional hard cutoff) | Observability for the loop-detection guard (see §8). The server already substituted the synthetic skip + steering nudge — SDK clients render a status note (`looping — nudged` / `looping — gave up`) and otherwise leave the run alone. |
|
|
433
433
|
| `tool_budget_exceeded` | M → SDK | Per intercepted tool call | Observability for per-tool call budgets (see §8). The synthetic `tool_result` carrying the "budget exceeded — pivot or finalize" body lands on the normal tool-result channel; this event is purely so SDK clients can surface a UI banner. |
|
|
434
434
|
| `supervisor` | M → SDK | 0–N× per run (every `interval` LLM calls) | Run-supervisor check (see §4.7 / §8.4). Fired on **every** review — including `on_track` — so SDK clients can render supervisor activity. When the judge steers the run (`redirect` / `finalize`), the pipeline has already injected the steering message or forced a tools-disabled finalize turn. |
|
|
435
|
-
| `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the task plan (see §4.9 / §8.5). Emitted
|
|
435
|
+
| `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the task plan (see §4.9 / §8.5). Emitted when the plan is created (caller-supplied or agent-created), then again whenever the agent's `update_task_plan` call changes step statuses. **Non-terminal.** |
|
|
436
436
|
| `assistant_message` | M → SDK | 1× per turn | Final assistant message for the turn (concatenated, persistence-ready). |
|
|
437
437
|
| `result` | M → SDK | 1× terminal | Successful completion. Carries the final assistant text and run summary. |
|
|
438
438
|
| `error` | M → SDK | 1× terminal | Failure. Carries `error` (message), `code` / `errorClass` (category), `finishReason`, and an optional `partialText` salvage payload. See §4.7. |
|
|
@@ -469,14 +469,13 @@ progress text — it's not part of the canonical assistant response.
|
|
|
469
469
|
|
|
470
470
|
Purely informational. The SDK does not respond.
|
|
471
471
|
|
|
472
|
-
### 4.2.1 `tool_files` (
|
|
472
|
+
### 4.2.1 `tool_files` (historical)
|
|
473
473
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
and
|
|
479
|
-
`tool_result` summary and shares its display `name`.
|
|
474
|
+
No current tool kind emits this event. It appears only when replaying runs
|
|
475
|
+
recorded while server-executed workspace tools existed: file metadata for files
|
|
476
|
+
such a tool produced, preceding the matching `tool_result` summary and sharing
|
|
477
|
+
its display `name`. It was purely for observability (the Calls dashboard lists
|
|
478
|
+
and downloads the files); SDK clients may ignore it.
|
|
480
479
|
|
|
481
480
|
```jsonc
|
|
482
481
|
{
|
|
@@ -949,7 +948,7 @@ non-breaking since those return types were already objects).
|
|
|
949
948
|
{ "title": "Compute deltas by segment", "status": "pending" },
|
|
950
949
|
{ "title": "Summarize the top drivers", "status": "pending" } ] } }
|
|
951
950
|
|
|
952
|
-
//
|
|
951
|
+
// Plan update — emitted whenever step statuses change during the run.
|
|
953
952
|
{ "seq": 18, "type": "task_plan",
|
|
954
953
|
"data": { "brief": "Compare Q3 vs Q4 revenue and summarize drivers.",
|
|
955
954
|
"steps": [ { "title": "Pull Q3 and Q4 revenue", "status": "done" },
|
|
@@ -965,9 +964,7 @@ non-breaking since those return types were already objects).
|
|
|
965
964
|
Observability for the **task plan** (see §8.5). Emitted only when
|
|
966
965
|
the run carries a `plan` spec field. **Non-terminal** — SDK clients render a
|
|
967
966
|
live checklist that advances as the run progresses; the terminal `result`
|
|
968
|
-
stays text-only
|
|
969
|
-
right after the plan and the final checklist also rides on the terminal
|
|
970
|
-
`result` under `data.plan` (§8.5).
|
|
967
|
+
stays text-only.
|
|
971
968
|
|
|
972
969
|
---
|
|
973
970
|
|
|
@@ -1006,10 +1003,13 @@ Server response codes:
|
|
|
1006
1003
|
| `404` | `unknown_tool_use` — `toolUseId` doesn't match any pending call (already answered or unknown id). |
|
|
1007
1004
|
| `409` | `run_terminal` — the run already finished (success, failure, cancel, or local-tool timeout). The result is dropped. |
|
|
1008
1005
|
|
|
1009
|
-
The runner
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1006
|
+
The runner waits a few seconds in process for a result; after that the
|
|
1007
|
+
run is suspended (`awaiting_local_tool`) and resumes once every pending
|
|
1008
|
+
call has a posted result. A call with no result within the local-tool
|
|
1009
|
+
timeout (default 5 minutes) is resumed as a
|
|
1010
|
+
"Timed out waiting for local tool result" tool error. A `409` for a
|
|
1011
|
+
tool-result POST means the run already ended (for example it was
|
|
1012
|
+
cancelled).
|
|
1013
1013
|
|
|
1014
1014
|
---
|
|
1015
1015
|
|
|
@@ -1098,10 +1098,6 @@ Every terminal `result` and `error` includes the `structuredOutput` block from
|
|
|
1098
1098
|
`unconstrainedFallbackOccurred` is `false`, and the mechanism is the expected
|
|
1099
1099
|
provider path.
|
|
1100
1100
|
|
|
1101
|
-
`plan: { planOnly: true }` does not execute the agent loop and therefore cannot
|
|
1102
|
-
enforce a run-level output schema. Combining it with strict enforcement
|
|
1103
|
-
terminates explicitly as `structured_output_not_supported`.
|
|
1104
|
-
|
|
1105
1101
|
Validation (server-side, `400 invalid_request` on violation):
|
|
1106
1102
|
|
|
1107
1103
|
| Constraint | Limit |
|
|
@@ -1235,8 +1231,8 @@ banners without re-parsing tool-result bodies:
|
|
|
1235
1231
|
- `tool_budget_exceeded` — fired each time a call is intercepted. See §4.6.
|
|
1236
1232
|
- `supervisor` — fired on every run-supervisor review (`on_track`,
|
|
1237
1233
|
`redirect`, or `finalize`). See §4.7.
|
|
1238
|
-
- `task_plan` — fired when a run carries a `plan` spec field:
|
|
1239
|
-
|
|
1234
|
+
- `task_plan` — fired when a run carries a `plan` spec field: when the
|
|
1235
|
+
plan is created, then on each accepted `update_task_plan` change. See §4.9 / §8.5.
|
|
1240
1236
|
|
|
1241
1237
|
Both guard events (`loop_detected`, `tool_budget_exceeded`) are
|
|
1242
1238
|
observability-only: the server has already substituted the synthetic
|
|
@@ -1315,7 +1311,7 @@ omit the field to keep it disabled. The wire field above controls the
|
|
|
1315
1311
|
Each review emits a SSE `supervisor` event (§4.7). Supervisor LLM usage is
|
|
1316
1312
|
recorded under the `supervisor` usage surface for cost attribution.
|
|
1317
1313
|
|
|
1318
|
-
### 8.5 `plan` (task plan
|
|
1314
|
+
### 8.5 `plan` (task plan)
|
|
1319
1315
|
|
|
1320
1316
|
The optional `plan` field turns on the **task plan**, a live checklist the
|
|
1321
1317
|
agent maintains as it works. It is **opt-in** on ephemeral runs, same as
|
|
@@ -1329,9 +1325,6 @@ agent maintains as it works. It is **opt-in** on ephemeral runs, same as
|
|
|
1329
1325
|
"steps": ["Snapshot current schema", "Apply migration", "Backfill rows", "Verify counts"]
|
|
1330
1326
|
}
|
|
1331
1327
|
|
|
1332
|
-
"plan": { "planOnly": true } // produce the plan, do NOT run the agent
|
|
1333
|
-
"plan": { "planOnly": true, "steps": ["…", "…"] } // plan-only with a caller-provided checklist
|
|
1334
|
-
|
|
1335
1328
|
"plan": false // (or omit) no planning — a plain run
|
|
1336
1329
|
```
|
|
1337
1330
|
|
|
@@ -1340,46 +1333,17 @@ agent maintains as it works. It is **opt-in** on ephemeral runs, same as
|
|
|
1340
1333
|
| omitted / `false` | No planning. Default. |
|
|
1341
1334
|
| `true` | Pre-flight classifier decides whether a multi-step plan is warranted. If so, a `task_plan` event is emitted, the checklist is injected into the user turn, and step statuses are tracked (advancing on tool activity and on each supervisor review) until the run ends. If the classifier declines, the run proceeds normally with no plan. |
|
|
1342
1335
|
| `{ steps, brief? }` | Caller-provided checklist used verbatim — **skips** the classifier (and its `MIN_STEPS` gate). Injected + tracked like the auto case. |
|
|
1343
|
-
| `{ planOnly: true, steps? }` | Produce the plan (classifier when `steps` omitted, otherwise the provided checklist) and **terminate without executing the agent loop**. |
|
|
1344
1336
|
|
|
1345
1337
|
| Field | Type | Notes |
|
|
1346
1338
|
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
1347
|
-
| `planOnly` | boolean | Optional. When `true`, the run stops after producing the plan; the terminal `result` carries it under `data.plan`. |
|
|
1348
1339
|
| `brief` | string | Optional one-line objective for a caller-provided plan. Clamped server-side. |
|
|
1349
1340
|
| `steps` | string[] | Optional caller-provided checklist titles. Empty/omitted ⇒ auto-classify. Count and per-step length clamped server-side. |
|
|
1350
1341
|
| (literal `true`) | `true` | Auto pre-flight classifier + live tracking. |
|
|
1351
1342
|
|
|
1352
|
-
|
|
1353
|
-
terminal `result`
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
{
|
|
1357
|
-
"seq": 5,
|
|
1358
|
-
"type": "result",
|
|
1359
|
-
"data": {
|
|
1360
|
-
"subtype": "success",
|
|
1361
|
-
"text": "Migrate the billing tables and backfill\n\n1. Snapshot current schema\n2. Apply migration\n3. Backfill rows\n4. Verify counts",
|
|
1362
|
-
"plan": {
|
|
1363
|
-
"brief": "Migrate the billing tables and backfill",
|
|
1364
|
-
"steps": [
|
|
1365
|
-
{ "title": "Snapshot current schema", "status": "pending" } /* … */,
|
|
1366
|
-
],
|
|
1367
|
-
},
|
|
1368
|
-
"tokens": {
|
|
1369
|
-
/* zeroed — classifier usage is metered separately */
|
|
1370
|
-
},
|
|
1371
|
-
"turns": 0,
|
|
1372
|
-
"model": { "id": "…", "provider": "…", "vendorModelId": "…" },
|
|
1373
|
-
},
|
|
1374
|
-
}
|
|
1375
|
-
```
|
|
1376
|
-
|
|
1377
|
-
When the classifier declines in plan-only mode, `data.plan.steps` is `[]` and
|
|
1378
|
-
`data.text` explains that no multi-step plan was warranted. Plan-only runs do
|
|
1379
|
-
**not** append an assistant turn to a session (the plan is not the answer).
|
|
1380
|
-
|
|
1381
|
-
Planner LLM usage (the classifier and the per-run tracker) is metered under
|
|
1382
|
-
the `task_planning` usage surface for cost attribution.
|
|
1343
|
+
Plan-only runs (`planOnly: true`: produce the plan and stop without running
|
|
1344
|
+
the agent, with the plan on the terminal `result` under `data.plan`) are
|
|
1345
|
+
**deprecated**. Current SDKs no longer offer them; the server still honors
|
|
1346
|
+
the flag so older SDK versions keep working.
|
|
1383
1347
|
|
|
1384
1348
|
### 8.6 Session inheritance
|
|
1385
1349
|
|
|
@@ -1401,11 +1365,11 @@ POST /api/v1/workspaces/{slug}/agent-runs/{runId}/cancel
|
|
|
1401
1365
|
Authorization: Bearer <api-key>
|
|
1402
1366
|
```
|
|
1403
1367
|
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1368
|
+
Marks the run `cancelled`, appends the terminal `cancelled` event, and
|
|
1369
|
+
publishes a Valkey signal. The runner stops at once (the in-flight model
|
|
1370
|
+
call is torn down and pending local-tool waits end) and writes nothing
|
|
1371
|
+
more: no `result` or `error` follows `cancelled`. Results posted for
|
|
1372
|
+
outstanding `local_tool_call`s are refused with `409`.
|
|
1409
1373
|
|
|
1410
1374
|
---
|
|
1411
1375
|
|
|
@@ -1414,9 +1378,8 @@ terminal event.
|
|
|
1414
1378
|
- Every event has a monotonically-increasing `seq` per run, persisted to
|
|
1415
1379
|
`EphemeralAgentRunEvent`. Reopen with `Last-Event-ID: <seq>` to resume.
|
|
1416
1380
|
- The Valkey pub/sub is best-effort; the persisted log is the source of
|
|
1417
|
-
truth.
|
|
1418
|
-
|
|
1419
|
-
runner.
|
|
1381
|
+
truth. A run waiting on local tool results reads them from the
|
|
1382
|
+
database when it resumes, so a missed publish never loses a result.
|
|
1420
1383
|
- `local_tool_result_in` is persisted in addition to the live publish, so
|
|
1421
1384
|
late-joining viewers can replay the SDK's response.
|
|
1422
1385
|
- Tool-result POSTs are idempotent on `toolUseId`: a second POST for the
|
|
@@ -1573,12 +1536,11 @@ A reference SDK should:
|
|
|
1573
1536
|
status notes / log lines / telemetry — the server already substituted
|
|
1574
1537
|
synthetic tool-results / steering nudges / supervisor verdicts, so the
|
|
1575
1538
|
SDK should keep consuming the stream until the terminal event lands.
|
|
1576
|
-
- [ ] Accept `plan` from the caller (`true` | `{ steps?, brief
|
|
1539
|
+
- [ ] Accept `plan` from the caller (`true` | `{ steps?, brief? }`
|
|
1577
1540
|
| `false`) and pass it through unchanged (see §8.5). It is opt-in —
|
|
1578
1541
|
omitting it (or `false`) means no planning. Render `task_plan` events
|
|
1579
1542
|
(§4.9) as a live, non-terminal checklist; keep consuming the stream
|
|
1580
|
-
until the terminal event.
|
|
1581
|
-
from the terminal `result.data.plan`.
|
|
1543
|
+
until the terminal event.
|
|
1582
1544
|
- [ ] Maintain three local-callback registries (or one tagged-union
|
|
1583
1545
|
registry), keyed by `name`: - generic local tools (`kind: "local"`), - local A2A peers (`kind: "a2a_local"`, indexed by some Agent Card
|
|
1584
1546
|
field — typically `agentCard.url`), - local MCP servers (`kind: "mcp_local"`, indexed by the SDK-side
|