@mastra/core 1.33.0-alpha.1 → 1.33.0-alpha.2
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 +14 -0
- package/dist/agent/agent.d.ts +11 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/durable/index.cjs +22 -22
- package/dist/agent/durable/index.js +4 -4
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +4 -0
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/browser/index.cjs +2 -2
- package/dist/browser/index.js +1 -1
- package/dist/channels/index.cjs +4 -4
- package/dist/channels/index.js +1 -1
- package/dist/{chunk-7M65H4UA.js → chunk-7DU5ZEI7.js} +3 -3
- package/dist/{chunk-7M65H4UA.js.map → chunk-7DU5ZEI7.js.map} +1 -1
- package/dist/{chunk-GQDJFBVF.js → chunk-7L4SZOZX.js} +6 -6
- package/dist/{chunk-GQDJFBVF.js.map → chunk-7L4SZOZX.js.map} +1 -1
- package/dist/{chunk-C6M5HBBX.cjs → chunk-7UVX6QCQ.cjs} +57 -24
- package/dist/chunk-7UVX6QCQ.cjs.map +1 -0
- package/dist/{chunk-L4Q63LCX.js → chunk-BTELIKVV.js} +45 -12
- package/dist/chunk-BTELIKVV.js.map +1 -0
- package/dist/{chunk-VUY4QAW4.cjs → chunk-CBVQV2MC.cjs} +224 -224
- package/dist/{chunk-VUY4QAW4.cjs.map → chunk-CBVQV2MC.cjs.map} +1 -1
- package/dist/{chunk-PA73DY5B.cjs → chunk-DIXS2HEO.cjs} +394 -153
- package/dist/chunk-DIXS2HEO.cjs.map +1 -0
- package/dist/{chunk-3OIXD6QZ.js → chunk-DNMUSSVS.js} +3 -3
- package/dist/{chunk-3OIXD6QZ.js.map → chunk-DNMUSSVS.js.map} +1 -1
- package/dist/{chunk-CHGGDYI6.cjs → chunk-HKAOLV6C.cjs} +389 -389
- package/dist/{chunk-CHGGDYI6.cjs.map → chunk-HKAOLV6C.cjs.map} +1 -1
- package/dist/{chunk-PBD75KII.js → chunk-KKVJWLOG.js} +4 -4
- package/dist/{chunk-PBD75KII.js.map → chunk-KKVJWLOG.js.map} +1 -1
- package/dist/{chunk-OPMKAUNT.js → chunk-LI47CL4R.js} +3 -3
- package/dist/{chunk-OPMKAUNT.js.map → chunk-LI47CL4R.js.map} +1 -1
- package/dist/{chunk-IFWVHG2M.cjs → chunk-MA5KNDJ7.cjs} +59 -59
- package/dist/{chunk-IFWVHG2M.cjs.map → chunk-MA5KNDJ7.cjs.map} +1 -1
- package/dist/{chunk-5AFWTTES.js → chunk-N3FYHMZR.js} +4 -4
- package/dist/{chunk-5AFWTTES.js.map → chunk-N3FYHMZR.js.map} +1 -1
- package/dist/{chunk-JOA5YBHN.js → chunk-NM4SFK6O.js} +3 -3
- package/dist/{chunk-JOA5YBHN.js.map → chunk-NM4SFK6O.js.map} +1 -1
- package/dist/{chunk-GB2CQKRS.cjs → chunk-RLC5SIPH.cjs} +9 -9
- package/dist/{chunk-GB2CQKRS.cjs.map → chunk-RLC5SIPH.cjs.map} +1 -1
- package/dist/{chunk-2YN2GWML.cjs → chunk-RQY43SKV.cjs} +3 -3
- package/dist/{chunk-2YN2GWML.cjs.map → chunk-RQY43SKV.cjs.map} +1 -1
- package/dist/{chunk-YXEOBUUH.js → chunk-SP4J4UBB.js} +9 -9
- package/dist/{chunk-YXEOBUUH.js.map → chunk-SP4J4UBB.js.map} +1 -1
- package/dist/{chunk-UGRXTMCT.js → chunk-UFQBQAMW.js} +3 -3
- package/dist/{chunk-UGRXTMCT.js.map → chunk-UFQBQAMW.js.map} +1 -1
- package/dist/{chunk-5LXIX7FZ.js → chunk-VQ5BAIDK.js} +385 -145
- package/dist/chunk-VQ5BAIDK.js.map +1 -0
- package/dist/{chunk-BSC4D3AA.cjs → chunk-X4CVAUMI.cjs} +22 -22
- package/dist/{chunk-BSC4D3AA.cjs.map → chunk-X4CVAUMI.cjs.map} +1 -1
- package/dist/{chunk-GVVA4JRD.cjs → chunk-XHA64NGS.cjs} +5 -5
- package/dist/{chunk-GVVA4JRD.cjs.map → chunk-XHA64NGS.cjs.map} +1 -1
- package/dist/{chunk-KE7K677R.cjs → chunk-XWQANVQ2.cjs} +7 -7
- package/dist/{chunk-KE7K677R.cjs.map → chunk-XWQANVQ2.cjs.map} +1 -1
- package/dist/{chunk-QBT4WKAU.cjs → chunk-XWRGP5O4.cjs} +7 -7
- package/dist/{chunk-QBT4WKAU.cjs.map → chunk-XWRGP5O4.cjs.map} +1 -1
- package/dist/datasets/index.cjs +11 -11
- package/dist/datasets/index.js +1 -1
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +211 -207
- package/dist/docs/references/docs-agents-processors.md +26 -2
- package/dist/docs/references/reference-processors-processor-interface.md +74 -12
- package/dist/docs/references/reference-processors-provider-history-compat.md +132 -0
- package/dist/docs/references/reference.md +1 -0
- package/dist/evals/index.cjs +6 -6
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +27 -22
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.js +25 -20
- package/dist/harness/index.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +20 -20
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +14 -2
- package/dist/loop/index.cjs +14 -14
- package/dist/loop/index.js +1 -1
- package/dist/loop/types.d.ts +1 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/mastra-LYBVVAEM.js +3 -0
- package/dist/{mastra-TBJEDBDE.js.map → mastra-LYBVVAEM.js.map} +1 -1
- package/dist/mastra-SAWYVVAO.cjs +12 -0
- package/dist/{mastra-XZZ5PGRE.cjs.map → mastra-SAWYVVAO.cjs.map} +1 -1
- package/dist/memory/index.cjs +19 -19
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-GR4H4HSO.js +3 -0
- package/dist/{models-dev-NBPBZGNU.js.map → models-dev-GR4H4HSO.js.map} +1 -1
- package/dist/models-dev-S7CNVODQ.cjs +12 -0
- package/dist/{models-dev-VYQYBTPH.cjs.map → models-dev-S7CNVODQ.cjs.map} +1 -1
- package/dist/netlify-SHROXKV7.cjs +12 -0
- package/dist/{netlify-B4ALATN2.cjs.map → netlify-SHROXKV7.cjs.map} +1 -1
- package/dist/netlify-TR7QGCG5.js +3 -0
- package/dist/{netlify-AHTOWHQ3.js.map → netlify-TR7QGCG5.js.map} +1 -1
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +55 -51
- package/dist/processors/index.d.ts +51 -3
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/provider-history-compat.d.ts +97 -17
- package/dist/processors/provider-history-compat.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +23 -0
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry-MCPX3HYB.cjs +44 -0
- package/dist/{provider-registry-5MSQZY5O.cjs.map → provider-registry-MCPX3HYB.cjs.map} +1 -1
- package/dist/provider-registry-NDEFG4LF.js +3 -0
- package/dist/{provider-registry-GPH6SHFV.js.map → provider-registry-NDEFG4LF.js.map} +1 -1
- package/dist/provider-registry.json +37 -4
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/runner-OTR5L3EM.js +3 -0
- package/dist/{runner-LF2L47BX.js.map → runner-OTR5L3EM.js.map} +1 -1
- package/dist/runner-YBVW5BC2.cjs +16 -0
- package/dist/{runner-HODGJLIH.cjs.map → runner-YBVW5BC2.cjs.map} +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +28 -28
- package/dist/workflows/index.js +1 -1
- package/package.json +5 -5
- package/src/llm/model/provider-types.generated.d.ts +14 -2
- package/dist/chunk-5LXIX7FZ.js.map +0 -1
- package/dist/chunk-C6M5HBBX.cjs.map +0 -1
- package/dist/chunk-L4Q63LCX.js.map +0 -1
- package/dist/chunk-PA73DY5B.cjs.map +0 -1
- package/dist/mastra-TBJEDBDE.js +0 -3
- package/dist/mastra-XZZ5PGRE.cjs +0 -12
- package/dist/models-dev-NBPBZGNU.js +0 -3
- package/dist/models-dev-VYQYBTPH.cjs +0 -12
- package/dist/netlify-AHTOWHQ3.js +0 -3
- package/dist/netlify-B4ALATN2.cjs +0 -12
- package/dist/provider-registry-5MSQZY5O.cjs +0 -44
- package/dist/provider-registry-GPH6SHFV.js +0 -3
- package/dist/runner-HODGJLIH.cjs +0 -16
- package/dist/runner-LF2L47BX.js +0 -3
|
@@ -211,6 +211,22 @@ The method receives the current `stepNumber`, `model`, `tools`, `toolChoice`, `m
|
|
|
211
211
|
|
|
212
212
|
See the [`Processor` reference](https://mastra.ai/reference/processors/processor-interface) for all available arguments and return types.
|
|
213
213
|
|
|
214
|
+
### Rewrite the LLM request before the provider call
|
|
215
|
+
|
|
216
|
+
Use `processLLMRequest()` when you need to rewrite the final prompt that Mastra sends to the model. This hook runs after Mastra converts the `MessageList` into the provider-facing prompt format (`LanguageModelV2Prompt`) and immediately before the provider call.
|
|
217
|
+
|
|
218
|
+
Use the message-based hooks for conversation changes:
|
|
219
|
+
|
|
220
|
+
- `processInput()`: Change the conversation once before the agentic loop starts.
|
|
221
|
+
- `processInputStep()`: Change messages or step configuration before each LLM call.
|
|
222
|
+
- `processLLMRequest()`: Change only the outbound prompt for the current provider call.
|
|
223
|
+
|
|
224
|
+
Changes returned from `processLLMRequest()` are transient. They don't persist back to `MessageList`, memory, UI history, or future provider calls. This makes the hook a good fit for provider compatibility rewrites, role/content normalization, or other model-specific prompt changes that shouldn't alter stored conversation history.
|
|
225
|
+
|
|
226
|
+
The method receives `prompt`, `model`, `stepNumber`, `steps`, `state`, and the shared processor context. Calling `abort()` from `processLLMRequest()` emits the normal tripwire response and stops the call.
|
|
227
|
+
|
|
228
|
+
See the [`Processor` reference](https://mastra.ai/reference/processors/processor-interface) for all available arguments and return types.
|
|
229
|
+
|
|
214
230
|
### Use the `prepareStep()` callback
|
|
215
231
|
|
|
216
232
|
The `prepareStep()` callback on `generate()` or `stream()` is a shorthand for `processInputStep()`. Internally, Mastra wraps it in a processor that calls your function at each step. It accepts the same arguments and return type as `processInputStep()`, but doesn't require creating a class:
|
|
@@ -317,7 +333,7 @@ For more on retry behavior, see [Retry mechanism](#retry-mechanism) in Advanced
|
|
|
317
333
|
|
|
318
334
|
### Persist data across chunks and steps
|
|
319
335
|
|
|
320
|
-
Output methods receive a `state` object that persists for the lifetime of one request. State is keyed by the processor's `id`, so each processor sees only its own data, and it
|
|
336
|
+
Output methods receive a `state` object that persists for the lifetime of one request. State is keyed by the processor's `id`, so each processor sees only its own data, and it's shared between `processOutputStream`, `processOutputStep`, and `processOutputResult`. A new state object is created for every new `agent.generate()` or `agent.stream()` call.
|
|
321
337
|
|
|
322
338
|
```typescript
|
|
323
339
|
import type { Processor } from '@mastra/core/processors'
|
|
@@ -383,6 +399,14 @@ Enables dynamic tool discovery for agents with large tool libraries. Instead of
|
|
|
383
399
|
|
|
384
400
|
See the [`ToolSearchProcessor` reference](https://mastra.ai/reference/processors/tool-search-processor) for configuration options and usage examples.
|
|
385
401
|
|
|
402
|
+
### `ProviderHistoryCompat`
|
|
403
|
+
|
|
404
|
+
Handles provider-specific history incompatibilities when agents reuse messages across model providers. It can rewrite the outbound LLM request before the provider call, or recover from known provider API errors and retry.
|
|
405
|
+
|
|
406
|
+
Add `ProviderHistoryCompat` explicitly when you need provider history compatibility rules, reactive API error recovery, custom compatibility rules, or predictable processor ordering.
|
|
407
|
+
|
|
408
|
+
See the [`ProviderHistoryCompat` reference](https://mastra.ai/reference/processors/provider-history-compat) for setup, built-in rules, and custom rule options.
|
|
409
|
+
|
|
386
410
|
## Advanced patterns
|
|
387
411
|
|
|
388
412
|
### Ensure a final response with `maxSteps`
|
|
@@ -494,7 +518,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
494
518
|
|
|
495
519
|
Custom chunk types must use the `data-` prefix (e.g., `data-moderation-update`, `data-status`).
|
|
496
520
|
|
|
497
|
-
By default, `processOutputStream()` skips `data-*` chunks so it
|
|
521
|
+
By default, `processOutputStream()` skips `data-*` chunks so it doesn't accidentally operate on tool telemetry or other processors' output. To inspect, modify, or block these chunks in a processor, set `processDataParts = true` on that processor:
|
|
498
522
|
|
|
499
523
|
```typescript
|
|
500
524
|
class ModerationCollector implements Processor {
|
|
@@ -4,7 +4,7 @@ The `Processor` interface defines the contract for all processors in Mastra. Pro
|
|
|
4
4
|
|
|
5
5
|
## When processor methods run
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The seven processor methods run at different points in the agent execution lifecycle:
|
|
8
8
|
|
|
9
9
|
```text
|
|
10
10
|
┌─────────────────────────────────────────────────────────────────┐
|
|
@@ -26,6 +26,11 @@ The six processor methods run at different points in the agent execution lifecyc
|
|
|
26
26
|
│ │ └──────────┬──────────┘ │ │
|
|
27
27
|
│ │ │ │ │
|
|
28
28
|
│ │ ▼ │ │
|
|
29
|
+
│ │ ┌─────────────────────┐ │ │
|
|
30
|
+
│ │ │ processLLMRequest │ ← Runs before provider call │ │
|
|
31
|
+
│ │ └──────────┬──────────┘ │ │
|
|
32
|
+
│ │ │ │ │
|
|
33
|
+
│ │ ▼ │ │
|
|
29
34
|
│ │ LLM Execution ──── API Error? ──┐ │ │
|
|
30
35
|
│ │ │ │ │ │
|
|
31
36
|
│ │ │ ┌───────────────────┐ │ │
|
|
@@ -59,14 +64,15 @@ The six processor methods run at different points in the agent execution lifecyc
|
|
|
59
64
|
└─────────────────────────────────────────────────────────────────┘
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
| Method | When it runs | Use case
|
|
63
|
-
| --------------------- | ------------------------------------------------------ |
|
|
64
|
-
| `processInput` | Once at the start, before the agentic loop | Validate/transform initial user input, add context
|
|
65
|
-
| `processInputStep` | At each step of the agentic loop, before each LLM call | Transform messages between steps, handle tool results
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
67
|
+
| Method | When it runs | Use case |
|
|
68
|
+
| --------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `processInput` | Once at the start, before the agentic loop | Validate/transform initial user input, add context |
|
|
70
|
+
| `processInputStep` | At each step of the agentic loop, before each LLM call | Transform messages between steps, handle tool results |
|
|
71
|
+
| `processLLMRequest` | After LLM request conversion, before the provider call | Rewrite the outbound `LanguageModelV2Prompt` for the current call without persisting changes |
|
|
72
|
+
| `processAPIError` | When an LLM API call fails | Inspect API rejections, optionally mutate state/messages, and request a retry |
|
|
73
|
+
| `processOutputStream` | On each streaming chunk during LLM response | Filter/modify streaming content, detect patterns in real-time |
|
|
74
|
+
| `processOutputStep` | After each LLM response, before tool execution | Validate output quality, implement guardrails with retry |
|
|
75
|
+
| `processOutputResult` | Once after generation completes | Post-process final response, log results |
|
|
70
76
|
|
|
71
77
|
## Interface definition
|
|
72
78
|
|
|
@@ -97,6 +103,10 @@ interface Processor<TId extends string = string, TTripwireMetadata = unknown> {
|
|
|
97
103
|
| void
|
|
98
104
|
| undefined
|
|
99
105
|
|
|
106
|
+
processLLMRequest?(
|
|
107
|
+
args: ProcessLLMRequestArgs<TTripwireMetadata>,
|
|
108
|
+
): Promise<ProcessLLMRequestResult> | ProcessLLMRequestResult
|
|
109
|
+
|
|
100
110
|
processAPIError?(
|
|
101
111
|
args: ProcessAPIErrorArgs<TTripwireMetadata>,
|
|
102
112
|
): Promise<ProcessAPIErrorResult | void> | ProcessAPIErrorResult | void
|
|
@@ -243,9 +253,10 @@ processInputStep?<TTripwireMetadata = unknown>(
|
|
|
243
253
|
1. `processInput` (once at start)
|
|
244
254
|
2. `processInputStep` from inputProcessors (at each step, before LLM call)
|
|
245
255
|
3. `prepareStep` callback (runs as part of the processInputStep pipeline, after inputProcessors)
|
|
246
|
-
4.
|
|
247
|
-
5.
|
|
248
|
-
6.
|
|
256
|
+
4. `processLLMRequest` from inputProcessors (after prompt conversion, before the provider call)
|
|
257
|
+
5. LLM execution
|
|
258
|
+
6. Tool execution (if needed)
|
|
259
|
+
7. Repeat from step 2 if tools were called
|
|
249
260
|
|
|
250
261
|
#### `ProcessInputStepArgs`
|
|
251
262
|
|
|
@@ -339,6 +350,57 @@ System messages are **reset to their original values** at the start of each step
|
|
|
339
350
|
|
|
340
351
|
***
|
|
341
352
|
|
|
353
|
+
### `processLLMRequest`
|
|
354
|
+
|
|
355
|
+
Processes the final LLM request after Mastra converts the `MessageList` into `LanguageModelV2Prompt` and before the provider call. Use this method for transient, model-aware rewrites that should affect only the current outbound request.
|
|
356
|
+
|
|
357
|
+
Returned prompt changes are forwarded to the model for the current call only. They are not persisted back to `MessageList`, memory, UI history, or later provider calls.
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
processLLMRequest?(
|
|
361
|
+
args: ProcessLLMRequestArgs,
|
|
362
|
+
): Promise<ProcessLLMRequestResult> | ProcessLLMRequestResult;
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
#### `ProcessLLMRequestArgs`
|
|
366
|
+
|
|
367
|
+
**prompt** (`LanguageModelV2Prompt`): The LLM request prompt that will be sent to the provider for this call.
|
|
368
|
+
|
|
369
|
+
**model** (`MastraLanguageModel`): The resolved model that will receive the prompt. Use this to scope provider-specific rewrites.
|
|
370
|
+
|
|
371
|
+
**stepNumber** (`number`): Current step number (0-indexed). Step 0 is the initial LLM call.
|
|
372
|
+
|
|
373
|
+
**steps** (`StepResult[]`): Results from previous steps, including text, toolCalls, and toolResults.
|
|
374
|
+
|
|
375
|
+
**state** (`Record<string, unknown>`): Per-processor state that persists across all method calls within this request.
|
|
376
|
+
|
|
377
|
+
**abort** (`(reason?: string, options?: { retry?: boolean; metadata?: unknown }) => never`): Function to abort processing. Throws a TripWire error that stops execution and emits a \`tripwire\` chunk.
|
|
378
|
+
|
|
379
|
+
**retryCount** (`number`): Current retry attempt count from \`ProcessorContext\`. Starts at \`0\`; use to cap processor-triggered retries.
|
|
380
|
+
|
|
381
|
+
**requestContext** (`RequestContext`): Request-scoped context with execution metadata.
|
|
382
|
+
|
|
383
|
+
**tracingContext** (`TracingContext`): Tracing context for observability.
|
|
384
|
+
|
|
385
|
+
**writer** (`ProcessorStreamWriter`): Stream writer for emitting custom data chunks during streaming. Use \`writer.custom()\` to send transient UI signals.
|
|
386
|
+
|
|
387
|
+
**abortSignal** (`AbortSignal`): Signal for cancelling the operation.
|
|
388
|
+
|
|
389
|
+
#### Return value
|
|
390
|
+
|
|
391
|
+
`processLLMRequest` returns `ProcessLLMRequestResult`, which is `{ prompt?: LanguageModelV2Prompt } | undefined | void`.
|
|
392
|
+
|
|
393
|
+
- Return `{ prompt }` to replace the outbound prompt for the current provider call.
|
|
394
|
+
- Return `undefined` or `void` to forward the original prompt unchanged.
|
|
395
|
+
|
|
396
|
+
#### Use cases
|
|
397
|
+
|
|
398
|
+
- Removing or reshaping provider-specific prompt parts before a model call
|
|
399
|
+
- Normalizing roles or content to match a provider's input requirements
|
|
400
|
+
- Adapting tool result formats when switching providers mid-loop
|
|
401
|
+
|
|
402
|
+
***
|
|
403
|
+
|
|
342
404
|
### `processAPIError`
|
|
343
405
|
|
|
344
406
|
Handles LLM API rejection errors before they surface as final errors. This runs when the API call fails with a non-retryable error (such as a 400 or 422 status code). Unlike `processOutputStep` which runs after successful responses, this runs when the API rejects the request.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# ProviderHistoryCompat
|
|
2
|
+
|
|
3
|
+
The `ProviderHistoryCompat` processor handles provider-specific history incompatibilities. It can rewrite the outbound language model prompt before a provider call, or react to API errors and retry with repaired message history.
|
|
4
|
+
|
|
5
|
+
Use it when an agent may switch between model providers, reuse message history across providers, or call a provider that rejects fields emitted by another provider.
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
Add `ProviderHistoryCompat` to `inputProcessors` when you want all built-in compatibility rules available for an agent:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { Agent } from '@mastra/core/agent'
|
|
13
|
+
import { ProviderHistoryCompat } from '@mastra/core/processors'
|
|
14
|
+
|
|
15
|
+
export const agent = new Agent({
|
|
16
|
+
name: 'my-agent',
|
|
17
|
+
instructions: 'You are a helpful assistant.',
|
|
18
|
+
model: 'anthropic/claude-sonnet-4-5',
|
|
19
|
+
inputProcessors: [new ProviderHistoryCompat()],
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Mastra agents don't add this processor automatically. Add it explicitly when you need provider history compatibility rules, reactive API error recovery, custom rules, or predictable processor ordering.
|
|
24
|
+
|
|
25
|
+
## Constructor parameters
|
|
26
|
+
|
|
27
|
+
**opts** (`{ additionalRules?: CompatRule[] }`): Configuration options for provider history compatibility rules.
|
|
28
|
+
|
|
29
|
+
**opts.additionalRules** (`CompatRule[]`): Custom compatibility rules to run after the built-in rules. Rules can rewrite the outbound prompt or repair persisted messages after matching an API error.
|
|
30
|
+
|
|
31
|
+
## Properties
|
|
32
|
+
|
|
33
|
+
**id** (`'provider-history-compat'`): Processor identifier.
|
|
34
|
+
|
|
35
|
+
**name** (`'Provider History Compat'`): Processor display name.
|
|
36
|
+
|
|
37
|
+
**processLLMRequest** (`(args: ProcessLLMRequestArgs) => ProcessLLMRequestResult`): Runs preemptive compatibility rules against the converted LanguageModelV2Prompt immediately before the provider call. Returned prompt changes are transient and are not persisted to memory or message history.
|
|
38
|
+
|
|
39
|
+
**processAPIError** (`(args: ProcessAPIErrorArgs) => Promise<ProcessAPIErrorResult | void>`): Runs reactive compatibility rules when a provider rejects the request. Matching rules can mutate the message list and return retry: true on the first retry attempt.
|
|
40
|
+
|
|
41
|
+
## Built-in rules
|
|
42
|
+
|
|
43
|
+
`ProviderHistoryCompat` includes these built-in compatibility rules:
|
|
44
|
+
|
|
45
|
+
| Rule | Provider | Timing | Behavior |
|
|
46
|
+
| ------------------------------------------- | --------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `anthropic-tool-id-format` | Anthropic | Reactive API error recovery | Rewrites tool call IDs that contain characters outside `[a-zA-Z0-9_-]` and retries the request. |
|
|
48
|
+
| `cerebras-strip-reasoning-content` | Cerebras | Preemptive prompt rewrite | Removes assistant `reasoning` parts from the outbound prompt so they're not serialized as unsupported `reasoning_content` fields. |
|
|
49
|
+
| `anthropic-strip-foreign-reasoning-content` | Anthropic | Preemptive prompt rewrite | Removes non-Anthropic assistant `reasoning` parts from the outbound prompt. Anthropic-native thinking history is preserved. |
|
|
50
|
+
|
|
51
|
+
Preemptive rules run through `processLLMRequest` after Mastra converts messages to the model prompt format and before the prompt is sent to the provider. These rewrites affect only the current provider call.
|
|
52
|
+
|
|
53
|
+
Reactive rules run through `processAPIError` after a provider rejection. They can update the persisted `messageList` and request a retry.
|
|
54
|
+
|
|
55
|
+
## `CompatRule`
|
|
56
|
+
|
|
57
|
+
A `CompatRule` defines one provider history compatibility fix:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type { CompatRule } from '@mastra/core/processors'
|
|
61
|
+
|
|
62
|
+
const removeUnsupportedPromptParts: CompatRule = {
|
|
63
|
+
name: 'remove-unsupported-prompt-parts',
|
|
64
|
+
applyToPrompt({ prompt, model }) {
|
|
65
|
+
// Return a modified LanguageModelV2Prompt, or undefined to leave it unchanged.
|
|
66
|
+
return undefined
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**name** (`string`): Human-readable rule identifier for logs and debugging.
|
|
72
|
+
|
|
73
|
+
**errorPatterns** (`RegExp[]`): Patterns matched against provider API error messages and response bodies. Required for reactive rules that implement fix.
|
|
74
|
+
|
|
75
|
+
**fix** (`(messages: MastraDBMessage[]) => boolean`): Reactive fix that mutates persisted database messages after a matching API error. Return true when the rule changed messages and the request should retry.
|
|
76
|
+
|
|
77
|
+
**applyToPrompt** (`(args: { prompt: LanguageModelV2Prompt; model: unknown }) => LanguageModelV2Prompt | undefined`): Preemptive fix that rewrites the outbound prompt for the current provider call. Return undefined when no prompt change is needed.
|
|
78
|
+
|
|
79
|
+
## Custom rules
|
|
80
|
+
|
|
81
|
+
Pass custom rules through `additionalRules`. Custom rules run after the built-in rules:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { Agent } from '@mastra/core/agent'
|
|
85
|
+
import { ProviderHistoryCompat, type CompatRule } from '@mastra/core/processors'
|
|
86
|
+
|
|
87
|
+
const stripUnsupportedAssistantMetadata: CompatRule = {
|
|
88
|
+
name: 'strip-unsupported-assistant-metadata',
|
|
89
|
+
applyToPrompt({ prompt, model }) {
|
|
90
|
+
if (typeof model !== 'string' || !model.startsWith('example-provider/')) {
|
|
91
|
+
return undefined
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let changed = false
|
|
95
|
+
const nextPrompt = prompt.map(message => {
|
|
96
|
+
if (message.role !== 'assistant' || typeof message.content === 'string') {
|
|
97
|
+
return message
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const nextContent = message.content.map(part => {
|
|
101
|
+
if (!('providerOptions' in part)) return part
|
|
102
|
+
changed = true
|
|
103
|
+
const { providerOptions: _providerOptions, ...rest } = part
|
|
104
|
+
return rest
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return { ...message, content: nextContent }
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return changed ? nextPrompt : undefined
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const agent = new Agent({
|
|
115
|
+
name: 'custom-provider-agent',
|
|
116
|
+
instructions: 'You are a helpful assistant.',
|
|
117
|
+
model: 'example-provider/model',
|
|
118
|
+
inputProcessors: [
|
|
119
|
+
new ProviderHistoryCompat({
|
|
120
|
+
additionalRules: [stripUnsupportedAssistantMetadata],
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use `applyToPrompt` for provider-specific rewrites that shouldn't be saved to memory. Use `fix` with `errorPatterns` when the provider rejects persisted message history and the repaired history should be reused on future turns.
|
|
127
|
+
|
|
128
|
+
## Related
|
|
129
|
+
|
|
130
|
+
- [Processor interface](https://mastra.ai/reference/processors/processor-interface)
|
|
131
|
+
- [Processors](https://mastra.ai/docs/agents/processors)
|
|
132
|
+
- [PrefillErrorHandler](https://mastra.ai/reference/processors/prefill-error-handler)
|
|
@@ -168,6 +168,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
168
168
|
- [PrefillErrorHandler](https://mastra.ai/reference/processors/prefill-error-handler)
|
|
169
169
|
- [Processor Interface](https://mastra.ai/reference/processors/processor-interface)
|
|
170
170
|
- [PromptInjectionDetector](https://mastra.ai/reference/processors/prompt-injection-detector)
|
|
171
|
+
- [ProviderHistoryCompat](https://mastra.ai/reference/processors/provider-history-compat)
|
|
171
172
|
- [RegexFilterProcessor](https://mastra.ai/reference/processors/regex-filter-processor)
|
|
172
173
|
- [SemanticRecall](https://mastra.ai/reference/processors/semantic-recall-processor)
|
|
173
174
|
- [SkillSearchProcessor](https://mastra.ai/reference/processors/skill-search-processor)
|
package/dist/evals/index.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkXHA64NGS_cjs = require('../chunk-XHA64NGS.cjs');
|
|
4
|
+
var chunkDIXS2HEO_cjs = require('../chunk-DIXS2HEO.cjs');
|
|
5
5
|
var chunkAU4KVBT6_cjs = require('../chunk-AU4KVBT6.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "runEvals", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkXHA64NGS_cjs.runEvals; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "MastraScorer", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkDIXS2HEO_cjs.MastraScorer; }
|
|
16
16
|
});
|
|
17
17
|
Object.defineProperty(exports, "createScorer", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
19
|
+
get: function () { return chunkDIXS2HEO_cjs.createScorer; }
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(exports, "filterRun", {
|
|
22
22
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
23
|
+
get: function () { return chunkDIXS2HEO_cjs.filterRun; }
|
|
24
24
|
});
|
|
25
25
|
Object.defineProperty(exports, "extractTrajectory", {
|
|
26
26
|
enumerable: true,
|
package/dist/evals/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { runEvals } from '../chunk-
|
|
2
|
-
export { MastraScorer, createScorer, filterRun } from '../chunk-
|
|
1
|
+
export { runEvals } from '../chunk-7DU5ZEI7.js';
|
|
2
|
+
export { MastraScorer, createScorer, filterRun } from '../chunk-VQ5BAIDK.js';
|
|
3
3
|
export { extractTrajectory, extractTrajectoryFromTrace, extractWorkflowTrajectory, listScoresResponseSchema, saveScorePayloadSchema, scoreResultSchema, scoreRowDataSchema, scoringEntityTypeSchema, scoringExtractStepResultSchema, scoringHookInputSchema, scoringInputSchema, scoringInputWithExtractStepResultAndAnalyzeStepResultSchema, scoringInputWithExtractStepResultAndScoreAndReasonSchema, scoringInputWithExtractStepResultSchema, scoringPromptsSchema, scoringSourceSchema, scoringValueSchema } from '../chunk-CJHHPVVU.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMA5KNDJ7_cjs = require('../../chunk-MA5KNDJ7.cjs');
|
|
4
4
|
var chunkAU4KVBT6_cjs = require('../../chunk-AU4KVBT6.cjs');
|
|
5
5
|
var chunk5IS5R433_cjs = require('../../chunk-5IS5R433.cjs');
|
|
6
6
|
var chunk4U7ZLI36_cjs = require('../../chunk-4U7ZLI36.cjs');
|
|
@@ -234,7 +234,7 @@ function transformTraceToScorerInputAndOutput(trace) {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
// src/evals/scoreTraces/scoreTracesWorkflow.ts
|
|
237
|
-
var getTraceStep =
|
|
237
|
+
var getTraceStep = chunkMA5KNDJ7_cjs.createStep({
|
|
238
238
|
id: "__process-trace-scoring",
|
|
239
239
|
inputSchema: v4.z.object({
|
|
240
240
|
targets: v4.z.array(
|
|
@@ -429,7 +429,7 @@ async function attachScoreToSpan({
|
|
|
429
429
|
} catch {
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
var scoreTracesWorkflow =
|
|
432
|
+
var scoreTracesWorkflow = chunkMA5KNDJ7_cjs.createWorkflow({
|
|
433
433
|
id: "__batch-scoring-traces",
|
|
434
434
|
inputSchema: v4.z.object({
|
|
435
435
|
targets: v4.z.array(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createStep, createWorkflow } from '../../chunk-
|
|
1
|
+
import { createStep, createWorkflow } from '../../chunk-LI47CL4R.js';
|
|
2
2
|
import { saveScorePayloadSchema } from '../../chunk-CJHHPVVU.js';
|
|
3
3
|
import { getEntityTypeForSpan } from '../../chunk-DCLOP22D.js';
|
|
4
4
|
import { MastraError } from '../../chunk-FJEVLHJT.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/harness/harness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAUnD,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,2BAA2B,EAC3B,sCAAsC,EAEtC,oBAAoB,EACpB,cAAc,EAEd,WAAW,EACX,qBAAqB,EAErB,cAAc,EACd,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACb,MAAM,SAAS,CAAC;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,OAAO,CAAC,MAAM,GAAG,EAAE;;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,SAAS,CAA8B;I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;IAoB5C,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAatD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxB,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IAY3C,OAAO,CAAC,UAAU;CAMnB"}
|
package/dist/harness/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkX4CVAUMI_cjs = require('../chunk-X4CVAUMI.cjs');
|
|
4
|
+
var chunkDIXS2HEO_cjs = require('../chunk-DIXS2HEO.cjs');
|
|
5
5
|
var chunk5ANWVE3P_cjs = require('../chunk-5ANWVE3P.cjs');
|
|
6
6
|
var chunkAX6D722J_cjs = require('../chunk-AX6D722J.cjs');
|
|
7
7
|
var chunkM4KUR53T_cjs = require('../chunk-M4KUR53T.cjs');
|
|
@@ -610,7 +610,7 @@ ${FORKED_SUBAGENT_NESTING_NOTICE}`;
|
|
|
610
610
|
isError: true
|
|
611
611
|
};
|
|
612
612
|
}
|
|
613
|
-
subagentToRun = new
|
|
613
|
+
subagentToRun = new chunkDIXS2HEO_cjs.Agent({
|
|
614
614
|
id: `subagent-${definition.id}`,
|
|
615
615
|
name: `${definition.name} Subagent`,
|
|
616
616
|
instructions: definition.instructions,
|
|
@@ -907,7 +907,7 @@ var Harness = class {
|
|
|
907
907
|
*/
|
|
908
908
|
async init() {
|
|
909
909
|
if (this.config.storage) {
|
|
910
|
-
this.#internalMastra = new
|
|
910
|
+
this.#internalMastra = new chunkX4CVAUMI_cjs.Mastra({
|
|
911
911
|
logger: false,
|
|
912
912
|
storage: this.config.storage,
|
|
913
913
|
...this.config.observability ? { observability: this.config.observability } : {}
|
|
@@ -1167,7 +1167,7 @@ var Harness = class {
|
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
1169
1169
|
try {
|
|
1170
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
1170
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-MCPX3HYB.cjs');
|
|
1171
1171
|
const registry = PROVIDER_REGISTRY;
|
|
1172
1172
|
const providerConfig = registry[provider];
|
|
1173
1173
|
const envVars = providerConfig?.apiKeyEnvVar;
|
|
@@ -1187,7 +1187,7 @@ var Harness = class {
|
|
|
1187
1187
|
*/
|
|
1188
1188
|
async listAvailableModels() {
|
|
1189
1189
|
try {
|
|
1190
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
1190
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-MCPX3HYB.cjs');
|
|
1191
1191
|
if (!PROVIDER_REGISTRY) return [];
|
|
1192
1192
|
const registry = PROVIDER_REGISTRY;
|
|
1193
1193
|
const providers = Object.keys(registry);
|
|
@@ -1246,7 +1246,7 @@ var Harness = class {
|
|
|
1246
1246
|
}
|
|
1247
1247
|
async getProviderApiKeyEnvVar(provider) {
|
|
1248
1248
|
try {
|
|
1249
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
1249
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-MCPX3HYB.cjs');
|
|
1250
1250
|
const registry = PROVIDER_REGISTRY;
|
|
1251
1251
|
const envVars = registry[provider]?.apiKeyEnvVar;
|
|
1252
1252
|
return Array.isArray(envVars) ? envVars[0] : envVars;
|
|
@@ -1537,28 +1537,33 @@ var Harness = class {
|
|
|
1537
1537
|
}
|
|
1538
1538
|
const meta = thread?.metadata;
|
|
1539
1539
|
const updates = {};
|
|
1540
|
-
|
|
1541
|
-
if (meta?.[modeModelKey]) {
|
|
1542
|
-
updates.currentModelId = meta[modeModelKey];
|
|
1543
|
-
} else if (meta?.currentModelId) {
|
|
1544
|
-
updates.currentModelId = meta.currentModelId;
|
|
1545
|
-
}
|
|
1540
|
+
let previousModeIdForEmit;
|
|
1546
1541
|
if (meta?.currentModeId) {
|
|
1547
1542
|
const savedModeId = meta.currentModeId;
|
|
1548
1543
|
const modeExists = this.config.modes.some((m) => m.id === savedModeId);
|
|
1549
1544
|
if (modeExists && savedModeId !== this.currentModeId) {
|
|
1545
|
+
previousModeIdForEmit = this.currentModeId;
|
|
1550
1546
|
this.currentModeId = savedModeId;
|
|
1551
|
-
const restoredModeModelKey = `modeModelId_${savedModeId}`;
|
|
1552
|
-
if (meta[restoredModeModelKey]) {
|
|
1553
|
-
updates.currentModelId = meta[restoredModeModelKey];
|
|
1554
|
-
}
|
|
1555
|
-
this.emit({
|
|
1556
|
-
type: "mode_changed",
|
|
1557
|
-
modeId: savedModeId,
|
|
1558
|
-
previousModeId: this.config.modes.find((m) => m.default)?.id || this.config.modes[0].id
|
|
1559
|
-
});
|
|
1560
1547
|
}
|
|
1561
1548
|
}
|
|
1549
|
+
const modeModelKey = `modeModelId_${this.currentModeId}`;
|
|
1550
|
+
if (meta?.[modeModelKey]) {
|
|
1551
|
+
updates.currentModelId = meta[modeModelKey];
|
|
1552
|
+
} else {
|
|
1553
|
+
const currentMode = this.config.modes.find((m) => m.id === this.currentModeId);
|
|
1554
|
+
if (currentMode?.defaultModelId) {
|
|
1555
|
+
updates.currentModelId = currentMode.defaultModelId;
|
|
1556
|
+
} else if (meta?.currentModelId) {
|
|
1557
|
+
updates.currentModelId = meta.currentModelId;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
if (previousModeIdForEmit !== void 0) {
|
|
1561
|
+
this.emit({
|
|
1562
|
+
type: "mode_changed",
|
|
1563
|
+
modeId: this.currentModeId,
|
|
1564
|
+
previousModeId: previousModeIdForEmit
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1562
1567
|
if (meta?.observerModelId) {
|
|
1563
1568
|
updates.observerModelId = meta.observerModelId;
|
|
1564
1569
|
}
|