@mantyx/sdk 0.23.0 → 0.25.0
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 +18 -0
- package/README.md +15 -5
- package/dist/a2a-server.cjs +9 -0
- package/dist/a2a-server.cjs.map +1 -1
- package/dist/a2a-server.js +1 -1
- package/dist/{chunk-OUK6ZZ5H.js → chunk-4EJRV6KZ.js} +40 -1
- package/dist/chunk-4EJRV6KZ.js.map +1 -0
- package/dist/client.d.ts +19 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +40 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/structured-output.d.ts +12 -0
- package/dist/structured-output.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/docs/agent-runs-protocol.md +189 -93
- package/docs/wire-protocol.md +208 -82
- package/package.json +1 -1
- package/dist/chunk-OUK6ZZ5H.js.map +0 -1
package/docs/wire-protocol.md
CHANGED
|
@@ -118,6 +118,7 @@ short-circuit, etc.) see `agent-runs-protocol.md` §4.
|
|
|
118
118
|
"outputSchema": {
|
|
119
119
|
// optional; see §7
|
|
120
120
|
"name": "weather_report", // defaults to "output"
|
|
121
|
+
"enforcement": "strict", // optional; "best_effort" (default) | "strict"
|
|
121
122
|
"schema": {
|
|
122
123
|
/* JSON Schema */
|
|
123
124
|
},
|
|
@@ -162,6 +163,13 @@ messages are merged after `systemPrompt`; the last non-system message must be a
|
|
|
162
163
|
"url": "https://example.com/image.png", // https only; provider fetches it
|
|
163
164
|
"mimeType": "image/png", // optional
|
|
164
165
|
}
|
|
166
|
+
// — or audio —
|
|
167
|
+
{
|
|
168
|
+
"type": "input_file",
|
|
169
|
+
"mimeType": "audio/mp4", // M4A recordings use audio/mp4
|
|
170
|
+
"filename": "recording.m4a",
|
|
171
|
+
"data": "<base64>",
|
|
172
|
+
}
|
|
165
173
|
```
|
|
166
174
|
|
|
167
175
|
See [`agent-runs-protocol.md` §4.0.1](./agent-runs-protocol.md) for the full
|
|
@@ -416,21 +424,22 @@ Every event payload has the same envelope:
|
|
|
416
424
|
|
|
417
425
|
The vocabulary (`EphemeralEventType` in `bus.ts`):
|
|
418
426
|
|
|
419
|
-
| Type | Direction | Frequency | Purpose
|
|
420
|
-
| ---------------------- | --------- | ------------------------------------------------ |
|
|
421
|
-
| `assistant_delta` | M → SDK | Many | Streamed assistant text token / chunk.
|
|
422
|
-
| `thinking_delta` | M → SDK | Many (iff `reasoningLevel > 0`) | Streamed extended-thinking text (provider redacts when policy requires).
|
|
423
|
-
| `tool_result` | M → SDK | Per server-resolved tool call | Informational — tells the SDK that MANTYX ran a server-resolved tool (`mantyx`, `mantyx_plugin`, `a2a`, `mcp`) and got a result. The SDK does not need to act on it.
|
|
424
|
-
| `
|
|
425
|
-
| `
|
|
426
|
-
| `
|
|
427
|
-
| `
|
|
427
|
+
| Type | Direction | Frequency | Purpose |
|
|
428
|
+
| ---------------------- | --------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
429
|
+
| `assistant_delta` | M → SDK | Many | Streamed assistant text token / chunk. |
|
|
430
|
+
| `thinking_delta` | M → SDK | Many (iff `reasoningLevel > 0`) | Streamed extended-thinking text (provider redacts when policy requires). |
|
|
431
|
+
| `tool_result` | M → SDK | Per server-resolved tool call | Informational — tells the SDK that MANTYX ran a server-resolved tool (`mantyx`, `mantyx_plugin`, `a2a`, `mcp`) and got a result. The SDK does not need to act on it. |
|
|
432
|
+
| `tool_files` | M → SDK | Per server-resolved tool call that returns files | Informational metadata for files a server-resolved tool produced (see §4.2.1). Precedes the matching `tool_result`. Inline bytes are redacted from the stream; download via the admin route. |
|
|
433
|
+
| `local_tool_call` | M → SDK | Per client-resolved tool call | **Action required.** SDK must POST a tool-result. |
|
|
434
|
+
| `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). |
|
|
435
|
+
| `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. |
|
|
436
|
+
| `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. |
|
|
428
437
|
| `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. |
|
|
429
|
-
| `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the in-product task plan (see §4.9 / §8.5). Emitted once after classify / caller-supplied plan, then again whenever the tracker advances step statuses. **Non-terminal.** For `planOnly` runs the final plan also rides on the terminal `result` under `data.plan`.
|
|
430
|
-
| `assistant_message` | M → SDK | 1× per turn | Final assistant message for the turn (concatenated, persistence-ready).
|
|
431
|
-
| `result` | M → SDK | 1× terminal | Successful completion. Carries the final assistant text and run summary.
|
|
432
|
-
| `error` | M → SDK | 1× terminal | Failure. Carries `error` (message), `code` / `errorClass` (category), `finishReason`, and an optional `partialText` salvage payload. See §4.7.
|
|
433
|
-
| `cancelled` | M → SDK | 1× terminal | Cancellation. Run was aborted via `POST /cancel`.
|
|
438
|
+
| `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the in-product task plan (see §4.9 / §8.5). Emitted once after classify / caller-supplied plan, then again whenever the tracker advances step statuses. **Non-terminal.** For `planOnly` runs the final plan also rides on the terminal `result` under `data.plan`. |
|
|
439
|
+
| `assistant_message` | M → SDK | 1× per turn | Final assistant message for the turn (concatenated, persistence-ready). |
|
|
440
|
+
| `result` | M → SDK | 1× terminal | Successful completion. Carries the final assistant text and run summary. |
|
|
441
|
+
| `error` | M → SDK | 1× terminal | Failure. Carries `error` (message), `code` / `errorClass` (category), `finishReason`, and an optional `partialText` salvage payload. See §4.7. |
|
|
442
|
+
| `cancelled` | M → SDK | 1× terminal | Cancellation. Run was aborted via `POST /cancel`. |
|
|
434
443
|
|
|
435
444
|
`result`, `error`, and `cancelled` are the **terminal** events — the SDK
|
|
436
445
|
should close the SSE stream after one of them arrives.
|
|
@@ -463,6 +472,48 @@ progress text — it's not part of the canonical assistant response.
|
|
|
463
472
|
|
|
464
473
|
Purely informational. The SDK does not respond.
|
|
465
474
|
|
|
475
|
+
### 4.2.1 `tool_files` (server-resolved tool outputs)
|
|
476
|
+
|
|
477
|
+
Emitted when a **server-resolved** tool returns files alongside (or instead of)
|
|
478
|
+
text — e.g. a `mantyx` tool that renders a chart or exports a PDF. The bytes also
|
|
479
|
+
reach the model natively (as file parts), so this event is purely for
|
|
480
|
+
observability: it lets the Calls dashboard (and any SDK client that cares) list
|
|
481
|
+
and download a run's produced artifacts. It always precedes the matching
|
|
482
|
+
`tool_result` summary and shares its display `name`.
|
|
483
|
+
|
|
484
|
+
```jsonc
|
|
485
|
+
{
|
|
486
|
+
"seq": 6,
|
|
487
|
+
"type": "tool_files",
|
|
488
|
+
"data": {
|
|
489
|
+
"name": "render_chart", // matches the paired tool_result `name`
|
|
490
|
+
"files": [
|
|
491
|
+
{
|
|
492
|
+
"filename": "chart.png",
|
|
493
|
+
"mimeType": "image/png",
|
|
494
|
+
"sizeBytes": 20480,
|
|
495
|
+
"storageKey": "chat-attachments/<tenant>/tool-results/<tool>/<uuid>.png",
|
|
496
|
+
},
|
|
497
|
+
],
|
|
498
|
+
},
|
|
499
|
+
}
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
| Field | Type | Notes |
|
|
503
|
+
| ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
504
|
+
| `filename` | string | Original filename. |
|
|
505
|
+
| `mimeType` | string | Content type. |
|
|
506
|
+
| `sizeBytes` | integer | Decoded byte length (`0` when only a pre-existing URI was available). |
|
|
507
|
+
| `storageKey` | string? | Object-store key when MANTYX persisted the bytes (the canonical case in production). Resolve via the admin download route; not a public URL. |
|
|
508
|
+
| `url` | string? | Public HTTPS URL when the tool itself returned a `file_uri` to a public file. |
|
|
509
|
+
|
|
510
|
+
When object storage is **not** configured (e.g. local dev), MANTYX inlines the
|
|
511
|
+
bytes as base64 on the persisted event row instead of a `storageKey`. That inline
|
|
512
|
+
`data` is **redacted from the SSE/stream payload** (only the metadata above is
|
|
513
|
+
sent); the bytes are served on demand by the admin download route. The
|
|
514
|
+
client-resolved equivalent (`local_tool_result_in.files`) is redacted the same
|
|
515
|
+
way.
|
|
516
|
+
|
|
466
517
|
### 4.3 `local_tool_call` (client-resolved tools)
|
|
467
518
|
|
|
468
519
|
This is the workhorse event for SDK-implemented tools. Payload shape varies
|
|
@@ -696,14 +747,14 @@ See §8 for the wire-spec field that defines budgets.
|
|
|
696
747
|
"data": { "action": "redirect", "phase": "reasoning", "reason": "Overthinking; looping on the same edge case.", "redirect": "Commit to the straightforward approach and answer.", "llmCalls": 7 } }
|
|
697
748
|
```
|
|
698
749
|
|
|
699
|
-
| Field | Type | Notes
|
|
700
|
-
| ---------- | ------- |
|
|
701
|
-
| `action` | string | One of `"on_track"`, `"redirect"`, `"finalize"`.
|
|
702
|
-
| `reason` | string | One- or two-sentence explanation from the judge.
|
|
703
|
-
| `redirect` | string | Present when `action === "redirect"`: the steering message injected into the conversation (same text the agent sees as a user message). Omitted for `on_track` / `finalize`.
|
|
704
|
-
| `llmCalls` | integer | Number of LLM calls (`completeTurn` invocations) completed when this review fired. Matches the pipeline's `modelInvocations` counter at the check boundary.
|
|
705
|
-
| `phase` | string | Optional. `"turn_boundary"` (default cadence review) or `"reasoning"` (mid-turn review fired while a long reasoning span was still streaming). Absent is equivalent to `"turn_boundary"`.
|
|
706
|
-
| `model`
|
|
750
|
+
| Field | Type | Notes |
|
|
751
|
+
| ---------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
752
|
+
| `action` | string | One of `"on_track"`, `"redirect"`, `"finalize"`. |
|
|
753
|
+
| `reason` | string | One- or two-sentence explanation from the judge. |
|
|
754
|
+
| `redirect` | string | Present when `action === "redirect"`: the steering message injected into the conversation (same text the agent sees as a user message). Omitted for `on_track` / `finalize`. |
|
|
755
|
+
| `llmCalls` | integer | Number of LLM calls (`completeTurn` invocations) completed when this review fired. Matches the pipeline's `modelInvocations` counter at the check boundary. |
|
|
756
|
+
| `phase` | string | Optional. `"turn_boundary"` (default cadence review) or `"reasoning"` (mid-turn review fired while a long reasoning span was still streaming). Absent is equivalent to `"turn_boundary"`. |
|
|
757
|
+
| `model` | object | Optional. Resolved judge model (`{ id, provider, vendorModelId }`) — same shape as terminal `result.model` (§4.7.1). Present on platform-hosted runs for cost attribution and debug UIs. |
|
|
707
758
|
|
|
708
759
|
Observability for the run-supervisor guard (see §8.4). The event fires on
|
|
709
760
|
**every** check, not only when the judge intervenes — `on_track` reviews are
|
|
@@ -724,10 +775,16 @@ supervisor **off** on ephemeral API runs.
|
|
|
724
775
|
|
|
725
776
|
```jsonc
|
|
726
777
|
// Every terminal `result` and `error` event also carries `tokens`, `turns`,
|
|
727
|
-
// and `
|
|
778
|
+
// `model`, and `structuredOutput` — see below and §4.8.1.
|
|
728
779
|
{ "seq": 14, "type": "result", "data": {
|
|
729
|
-
"
|
|
780
|
+
"subtype": "success",
|
|
730
781
|
"text": "...",
|
|
782
|
+
"structuredOutput": {
|
|
783
|
+
"schemaRequested": true,
|
|
784
|
+
"schemaEnforced": true,
|
|
785
|
+
"enforcementMechanism": "native_schema",
|
|
786
|
+
"unconstrainedFallbackOccurred": false
|
|
787
|
+
},
|
|
731
788
|
"tokens": { "inputTokens": 1283, "cachedTokens": 512, "reasoningTokens": 96, "outputTokens": 240 },
|
|
732
789
|
"turns": 3,
|
|
733
790
|
"model": { "id": "platform:demo", "provider": "openai", "vendorModelId": "gpt-5.4-mini", "reasoningEffort": "low" }
|
|
@@ -739,6 +796,12 @@ supervisor **off** on ephemeral API runs.
|
|
|
739
796
|
"finishReason": "max_tokens", // canonical lowercase stop reason
|
|
740
797
|
"partialText": "{\n \"answer\":… (truncated JSON) …",
|
|
741
798
|
"retryable": false, // optional; per-class retry hint
|
|
799
|
+
"structuredOutput": {
|
|
800
|
+
"schemaRequested": true,
|
|
801
|
+
"schemaEnforced": false,
|
|
802
|
+
"enforcementMechanism": "native_schema",
|
|
803
|
+
"unconstrainedFallbackOccurred": false
|
|
804
|
+
},
|
|
742
805
|
"tokens": { "inputTokens": 8190, "cachedTokens": 0, "reasoningTokens": 0, "outputTokens": 1024 },
|
|
743
806
|
"turns": 1,
|
|
744
807
|
"model": { "id": "provider:cmf…", "provider": "google", "vendorModelId": "gemini-2.5-pro" }
|
|
@@ -753,14 +816,37 @@ SSE stream.
|
|
|
753
816
|
with structured triage attributes when the failure carried a salvage path
|
|
754
817
|
(typically truncation, upstream deadline, or max-budget-with-text):
|
|
755
818
|
|
|
756
|
-
| Field
|
|
757
|
-
|
|
|
758
|
-
| `error`
|
|
759
|
-
| `code`
|
|
760
|
-
| `errorClass`
|
|
761
|
-
| `finishReason`
|
|
762
|
-
| `partialText`
|
|
763
|
-
| `retryable`
|
|
819
|
+
| Field | Type | Required | Notes |
|
|
820
|
+
| ------------------ | ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
821
|
+
| `error` | string | yes | Human-readable message (also persisted on `EphemeralAgentRun.error`). |
|
|
822
|
+
| `code` | string | yes | Legacy alias for `errorClass`. Equals `errorClass` when present; otherwise a small lowercase token (`"error"`, `"invalid_spec"`, `"worker_error"`, …) the SDK can switch on. |
|
|
823
|
+
| `errorClass` | string | no | Canonical category. One of `"rate_limit"`, `"overloaded"`, `"server"`, `"context_window"` (input too big), `"truncation"` (output budget exhausted), `"invalid_request"`, `"auth"`, `"timeout"`, `"local_timeout"`, `"upstream_deadline"`, `"unknown"`. New categories may land additively. |
|
|
824
|
+
| `finishReason` | string\|null | no | Canonical lowercase stop reason normalized across providers (`"max_tokens"`, `"refusal"`, `"malformed_function_call"`, …). When present, mirrors the value on the last `assistant_message`. |
|
|
825
|
+
| `partialText` | string | no | **Best-effort raw bytes** the model emitted before the failure. For `outputSchema` runs this is likely **incomplete JSON** that will fail `JSON.parse` — see §7 below. Also persisted on `EphemeralAgentRun.finalText` so the Calls UI can render it alongside a truncation banner. |
|
|
826
|
+
| `retryable` | boolean | no | Coarse retry hint inherited from the pipeline's error classifier. Informational; the SDK still owns the actual retry decision. |
|
|
827
|
+
| `apiStatus` | integer | no | HTTP status returned by the model provider, when available. Preserved on structured-output schema rejection and other classified provider errors. |
|
|
828
|
+
| `apiCode` | string | no | Provider-specific error code, when available. This is distinct from MANTYX's canonical `code` / `errorClass`. |
|
|
829
|
+
| `structuredOutput` | object | yes | Actual structured-output execution state described below. New servers include it on terminal `result` and `error` events; SDKs treat omission as a legacy-server response. |
|
|
830
|
+
|
|
831
|
+
**`structuredOutput` execution metadata.** This block describes what the
|
|
832
|
+
runtime actually did, not merely what appeared in the request:
|
|
833
|
+
|
|
834
|
+
| Field | Type | Notes |
|
|
835
|
+
| ------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
836
|
+
| `schemaRequested` | boolean | `true` when the resolved run spec carried `outputSchema`. |
|
|
837
|
+
| `schemaEnforced` | boolean | `true` only when the successful provider call used a native schema, or the runtime captured the required synthetic final-result tool. |
|
|
838
|
+
| `enforcementMechanism` | string | `"native_schema"`, `"synthetic_tool"`, or `"none"`. On a rejection it records the attempted mechanism; after unconstrained fallback it is `"none"`. |
|
|
839
|
+
| `unconstrainedFallbackOccurred` | boolean | Run-level flag: `true` when any provider call retried or completed without the requested schema. Always `false` in strict mode. |
|
|
840
|
+
|
|
841
|
+
Without `outputSchema`, new servers emit
|
|
842
|
+
`{ schemaRequested: false, schemaEnforced: false, enforcementMechanism:
|
|
843
|
+
"none", unconstrainedFallbackOccurred: false }`.
|
|
844
|
+
|
|
845
|
+
`errorClass: "rate_limit"` specifically means the model provider throttled an
|
|
846
|
+
LLM request. The agent pipeline retries that provider failure before emitting a
|
|
847
|
+
terminal event. It is not the MANTYX Developer API HTTP limiter, which rejects
|
|
848
|
+
an incoming request immediately with HTTP 429 and
|
|
849
|
+
`code: "rate_limit_exceeded"` plus `Retry-After`.
|
|
764
850
|
|
|
765
851
|
When `errorClass` is `"truncation"`, the `EphemeralAgentRun` row that the
|
|
766
852
|
SDK can re-fetch via `GET /agent-runs/:runId` will have:
|
|
@@ -882,7 +968,7 @@ non-breaking since those return types were already objects).
|
|
|
882
968
|
{ "title": "Summarize the top drivers", "status": "pending" } ] } }
|
|
883
969
|
```
|
|
884
970
|
|
|
885
|
-
| Field | Type | Notes
|
|
971
|
+
| Field | Type | Notes |
|
|
886
972
|
| ------- | ------ | ----------------------------------------------------------------------------------------------------- |
|
|
887
973
|
| `brief` | string | Optional one-line summary of the overall objective. |
|
|
888
974
|
| `steps` | array | Ordered checklist. Each `{ title, status }` where `status` is `"pending" \| "in_progress" \| "done"`. |
|
|
@@ -915,11 +1001,11 @@ Authorization: Bearer <api-key>
|
|
|
915
1001
|
}
|
|
916
1002
|
```
|
|
917
1003
|
|
|
918
|
-
| Field | Type | Required | Notes
|
|
919
|
-
| ----------- | ------ | -------- |
|
|
920
|
-
| `toolUseId` | string | yes | Must match a pending `local_tool_call`'s id.
|
|
921
|
-
| `result` | string | one-of | Successful textual result (≤ 2 MB). For MCP tools, flatten content blocks to text. For A2A delegations, the peer's reply text.
|
|
922
|
-
| `error` | string | one-of | Human-readable failure message (≤ 8 KB). Surfaced to the model so it can recover.
|
|
1004
|
+
| Field | Type | Required | Notes |
|
|
1005
|
+
| ----------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1006
|
+
| `toolUseId` | string | yes | Must match a pending `local_tool_call`'s id. |
|
|
1007
|
+
| `result` | string | one-of | Successful textual result (≤ 2 MB). For MCP tools, flatten content blocks to text. For A2A delegations, the peer's reply text. |
|
|
1008
|
+
| `error` | string | one-of | Human-readable failure message (≤ 8 KB). Surfaced to the model so it can recover. |
|
|
923
1009
|
| `files` | array | no | Files the client-resolved tool produced, surfaced to the model on the next turn as native file parts (Anthropic / Gemini / Bedrock inside `tool_result`; OpenAI as a synthetic follow-up user turn). Each entry is `{ filename, mimeType, data }` with `data` base64 (no data-URL prefix). Only honored alongside `result`; ignored when `error` is set. `mimeType` must be an allowed attachment type. Up to 20 files; combined decoded bytes are capped (currently 5 MB), and large files are persisted to object storage and forwarded by reference. For bigger artifacts, upload out of band and reference a URL in `result`. |
|
|
924
1010
|
|
|
925
1011
|
Server response codes:
|
|
@@ -965,22 +1051,41 @@ will include `thinking_delta` events alongside `assistant_delta`.
|
|
|
965
1051
|
|
|
966
1052
|
## 7. `outputSchema` (structured final reply)
|
|
967
1053
|
|
|
968
|
-
`outputSchema`
|
|
969
|
-
conforming to a JSON Schema.
|
|
970
|
-
|
|
971
|
-
|
|
1054
|
+
`outputSchema` asks the provider to constrain the final assistant message to a
|
|
1055
|
+
JSON document conforming to a JSON Schema. The terminal `result` event still
|
|
1056
|
+
carries the reply as `data.text: string`. Use `enforcement: "strict"` when a
|
|
1057
|
+
caller must fail instead of accepting a provider rejection, an unsupported
|
|
1058
|
+
provider, or an unconstrained result.
|
|
972
1059
|
|
|
973
1060
|
```jsonc
|
|
974
1061
|
"outputSchema": {
|
|
975
1062
|
"name": "weather_report", // optional; default "output"; /^[a-zA-Z0-9_-]{1,64}$/
|
|
976
|
-
"schema": { /* JSON Schema */ }
|
|
1063
|
+
"schema": { /* JSON Schema */ }, // required, root must be a JSON object
|
|
1064
|
+
"enforcement": "strict" // optional; default "best_effort"
|
|
977
1065
|
}
|
|
978
1066
|
```
|
|
979
1067
|
|
|
980
|
-
| Field
|
|
981
|
-
|
|
|
982
|
-
| `name`
|
|
983
|
-
| `schema`
|
|
1068
|
+
| Field | Type | Required | Notes |
|
|
1069
|
+
| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1070
|
+
| `name` | string | no | Stable identifier passed to providers (OpenAI `text.format.name`, Anthropic synthetic-tool name). Defaults to `"output"`. |
|
|
1071
|
+
| `schema` | object | yes | JSON Schema for the assistant text. Root must be a JSON object — most providers reject array/scalar roots in structured-output mode. Passed through verbatim; MANTYX does not validate the schema's contents. |
|
|
1072
|
+
| `enforcement` | string | no | `"best_effort"` (default) preserves the historical fallback behavior. `"strict"` requires actual enforcement and forbids an unconstrained retry. |
|
|
1073
|
+
|
|
1074
|
+
**Enforcement modes:**
|
|
1075
|
+
|
|
1076
|
+
- `best_effort` is the backward-compatible default. When OpenAI or Gemini
|
|
1077
|
+
rejects the schema request, MANTYX may memoize that incompatibility and retry
|
|
1078
|
+
without the schema. The run may still succeed; inspect
|
|
1079
|
+
`structuredOutput.schemaEnforced` and
|
|
1080
|
+
`unconstrainedFallbackOccurred` before treating it as provider compatibility.
|
|
1081
|
+
- `strict` never retries without the schema, never consults or writes the
|
|
1082
|
+
best-effort unsupported-schema memo, and never silently ignores the schema.
|
|
1083
|
+
Provider rejection terminates with
|
|
1084
|
+
`errorClass: "structured_output_schema_rejected"` while preserving
|
|
1085
|
+
`apiStatus`, `apiCode`, and the provider message. A provider/model with no
|
|
1086
|
+
enforcement path fails as `structured_output_not_supported`; bypassing a
|
|
1087
|
+
required synthetic final-result tool fails as
|
|
1088
|
+
`structured_output_not_enforced`.
|
|
984
1089
|
|
|
985
1090
|
Per provider:
|
|
986
1091
|
|
|
@@ -991,13 +1096,23 @@ Per provider:
|
|
|
991
1096
|
| Gemini ≤ 2.5 with no tools | Same as Gemini 3+: `responseMimeType: "application/json"` + `responseJsonSchema`. |
|
|
992
1097
|
| Gemini ≤ 2.5 **with tools** | Synthetic `set_model_response` function declaration is injected; its `parametersJsonSchema` is the supplied schema. The system instruction is augmented to direct the model to call this tool with the final answer. The engine intercepts the call, hides it from the SDK, and surfaces the call's arguments as the assistant text (JSON-stringified). Sidesteps the API rejection ("Function calling with a response mime type: 'application/json' is unsupported") without round-tripping a 4xx. |
|
|
993
1098
|
| Anthropic / Bedrock-Anthropic | Synthetic `final_report` tool whose `input_schema` is the supplied schema; `tool_choice` is forced on the no-tools finishing turn. The tool's input is surfaced as the assistant text. |
|
|
994
|
-
| xAI Grok, others |
|
|
1099
|
+
| xAI Grok, others | Best effort may return plain text and reports `enforcementMechanism: "none"`. Strict mode fails explicitly instead of calling this a schema-enforced success. |
|
|
995
1100
|
|
|
996
1101
|
The synthetic-tool paths (Gemini 2.5 + tools, Anthropic) are entirely
|
|
997
1102
|
internal: the SDK still receives `data.text: string` on the terminal
|
|
998
1103
|
`result` event and never sees a `local_tool_call` for `set_model_response`
|
|
999
1104
|
or `final_report`. They never appear in the tools array the SDK declared.
|
|
1000
1105
|
|
|
1106
|
+
Every terminal `result` and `error` includes the `structuredOutput` block from
|
|
1107
|
+
§4.8. A strict compatibility test succeeds only when `schemaRequested` and
|
|
1108
|
+
`schemaEnforced` are both `true`,
|
|
1109
|
+
`unconstrainedFallbackOccurred` is `false`, and the mechanism is the expected
|
|
1110
|
+
provider path.
|
|
1111
|
+
|
|
1112
|
+
`plan: { planOnly: true }` does not execute the agent loop and therefore cannot
|
|
1113
|
+
enforce a run-level output schema. Combining it with strict enforcement
|
|
1114
|
+
terminates explicitly as `structured_output_not_supported`.
|
|
1115
|
+
|
|
1001
1116
|
Validation (server-side, `400 invalid_request` on violation):
|
|
1002
1117
|
|
|
1003
1118
|
| Constraint | Limit |
|
|
@@ -1127,10 +1242,9 @@ entries are layered on top so per-run overrides win):
|
|
|
1127
1242
|
| ---------------------------------------------------------------------------------------- | ------------------ |
|
|
1128
1243
|
| `recall` (workspace memory hybrid search) | `4` |
|
|
1129
1244
|
| `traverse` (memory graph BFS) | `3` |
|
|
1130
|
-
| `hive_consult_ontology` (per-hive ontology read; same name across
|
|
1245
|
+
| `hive_consult_ontology` (per-hive ontology read; same name across both active hives) | `4` |
|
|
1131
1246
|
| `hive_search_deals` / `_meetings` / `_companies` / `_people` (Sales Hive general search) | `5` |
|
|
1132
1247
|
| `hive_search_tickets` / `_conversations` / `_accounts` (Customer Hive general search) | `5` |
|
|
1133
|
-
| `hive_search_releases` / `_issues` (Product Hive general search) | `5` |
|
|
1134
1248
|
|
|
1135
1249
|
Pass `"toolBudgets": {}` to start from a clean slate (no defaults applied
|
|
1136
1250
|
on top — useful for runs that intentionally want unbounded research). When
|
|
@@ -1163,18 +1277,18 @@ An optional LLM **run supervisor** periodically reviews the agent's
|
|
|
1163
1277
|
transcript (reasoning, tool calls, tool results, visible text) and may
|
|
1164
1278
|
steer the run:
|
|
1165
1279
|
|
|
1166
|
-
| Verdict
|
|
1167
|
-
|
|
|
1168
|
-
| `on_track`
|
|
1169
|
-
| `redirect`
|
|
1170
|
-
| `finalize`
|
|
1280
|
+
| Verdict | Server action |
|
|
1281
|
+
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
1282
|
+
| `on_track` | No-op — the run continues unchanged. |
|
|
1283
|
+
| `redirect` | A steering **user message** is injected; tools stay available on the next turn. |
|
|
1284
|
+
| `finalize` | The next turn is forced **tools-disabled** so the run lands a clean final answer (optionally prefaced by the supervisor's message). |
|
|
1171
1285
|
|
|
1172
1286
|
Reviews fire on two triggers:
|
|
1173
1287
|
|
|
1174
1288
|
- **Cadence** — every **`interval` LLM calls** (`completeTurn` invocations),
|
|
1175
1289
|
measured at the bottom of tool-emitting rounds (`phase: "turn_boundary"`).
|
|
1176
1290
|
Default interval is **5** when the field is omitted.
|
|
1177
|
-
- **Mid-turn reasoning** — while a
|
|
1291
|
+
- **Mid-turn reasoning** — while a _single_ turn is still streaming reasoning,
|
|
1178
1292
|
once the current reasoning span crosses **3000 characters or 30s** (whichever
|
|
1179
1293
|
first), a `phase: "reasoning"` review runs on the in-progress reasoning. A
|
|
1180
1294
|
`redirect` / `finalize` verdict **aborts the in-flight turn** and steers the
|
|
@@ -1199,13 +1313,13 @@ Reviews fire on two triggers:
|
|
|
1199
1313
|
"supervisor": false // explicitly disable (same as omitting the field)
|
|
1200
1314
|
```
|
|
1201
1315
|
|
|
1202
|
-
| Field
|
|
1203
|
-
|
|
|
1204
|
-
| (literal `true`)
|
|
1205
|
-
| `interval`
|
|
1206
|
-
| `modelId`
|
|
1207
|
-
| `reasoningTrigger` | `false` \| `{ chars?, ms? }` | Optional. Mid-turn reasoning trigger. Defaults to `{ chars: 3000, ms: 30000 }`. `chars` capped at 50000, `ms` at 600000. Pass `false` to only review at tool-round boundaries.
|
|
1208
|
-
| (literal `false`)
|
|
1316
|
+
| Field | Type | Notes |
|
|
1317
|
+
| ------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1318
|
+
| (literal `true`) | `true` | Enables the run supervisor with platform defaults (`interval` 5, reasoning trigger 3000 chars / 30s, workspace judge model). |
|
|
1319
|
+
| `interval` | integer ≥ 1 | Optional. Default **5** when omitted. Capped at **100** server-side. |
|
|
1320
|
+
| `modelId` | string | Optional. Same selector grammar as top-level `modelId` (§2). When omitted, the platform resolves the judge model from the workspace default supervisor model, then the workspace default model. |
|
|
1321
|
+
| `reasoningTrigger` | `false` \| `{ chars?, ms? }` | Optional. Mid-turn reasoning trigger. Defaults to `{ chars: 3000, ms: 30000 }`. `chars` capped at 50000, `ms` at 600000. Pass `false` to only review at tool-round boundaries. |
|
|
1322
|
+
| (literal `false`) | `false` | Disables the run supervisor for this run. Loop detection and tool budgets still apply. |
|
|
1209
1323
|
|
|
1210
1324
|
**Model resolution.** When the supervisor is enabled, the judge model is chosen in order:
|
|
1211
1325
|
|
|
@@ -1249,31 +1363,43 @@ features add extra LLM calls.
|
|
|
1249
1363
|
"plan": false // (or omit) no planning — a plain run
|
|
1250
1364
|
```
|
|
1251
1365
|
|
|
1252
|
-
| Form
|
|
1253
|
-
|
|
|
1254
|
-
| omitted / `false`
|
|
1255
|
-
| `true`
|
|
1256
|
-
| `{ steps, brief? }`
|
|
1257
|
-
| `{ planOnly: true, steps? }`
|
|
1366
|
+
| Form | Behavior |
|
|
1367
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1368
|
+
| omitted / `false` | No planning. Default. |
|
|
1369
|
+
| `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. |
|
|
1370
|
+
| `{ steps, brief? }` | Caller-provided checklist used verbatim — **skips** the classifier (and its `MIN_STEPS` gate). Injected + tracked like the auto case. |
|
|
1371
|
+
| `{ planOnly: true, steps? }` | Produce the plan (classifier when `steps` omitted, otherwise the provided checklist) and **terminate without executing the agent loop**. |
|
|
1258
1372
|
|
|
1259
|
-
| Field
|
|
1260
|
-
|
|
|
1261
|
-
| `planOnly`
|
|
1262
|
-
| `brief`
|
|
1263
|
-
| `steps`
|
|
1264
|
-
| (literal `true`)
|
|
1373
|
+
| Field | Type | Notes |
|
|
1374
|
+
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
1375
|
+
| `planOnly` | boolean | Optional. When `true`, the run stops after producing the plan; the terminal `result` carries it under `data.plan`. |
|
|
1376
|
+
| `brief` | string | Optional one-line objective for a caller-provided plan. Clamped server-side. |
|
|
1377
|
+
| `steps` | string[] | Optional caller-provided checklist titles. Empty/omitted ⇒ auto-classify. Count and per-step length clamped server-side. |
|
|
1378
|
+
| (literal `true`) | `true` | Auto pre-flight classifier + live tracking. |
|
|
1265
1379
|
|
|
1266
1380
|
**Plan-only terminal shape.** A `planOnly` run terminates with the normal
|
|
1267
1381
|
terminal `result` event (§4.8), plus a structured `plan`:
|
|
1268
1382
|
|
|
1269
1383
|
```jsonc
|
|
1270
|
-
{
|
|
1271
|
-
"
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1384
|
+
{
|
|
1385
|
+
"seq": 5,
|
|
1386
|
+
"type": "result",
|
|
1387
|
+
"data": {
|
|
1388
|
+
"subtype": "success",
|
|
1389
|
+
"text": "Migrate the billing tables and backfill\n\n1. Snapshot current schema\n2. Apply migration\n3. Backfill rows\n4. Verify counts",
|
|
1390
|
+
"plan": {
|
|
1391
|
+
"brief": "Migrate the billing tables and backfill",
|
|
1392
|
+
"steps": [
|
|
1393
|
+
{ "title": "Snapshot current schema", "status": "pending" } /* … */,
|
|
1394
|
+
],
|
|
1395
|
+
},
|
|
1396
|
+
"tokens": {
|
|
1397
|
+
/* zeroed — classifier usage is metered separately */
|
|
1398
|
+
},
|
|
1399
|
+
"turns": 0,
|
|
1400
|
+
"model": { "id": "…", "provider": "…", "vendorModelId": "…" },
|
|
1401
|
+
},
|
|
1402
|
+
}
|
|
1277
1403
|
```
|
|
1278
1404
|
|
|
1279
1405
|
When the classifier declines in plan-only mode, `data.plan.steps` is `[]` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantyx/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "MANTYX as a hosted agent runtime: define ephemeral agents, mix server-side MANTYX tools with locally-executed tools, run them remotely.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|