@mantyx/sdk 2026.11.2 → 2026.11.3

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 CHANGED
@@ -11,6 +11,18 @@ and new releases use calendar versions (`YYYY.M.RELEASE`). Historical versions r
11
11
 
12
12
  ### Added
13
13
 
14
+ - `turnInstructions` on agent runs and per-message session sends gives the
15
+ model context for one turn only. It is placed ahead of that turn's user
16
+ message, never stored in the session transcript, and never merged into the
17
+ system prompt, so provider prompt caches keep matching across turns.
18
+
19
+ - `turnInstructionsAuthority` (`"developer"` or `"context"`) on agent runs and
20
+ per-message session sends. With `"developer"`, the server default, turn
21
+ instructions go out as an OpenAI `developer` message or an Anthropic
22
+ mid-conversation `system` message where the run's model supports it, which
23
+ providers rank above the user's own text; elsewhere, and with `"context"`,
24
+ they stay ahead of the user message.
25
+
14
26
  - Configure a fallback model for ephemeral runs and sessions. MANTYX preserves
15
27
  completed tool results during failover and keeps switched sessions on the fallback.
16
28
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MantyxError,
3
3
  MantyxRunError
4
- } from "./chunk-RT44KYDO.js";
4
+ } from "./chunk-4WXIAVUB.js";
5
5
 
6
6
  // src/a2a-server.ts
7
7
  import {
@@ -777,7 +777,9 @@ var MantyxClient = class {
777
777
  body: serializeAgentSpec(spec, {
778
778
  prompt: spec.prompt,
779
779
  messages: spec.messages,
780
- attachments: spec.attachments
780
+ attachments: spec.attachments,
781
+ turnInstructions: spec.turnInstructions,
782
+ turnInstructionsAuthority: spec.turnInstructionsAuthority
781
783
  })
782
784
  });
783
785
  return await this.driveRun(created.runId, handlers, {
@@ -818,7 +820,9 @@ var MantyxClient = class {
818
820
  body: serializeAgentSpec(spec, {
819
821
  prompt: spec.prompt,
820
822
  messages: spec.messages,
821
- attachments: spec.attachments
823
+ attachments: spec.attachments,
824
+ turnInstructions: spec.turnInstructions,
825
+ turnInstructionsAuthority: spec.turnInstructionsAuthority
822
826
  })
823
827
  });
824
828
  yield* this.streamRunEvents(created.runId, handlers, spec.signal);
@@ -1437,7 +1441,16 @@ var AgentSession = class {
1437
1441
  }
1438
1442
  buildSessionMessageBody(promptOrMessages, opts) {
1439
1443
  const body = serializeTurnInput(
1440
- typeof promptOrMessages === "string" ? { prompt: promptOrMessages, attachments: opts.attachments } : { messages: promptOrMessages }
1444
+ typeof promptOrMessages === "string" ? {
1445
+ prompt: promptOrMessages,
1446
+ attachments: opts.attachments,
1447
+ turnInstructions: opts.turnInstructions,
1448
+ turnInstructionsAuthority: opts.turnInstructionsAuthority
1449
+ } : {
1450
+ messages: promptOrMessages,
1451
+ turnInstructions: opts.turnInstructions,
1452
+ turnInstructionsAuthority: opts.turnInstructionsAuthority
1453
+ }
1441
1454
  );
1442
1455
  if (!("prompt" in body) && !("messages" in body)) {
1443
1456
  throw new MantyxError("Either `prompt` or `messages` is required");
@@ -1500,6 +1513,24 @@ var AgentSession = class {
1500
1513
  }
1501
1514
  };
1502
1515
  function serializeTurnInput(input) {
1516
+ const body = serializeTurnMessages(input);
1517
+ if (input.turnInstructions !== void 0) {
1518
+ if (typeof input.turnInstructions !== "string") {
1519
+ throw new MantyxError("`turnInstructions` must be a string");
1520
+ }
1521
+ body.turnInstructions = input.turnInstructions;
1522
+ }
1523
+ if (input.turnInstructionsAuthority !== void 0) {
1524
+ if (input.turnInstructionsAuthority !== "developer" && input.turnInstructionsAuthority !== "context") {
1525
+ throw new MantyxError(
1526
+ '`turnInstructionsAuthority` must be "developer" or "context"'
1527
+ );
1528
+ }
1529
+ body.turnInstructionsAuthority = input.turnInstructionsAuthority;
1530
+ }
1531
+ return body;
1532
+ }
1533
+ function serializeTurnMessages(input) {
1503
1534
  if (input.messages !== void 0) {
1504
1535
  return { messages: input.messages };
1505
1536
  }
package/dist/client.d.ts CHANGED
@@ -89,6 +89,14 @@ export declare function inputFileUrlAttachment(opts: {
89
89
  }): InputFileUrlAttachment;
90
90
  /** Thumbs up/down verdict for {@link MantyxClient.submitRunFeedback}. */
91
91
  export type RunFeedbackVerdict = "UP" | "DOWN";
92
+ /**
93
+ * Authority for `turnInstructions` (their lifetime is always one run):
94
+ * `"developer"` (server default) sends them as an operator-authority message
95
+ * where the run's provider and model support it, else ahead of the user text;
96
+ * `"context"` always places them ahead of the user text. See
97
+ * `docs/agent-runs-protocol.md` §4.0.3.
98
+ */
99
+ export type TurnInstructionsAuthority = "developer" | "context";
92
100
  /** Body for `POST /agent-runs/:runId/feedback`. See §9a. */
93
101
  export interface RunFeedbackInput {
94
102
  verdict: RunFeedbackVerdict;
@@ -509,6 +517,15 @@ export interface RunSpec extends AgentSpecBase {
509
517
  * §4.0.1.
510
518
  */
511
519
  attachments?: MessageAttachment[];
520
+ /**
521
+ * Context the model sees ahead of the last `user` message, for this run
522
+ * only. Not merged into the system prompt, so the system prompt stays
523
+ * byte-stable for provider prompt caching. See
524
+ * `docs/agent-runs-protocol.md` §4.0.3.
525
+ */
526
+ turnInstructions?: string;
527
+ /** Authority for {@link RunSpec.turnInstructions}; the server defaults to `"developer"`. */
528
+ turnInstructionsAuthority?: TurnInstructionsAuthority;
512
529
  /** Receives streaming assistant text deltas. */
513
530
  onAssistantDelta?: (delta: string) => void;
514
531
  /** Receives raw events (assistant_message, local_tool_call, tool_result, ...) for advanced consumers. */
@@ -1347,6 +1364,15 @@ export declare class AgentSession {
1347
1364
  * not mutate the session's stored value. See {@link AgentSpecBase.plan}.
1348
1365
  */
1349
1366
  plan?: PlanSpec;
1367
+ /**
1368
+ * Context the model sees ahead of this message's user text, for this
1369
+ * run only. It is not stored in the session transcript (later turns
1370
+ * never replay it) and not merged into the system prompt. See
1371
+ * `docs/agent-runs-protocol.md` §4.0.3.
1372
+ */
1373
+ turnInstructions?: string;
1374
+ /** Authority for `turnInstructions`; the server defaults to `"developer"`. */
1375
+ turnInstructionsAuthority?: TurnInstructionsAuthority;
1350
1376
  }): Promise<RunResult>;
1351
1377
  stream(promptOrMessages: string | ConversationMessage[], opts?: {
1352
1378
  signal?: AbortSignal;
@@ -1359,6 +1385,8 @@ export declare class AgentSession {
1359
1385
  toolBudgets?: ToolBudgets;
1360
1386
  supervisor?: Supervisor | false;
1361
1387
  plan?: PlanSpec;
1388
+ turnInstructions?: string;
1389
+ turnInstructionsAuthority?: TurnInstructionsAuthority;
1362
1390
  }): AsyncGenerator<RunEvent, void, void>;
1363
1391
  private buildSessionMessageBody;
1364
1392
  /**
package/dist/index.cjs CHANGED
@@ -851,7 +851,9 @@ var MantyxClient = class {
851
851
  body: serializeAgentSpec(spec, {
852
852
  prompt: spec.prompt,
853
853
  messages: spec.messages,
854
- attachments: spec.attachments
854
+ attachments: spec.attachments,
855
+ turnInstructions: spec.turnInstructions,
856
+ turnInstructionsAuthority: spec.turnInstructionsAuthority
855
857
  })
856
858
  });
857
859
  return await this.driveRun(created.runId, handlers, {
@@ -892,7 +894,9 @@ var MantyxClient = class {
892
894
  body: serializeAgentSpec(spec, {
893
895
  prompt: spec.prompt,
894
896
  messages: spec.messages,
895
- attachments: spec.attachments
897
+ attachments: spec.attachments,
898
+ turnInstructions: spec.turnInstructions,
899
+ turnInstructionsAuthority: spec.turnInstructionsAuthority
896
900
  })
897
901
  });
898
902
  yield* this.streamRunEvents(created.runId, handlers, spec.signal);
@@ -1511,7 +1515,16 @@ var AgentSession = class {
1511
1515
  }
1512
1516
  buildSessionMessageBody(promptOrMessages, opts) {
1513
1517
  const body = serializeTurnInput(
1514
- typeof promptOrMessages === "string" ? { prompt: promptOrMessages, attachments: opts.attachments } : { messages: promptOrMessages }
1518
+ typeof promptOrMessages === "string" ? {
1519
+ prompt: promptOrMessages,
1520
+ attachments: opts.attachments,
1521
+ turnInstructions: opts.turnInstructions,
1522
+ turnInstructionsAuthority: opts.turnInstructionsAuthority
1523
+ } : {
1524
+ messages: promptOrMessages,
1525
+ turnInstructions: opts.turnInstructions,
1526
+ turnInstructionsAuthority: opts.turnInstructionsAuthority
1527
+ }
1515
1528
  );
1516
1529
  if (!("prompt" in body) && !("messages" in body)) {
1517
1530
  throw new MantyxError("Either `prompt` or `messages` is required");
@@ -1574,6 +1587,24 @@ var AgentSession = class {
1574
1587
  }
1575
1588
  };
1576
1589
  function serializeTurnInput(input) {
1590
+ const body = serializeTurnMessages(input);
1591
+ if (input.turnInstructions !== void 0) {
1592
+ if (typeof input.turnInstructions !== "string") {
1593
+ throw new MantyxError("`turnInstructions` must be a string");
1594
+ }
1595
+ body.turnInstructions = input.turnInstructions;
1596
+ }
1597
+ if (input.turnInstructionsAuthority !== void 0) {
1598
+ if (input.turnInstructionsAuthority !== "developer" && input.turnInstructionsAuthority !== "context") {
1599
+ throw new MantyxError(
1600
+ '`turnInstructionsAuthority` must be "developer" or "context"'
1601
+ );
1602
+ }
1603
+ body.turnInstructionsAuthority = input.turnInstructionsAuthority;
1604
+ }
1605
+ return body;
1606
+ }
1607
+ function serializeTurnMessages(input) {
1577
1608
  if (input.messages !== void 0) {
1578
1609
  return { messages: input.messages };
1579
1610
  }
@@ -2764,7 +2795,7 @@ async function runComputerUse(opts) {
2764
2795
  }
2765
2796
 
2766
2797
  // src/version.ts
2767
- var SDK_VERSION = "2026.11.2";
2798
+ var SDK_VERSION = "2026.11.3";
2768
2799
  // Annotate the CommonJS export names for ESM import in node:
2769
2800
  0 && (module.exports = {
2770
2801
  AgentSession,
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@
35
35
  */
36
36
  export type { DecisionQuestion, DecisionRequest, DecisionAnswer, DecisionResult, DecisionModelInfo, DecisionRunSummary, DecisionRunDetail, DecisionRunList } from "./decisions.js";
37
37
  export { MantyxClient, AgentSession, DEFAULT_BASE_URL, parseRunOutput, planOnly, taskPlanFromEventData, inputFileAttachment, inputFileUrlAttachment, } from "./client.js";
38
- export type { MantyxClientOptions, ModelInfo, ModelCatalog, AgentSpecBase, RunSpec, SessionSpec, OutputSchema, OutputSchemaValue, LoopDetection, ToolBudget, ToolBudgets, Supervisor, SupervisorAction, SupervisorPhase, ReasoningTrigger, PlanOptions, PlanMode, PlanSpec, TaskPlan, TaskPlanStep, TaskPlanStepStatus, TaskPlanTransition, RunResult, RunTokenUsage, RunModelInfo, RunEvent, RunEventBase, AssistantDeltaEvent, ThinkingDeltaEvent, AssistantMessageEvent, ModelFallbackEvent, UserMessageEvent, InputFileAttachment, InputFileUrlAttachment, MessageAttachment, InputFileAttachmentMetadata, InputFileUrlAttachmentMetadata, AttachmentMetadata, ConversationMessage, ServerToolResultEvent, LocalToolCallEvent, LocalToolResultInEvent, LoopDetectedEvent, ToolBudgetExceededEvent, SupervisorEvent, TaskPlanEvent, ResultEvent, ErrorEvent, CancelledEvent, SessionInfo, SessionSummary, SessionListResult, SessionEventsPage, LocalHandlers, RunFeedbackVerdict, RunFeedbackInput, RunFeedbackResult, EvalRunStatus, InlineEvalCaseSpec, InlineEvalDatasetSpec, AgentEvalOverrides, CreateEvalRunRequest, EvalDatasetSummary, EvalDatasetList, EvalCase, EvalDatasetDetail, EvalRunAccepted, EvalRunSummary, EvalCaseResult, EvalRunDetail, EvalRunList, EvalRunCompareSide, EvalRunCompareCase, EvalRunCompare, EvalRunEvent, ListEvalRunsOptions, RunEvalOptions, } from "./client.js";
38
+ export type { MantyxClientOptions, ModelInfo, ModelCatalog, AgentSpecBase, RunSpec, SessionSpec, OutputSchema, OutputSchemaValue, LoopDetection, ToolBudget, ToolBudgets, Supervisor, SupervisorAction, SupervisorPhase, ReasoningTrigger, PlanOptions, PlanMode, PlanSpec, TaskPlan, TaskPlanStep, TaskPlanStepStatus, TaskPlanTransition, RunResult, RunTokenUsage, RunModelInfo, RunEvent, RunEventBase, AssistantDeltaEvent, ThinkingDeltaEvent, AssistantMessageEvent, ModelFallbackEvent, UserMessageEvent, InputFileAttachment, InputFileUrlAttachment, MessageAttachment, InputFileAttachmentMetadata, InputFileUrlAttachmentMetadata, AttachmentMetadata, ConversationMessage, ServerToolResultEvent, LocalToolCallEvent, LocalToolResultInEvent, LoopDetectedEvent, ToolBudgetExceededEvent, SupervisorEvent, TaskPlanEvent, ResultEvent, ErrorEvent, CancelledEvent, SessionInfo, SessionSummary, SessionListResult, SessionEventsPage, LocalHandlers, RunFeedbackVerdict, TurnInstructionsAuthority, RunFeedbackInput, RunFeedbackResult, EvalRunStatus, InlineEvalCaseSpec, InlineEvalDatasetSpec, AgentEvalOverrides, CreateEvalRunRequest, EvalDatasetSummary, EvalDatasetList, EvalCase, EvalDatasetDetail, EvalRunAccepted, EvalRunSummary, EvalCaseResult, EvalRunDetail, EvalRunList, EvalRunCompareSide, EvalRunCompareCase, EvalRunCompare, EvalRunEvent, ListEvalRunsOptions, RunEvalOptions, } from "./client.js";
39
39
  export { defineLocalTool, mantyxTool, mantyxPluginTool, mantyxA2A, defineLocalA2A, mantyxMcp, defineLocalMcp, isLocalTool, isLocalA2ATool, isLocalMcpServer, } from "./tools.js";
40
40
  export type { LocalTool, LocalToolResult, LocalToolOutput, ToolResultFile, MantyxToolRef, MantyxPluginToolRef, ToolRef, ZodLikeObject, DefineLocalToolOptions, ReasoningLevel, A2AToolRef, LocalA2ATool, McpToolRef, LocalMcpServer, LocalMcpHttpTransport, LocalMcpStdioTransport, MantyxA2AOptions, DefineLocalA2AOptions, MantyxMcpOptions, DefineLocalMcpOptions, } from "./tools.js";
41
41
  export { MantyxError, MantyxAuthError, MantyxNetworkError, MantyxParseError, MantyxScopeError, MantyxToolError, MantyxRunError, } from "./errors.js";
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  taskPlanFromEventData,
28
28
  toToolParametersWire,
29
29
  zodToJsonSchema
30
- } from "./chunk-RT44KYDO.js";
30
+ } from "./chunk-4WXIAVUB.js";
31
31
 
32
32
  // src/oauth.ts
33
33
  var DEFAULT_OAUTH_BASE_URL = "https://app.mantyx.io";
@@ -603,7 +603,7 @@ async function runComputerUse(opts) {
603
603
  }
604
604
 
605
605
  // src/version.ts
606
- var SDK_VERSION = "2026.11.2";
606
+ var SDK_VERSION = "2026.11.3";
607
607
  export {
608
608
  AgentSession,
609
609
  COMPUTER_USE_ACTIONS,
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Release version — synced from sdk/VERSION (`pnpm run sync-version`).
3
3
  */
4
- export declare const SDK_VERSION = "2026.11.2";
4
+ export declare const SDK_VERSION = "2026.11.3";
@@ -491,6 +491,94 @@ non-terminal `model_fallback` SSE event carries `{ errorClass, model,
491
491
  primaryModelId, fallbackModelId }`. Session details expose each call's actual
492
492
  `model`, including failed calls that switched.
493
493
 
494
+ ### 4.0.3 `turnInstructions` (per-turn context that is not stored)
495
+
496
+ Optional string on `POST /agent-runs` and on
497
+ `POST /agent-sessions/:id/messages`. The model sees it for that run only. Use
498
+ it for context that belongs to one turn: retrieved records, a skill or
499
+ playbook body, a reminder or nudge.
500
+
501
+ Where it goes depends on `turnInstructionsAuthority` (optional, same two
502
+ endpoints, this run only) and on the run's provider and model:
503
+
504
+ | `turnInstructionsAuthority` | Provider / model | Sent as (`turnInstructionsPlacement`) |
505
+ | --------------------------- | -------------------------------------------------- | ------------------------------------------------------------------ |
506
+ | `developer` (default) | OpenAI direct, GPT-4o / 4.1 / 5 / 6, o1, o3, o4-mini | a `developer` message right after the user message (`developer_message`) |
507
+ | `developer` (default) | Anthropic direct, models with mid-conversation system messages (Opus 5.5 / 5 / 4.8, Sonnet 5.5, Haiku 5.5, Fable, Mythos) | a `system` message right after the user message (`system_message`) |
508
+ | `developer` (default) | anything else (Gemini, Bedrock, OpenRouter, Grok, OpenAI-compatible, a custom base URL, unlisted models) | text ahead of the user message, separated by a blank line (`user_message`) |
509
+ | `context` | any | text ahead of the user message (`user_message`) |
510
+
511
+ An operator-authority message outranks the user's own text, so a later user
512
+ sentence such as "skip verification" does not override it the way it can
513
+ when both share the user message.
514
+
515
+ The two operator placements differ in how they rank against the agent's own
516
+ system prompt. On Anthropic, a mid-conversation `system` message takes
517
+ precedence over the agent's system prompt for the rest of that run, so with
518
+ the default `developer` authority, turn instructions that conflict with the
519
+ system prompt win. On OpenAI, the `developer` message ranks above the user's
520
+ text but the agent's system prompt (sent as `instructions`) keeps priority.
521
+ Send `turnInstructionsAuthority: "context"` when turn instructions must never
522
+ outrank the agent's system prompt.
523
+
524
+ The `user_message` placement is the same
525
+ request turn instructions produced before `turnInstructionsAuthority`
526
+ existed. The evidence for each provider is kept with the platform source, in
527
+ `docs/turn-instructions-authority.md`.
528
+
529
+ The two older places for per-turn context each have a cost:
530
+
531
+ | Per-turn context sent as | Kept in session history | Changes the system prompt |
532
+ | ------------------------ | ---------------------------- | ------------------------- |
533
+ | part of the user message | yes, replayed on later turns | no |
534
+ | a `system` message | no | yes, every turn |
535
+ | `turnInstructions` | no | no |
536
+
537
+ Text in the user message is stored in the session transcript as sent, so every
538
+ later turn replays guidance that applied only to its own turn. A `system`
539
+ message is merged into the system prompt, so the system prompt differs on every
540
+ turn and provider prompt caches (Gemini implicit caching, Anthropic
541
+ `cache_control` on the system block) stop matching. With `turnInstructions`
542
+ the system prompt, tools and stored transcript stay byte-stable from turn to
543
+ turn. A request repeats the previous request up to the previous turn's user
544
+ message, which was sent with its instructions and is replayed without them, so
545
+ the reusable prefix ends there.
546
+
547
+ ```jsonc
548
+ // POST /agent-sessions/ses_abc/messages
549
+ {
550
+ "prompt": "Count the open tickets by owner.",
551
+ "turnInstructions": "Ticket fields: owner, status. Query the tracker; earlier answers may be stale.",
552
+ }
553
+ ```
554
+
555
+ Rules:
556
+
557
+ - Max 200,000 characters. Blank (or whitespace-only) instructions are ignored.
558
+ - The session transcript stores the user message exactly as sent, without the
559
+ instructions, so `GET /agent-sessions/:id` and later turns never see them.
560
+ - The supervisor's bounded goal context uses the undecorated conversation,
561
+ excluding turn instructions so they cannot crowd out the user's request.
562
+ - Per run only: `POST /agent-sessions` does not accept it, and a session message
563
+ without it gets none. The run's `agentSpec` (`GET /agent-runs/:id`) shows the
564
+ value it ran with, and once the run starts, `turnInstructionsPlacement`: where
565
+ the model's request put it. If the run fails over to a fallback model, the
566
+ value is updated to the fallback's placement: with `developer` authority a
567
+ fallback with support sends them at operator authority even when the
568
+ primary could not, and a fallback without support gets `user_message`.
569
+ - They stay in effect for the whole run: context compaction that drops or
570
+ summarizes the run's user message keeps the instructions, and they count
571
+ toward the context budget.
572
+ - A run that resumes after an approval or a worker shutdown keeps the
573
+ instructions it started with, in the same placement.
574
+ - File attachments on the user message are unaffected.
575
+
576
+ SDKs: TypeScript `turnInstructions` / `turnInstructionsAuthority` (run spec,
577
+ `session.send` / `session.stream` option), Python `turn_instructions` /
578
+ `turn_instructions_authority`, Go `RunSpec.TurnInstructions` /
579
+ `RunSpec.TurnInstructionsAuthority` and `WithTurnInstructions` /
580
+ `WithTurnInstructionsAuthority`.
581
+
494
582
  ### 4.1 Triggering a persisted MANTYX agent (`agentId`)
495
583
 
496
584
  Set `agentId` to the `id` of a workspace `Agent` to run that agent instead of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantyx/sdk",
3
- "version": "2026.11.2",
3
+ "version": "2026.11.3",
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",