@mastra/mcp-docs-server 0.13.24 → 0.13.25-alpha.1
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/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +8 -8
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +24 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +22 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +46 -46
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +104 -104
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +40 -40
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Flance.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +73 -73
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Frag.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Freact.md +17 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +51 -51
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +20 -3
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +32 -32
- package/.docs/organized/changelogs/mastra.md +64 -64
- package/.docs/organized/code-examples/agent.md +0 -4
- package/.docs/organized/code-examples/ai-elements.md +47 -0
- package/.docs/organized/code-examples/heads-up-game.md +5 -5
- package/.docs/raw/auth/clerk.mdx +3 -3
- package/.docs/raw/index.mdx +1 -0
- package/.docs/raw/observability/ai-tracing/exporters/braintrust.mdx +81 -0
- package/.docs/raw/observability/ai-tracing/exporters/cloud.mdx +120 -0
- package/.docs/raw/observability/ai-tracing/exporters/default.mdx +168 -0
- package/.docs/raw/observability/ai-tracing/exporters/langfuse.mdx +121 -0
- package/.docs/raw/observability/ai-tracing/exporters/langsmith.mdx +88 -0
- package/.docs/raw/observability/ai-tracing/exporters/otel.mdx +250 -0
- package/.docs/raw/observability/ai-tracing/overview.mdx +565 -0
- package/.docs/raw/observability/ai-tracing/processors/sensitive-data-filter.mdx +274 -0
- package/.docs/raw/observability/{tracing.mdx → otel-tracing.mdx} +2 -2
- package/.docs/raw/observability/overview.mdx +66 -0
- package/.docs/raw/reference/agents/generate.mdx +39 -1
- package/.docs/raw/reference/agents/generateVNext.mdx +34 -2
- package/.docs/raw/reference/agents/network.mdx +35 -3
- package/.docs/raw/reference/auth/clerk.mdx +1 -1
- package/.docs/raw/reference/client-js/agents.mdx +4 -13
- package/.docs/raw/reference/client-js/mastra-client.mdx +10 -0
- package/.docs/raw/reference/client-js/observability.mdx +76 -0
- package/.docs/raw/reference/core/getScorer.mdx +75 -0
- package/.docs/raw/reference/core/getScorerByName.mdx +75 -0
- package/.docs/raw/reference/core/getScorers.mdx +42 -0
- package/.docs/raw/reference/core/mastra-class.mdx +7 -0
- package/.docs/raw/reference/observability/ai-tracing/ai-tracing.mdx +182 -0
- package/.docs/raw/reference/observability/ai-tracing/configuration.mdx +234 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/braintrust.mdx +112 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/cloud-exporter.mdx +176 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/console-exporter.mdx +148 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/default-exporter.mdx +196 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/langfuse.mdx +116 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/langsmith.mdx +112 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/otel.mdx +355 -0
- package/.docs/raw/reference/observability/ai-tracing/interfaces.mdx +651 -0
- package/.docs/raw/reference/observability/ai-tracing/processors/sensitive-data-filter.mdx +178 -0
- package/.docs/raw/reference/observability/ai-tracing/span.mdx +371 -0
- package/.docs/raw/reference/observability/{logger.mdx → logging/pino-logger.mdx} +1 -1
- package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/index.mdx +6 -4
- package/.docs/raw/reference/scorers/create-scorer.mdx +59 -9
- package/.docs/raw/reference/scorers/mastra-scorer.mdx +6 -0
- package/.docs/raw/reference/scorers/run-experiment.mdx +216 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +3 -2
- package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +41 -3
- package/.docs/raw/reference/streaming/agents/streamVNext.mdx +34 -2
- package/.docs/raw/reference/streaming/workflows/resumeStreamVNext.mdx +17 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +39 -1
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +39 -1
- package/.docs/raw/reference/tools/create-tool.mdx +34 -1
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +38 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +38 -0
- package/.docs/raw/scorers/custom-scorers.mdx +16 -1
- package/.docs/raw/scorers/overview.mdx +28 -0
- package/CHANGELOG.md +15 -0
- package/package.json +6 -6
- package/.docs/raw/observability/ai-tracing.mdx +0 -597
- /package/.docs/raw/reference/observability/{otel-config.mdx → otel-tracing/otel-config.mdx} +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-ax.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-phoenix.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/braintrust.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/dash0.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/keywordsai.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/laminar.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langfuse.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langsmith.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langwatch.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/new-relic.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/signoz.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/traceloop.mdx +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: runExperiment | Scorers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the runExperiment function in Mastra, which enables batch evaluation of agents and workflows using multiple scorers."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# runExperiment
|
|
7
|
+
|
|
8
|
+
The `runExperiment` function enables batch evaluation of agents and workflows by running multiple test cases against scorers concurrently. This is essential for systematic testing, performance analysis, and validation of AI systems.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { runExperiment } from '@mastra/core/scores';
|
|
14
|
+
import { myAgent } from './agents/my-agent';
|
|
15
|
+
import { myScorer1, myScorer2 } from './scorers';
|
|
16
|
+
|
|
17
|
+
const result = await runExperiment({
|
|
18
|
+
target: myAgent,
|
|
19
|
+
data: [
|
|
20
|
+
{ input: "What is machine learning?" },
|
|
21
|
+
{ input: "Explain neural networks" },
|
|
22
|
+
{ input: "How does AI work?" }
|
|
23
|
+
],
|
|
24
|
+
scorers: [myScorer1, myScorer2],
|
|
25
|
+
concurrency: 2,
|
|
26
|
+
onItemComplete: ({ item, targetResult, scorerResults }) => {
|
|
27
|
+
console.log(`Completed: ${item.input}`);
|
|
28
|
+
console.log(`Scores:`, scorerResults);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(`Average scores:`, result.scores);
|
|
33
|
+
console.log(`Processed ${result.summary.totalItems} items`);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Parameters
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "target",
|
|
42
|
+
type: "Agent | Workflow",
|
|
43
|
+
description: "The agent or workflow to evaluate.",
|
|
44
|
+
isOptional: false,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "data",
|
|
48
|
+
type: "RunExperimentDataItem[]",
|
|
49
|
+
description: "Array of test cases with input data and optional ground truth.",
|
|
50
|
+
isOptional: false,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "scorers",
|
|
54
|
+
type: "MastraScorer[] | WorkflowScorerConfig",
|
|
55
|
+
description: "Array of scorers for agents, or configuration object for workflows specifying scorers for the workflow and individual steps.",
|
|
56
|
+
isOptional: false,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "concurrency",
|
|
60
|
+
type: "number",
|
|
61
|
+
description: "Number of test cases to run concurrently.",
|
|
62
|
+
isOptional: true,
|
|
63
|
+
defaultValue: "1",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "onItemComplete",
|
|
67
|
+
type: "function",
|
|
68
|
+
description: "Callback function called after each test case completes. Receives item, target result, and scorer results.",
|
|
69
|
+
isOptional: true,
|
|
70
|
+
},
|
|
71
|
+
]}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
## Data Item Structure
|
|
75
|
+
|
|
76
|
+
<PropertiesTable
|
|
77
|
+
content={[
|
|
78
|
+
{
|
|
79
|
+
name: "input",
|
|
80
|
+
type: "string | string[] | CoreMessage[] | any",
|
|
81
|
+
description: "Input data for the target. For agents: messages or strings. For workflows: workflow input data.",
|
|
82
|
+
isOptional: false,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "groundTruth",
|
|
86
|
+
type: "any",
|
|
87
|
+
description: "Expected or reference output for comparison during scoring.",
|
|
88
|
+
isOptional: true,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "runtimeContext",
|
|
92
|
+
type: "RuntimeContext",
|
|
93
|
+
description: "Runtime context to pass to the target during execution.",
|
|
94
|
+
isOptional: true,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "tracingContext",
|
|
98
|
+
type: "TracingContext",
|
|
99
|
+
description: "Tracing context for observability and debugging.",
|
|
100
|
+
isOptional: true,
|
|
101
|
+
},
|
|
102
|
+
]}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
## Workflow Scorer Configuration
|
|
106
|
+
|
|
107
|
+
For workflows, you can specify scorers at different levels using `WorkflowScorerConfig`:
|
|
108
|
+
|
|
109
|
+
<PropertiesTable
|
|
110
|
+
content={[
|
|
111
|
+
{
|
|
112
|
+
name: "workflow",
|
|
113
|
+
type: "MastraScorer[]",
|
|
114
|
+
description: "Array of scorers to evaluate the entire workflow output.",
|
|
115
|
+
isOptional: true,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "steps",
|
|
119
|
+
type: "Record<string, MastraScorer[]>",
|
|
120
|
+
description: "Object mapping step IDs to arrays of scorers for evaluating individual step outputs.",
|
|
121
|
+
isOptional: true,
|
|
122
|
+
},
|
|
123
|
+
]}
|
|
124
|
+
/>
|
|
125
|
+
|
|
126
|
+
## Returns
|
|
127
|
+
|
|
128
|
+
<PropertiesTable
|
|
129
|
+
content={[
|
|
130
|
+
{
|
|
131
|
+
name: "scores",
|
|
132
|
+
type: "Record<string, any>",
|
|
133
|
+
description: "Average scores across all test cases, organized by scorer name.",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "summary",
|
|
137
|
+
type: "object",
|
|
138
|
+
description: "Summary information about the experiment execution.",
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "summary.totalItems",
|
|
142
|
+
type: "number",
|
|
143
|
+
description: "Total number of test cases processed.",
|
|
144
|
+
},
|
|
145
|
+
]}
|
|
146
|
+
/>
|
|
147
|
+
|
|
148
|
+
## Examples
|
|
149
|
+
|
|
150
|
+
### Agent Evaluation
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { runExperiment } from '@mastra/core/scores';
|
|
154
|
+
import { createScorer } from '@mastra/core/scores';
|
|
155
|
+
|
|
156
|
+
const myScorer = createScorer({
|
|
157
|
+
name: 'My Scorer',
|
|
158
|
+
description: "Check if Agent's response contains ground truth",
|
|
159
|
+
type: 'agent'
|
|
160
|
+
}).generateScore(({ run }) => {
|
|
161
|
+
const response = run.output[0]?.content || '';
|
|
162
|
+
const expectedResponse = run.groundTruth
|
|
163
|
+
return response.includes(expectedResponse) ? 1 : 0
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const result = await runExperiment({
|
|
167
|
+
target: chatAgent,
|
|
168
|
+
data: [
|
|
169
|
+
{
|
|
170
|
+
input: "What is AI?",
|
|
171
|
+
groundTruth: "AI is a field of computer science that creates intelligent machines."
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
input: "How does machine learning work?",
|
|
175
|
+
groundTruth: "Machine learning uses algorithms to learn patterns from data."
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
scorers: [relevancyScorer],
|
|
179
|
+
concurrency: 3
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Workflow Evaluation
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const workflowResult = await runExperiment({
|
|
187
|
+
target: myWorkflow,
|
|
188
|
+
data: [
|
|
189
|
+
{ input: { query: "Process this data", priority: "high" } },
|
|
190
|
+
{ input: { query: "Another task", priority: "low" } }
|
|
191
|
+
],
|
|
192
|
+
scorers: {
|
|
193
|
+
workflow: [outputQualityScorer],
|
|
194
|
+
steps: {
|
|
195
|
+
'validation-step': [validationScorer],
|
|
196
|
+
'processing-step': [processingScorer]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
onItemComplete: ({ item, targetResult, scorerResults }) => {
|
|
200
|
+
console.log(`Workflow completed for: ${item.input.query}`);
|
|
201
|
+
if (scorerResults.workflow) {
|
|
202
|
+
console.log('Workflow scores:', scorerResults.workflow);
|
|
203
|
+
}
|
|
204
|
+
if (scorerResults.steps) {
|
|
205
|
+
console.log('Step scores:', scorerResults.steps);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Related
|
|
212
|
+
|
|
213
|
+
- [createScorer()](../../reference/scorers/create-scorer) - Create custom scorers for experiments
|
|
214
|
+
- [MastraScorer](../../reference/scorers/mastra-scorer) - Learn about scorer structure and methods
|
|
215
|
+
- [Custom Scorers](../../docs/scorers/custom-scorers) - Guide to building evaluation logic
|
|
216
|
+
- [Scorers Overview](../../docs/scorers/overview) - Understanding scorer concepts
|
|
@@ -853,5 +853,6 @@ for await (const chunk of stream.fullStream) {
|
|
|
853
853
|
|
|
854
854
|
## Related Types
|
|
855
855
|
|
|
856
|
-
- [MastraModelOutput](./MastraModelOutput.mdx) - The stream object that emits these chunks
|
|
857
|
-
- [.streamVNext()](./streamVNext.mdx) - Method that returns streams emitting these chunks
|
|
856
|
+
- [MastraModelOutput](./agents/MastraModelOutput.mdx) - The stream object that emits these chunks
|
|
857
|
+
- [agent.streamVNext()](./agents/streamVNext.mdx) - Method that returns streams emitting these chunks for agents
|
|
858
|
+
- [workflow.streamVNext()](./workflows/streamVNext.mdx) - Method that returns streams emitting these chunks for workflows
|
|
@@ -318,5 +318,5 @@ if (stream.error) {
|
|
|
318
318
|
|
|
319
319
|
## Related Types
|
|
320
320
|
|
|
321
|
-
- [ChunkType](
|
|
321
|
+
- [ChunkType](../ChunkType.mdx) - All possible chunk types in the full stream
|
|
322
322
|
- [.streamVNext()](./streamVNext.mdx) - Method that returns MastraModelOutput
|
|
@@ -182,7 +182,7 @@ await agent.stream("message for agent");
|
|
|
182
182
|
type: "TelemetrySettings",
|
|
183
183
|
isOptional: true,
|
|
184
184
|
description:
|
|
185
|
-
"Settings for telemetry collection during streaming.",
|
|
185
|
+
"Settings for OTLP telemetry collection during streaming (not AI tracing).",
|
|
186
186
|
properties: [
|
|
187
187
|
{
|
|
188
188
|
parameters: [{
|
|
@@ -341,6 +341,38 @@ await agent.stream("message for agent");
|
|
|
341
341
|
isOptional: true,
|
|
342
342
|
description: "Runtime context for dependency injection and contextual information.",
|
|
343
343
|
},
|
|
344
|
+
{
|
|
345
|
+
name: "tracingContext",
|
|
346
|
+
type: "TracingContext",
|
|
347
|
+
isOptional: true,
|
|
348
|
+
description: "AI tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
349
|
+
properties: [
|
|
350
|
+
{
|
|
351
|
+
parameters: [{
|
|
352
|
+
name: "currentSpan",
|
|
353
|
+
type: "AISpan",
|
|
354
|
+
isOptional: true,
|
|
355
|
+
description: "Current AI span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution."
|
|
356
|
+
}]
|
|
357
|
+
}
|
|
358
|
+
]
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: "tracingOptions",
|
|
362
|
+
type: "TracingOptions",
|
|
363
|
+
isOptional: true,
|
|
364
|
+
description: "Options for AI tracing configuration.",
|
|
365
|
+
properties: [
|
|
366
|
+
{
|
|
367
|
+
parameters: [{
|
|
368
|
+
name: "metadata",
|
|
369
|
+
type: "Record<string, any>",
|
|
370
|
+
isOptional: true,
|
|
371
|
+
description: "Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags."
|
|
372
|
+
}]
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
},
|
|
344
376
|
{
|
|
345
377
|
name: "maxTokens",
|
|
346
378
|
type: "number",
|
|
@@ -456,6 +488,12 @@ await agent.stream("message for agent");
|
|
|
456
488
|
}
|
|
457
489
|
]
|
|
458
490
|
},
|
|
491
|
+
{
|
|
492
|
+
name: "traceId",
|
|
493
|
+
type: "string",
|
|
494
|
+
isOptional: true,
|
|
495
|
+
description: "The trace ID associated with this execution when AI tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
496
|
+
},
|
|
459
497
|
]}
|
|
460
498
|
/>
|
|
461
499
|
|
|
@@ -475,5 +513,5 @@ await agent.stream("message for agent", {
|
|
|
475
513
|
|
|
476
514
|
## Related
|
|
477
515
|
|
|
478
|
-
- [Generating responses](
|
|
479
|
-
- [Streaming responses](
|
|
516
|
+
- [Generating responses](../../../../docs/agents/overview.mdx#generating-responses)
|
|
517
|
+
- [Streaming responses](../../../../docs/agents/overview.mdx#streaming-responses)
|
|
@@ -105,6 +105,32 @@ const aiSdkStream = await agent.streamVNext("message for agent", {
|
|
|
105
105
|
type: "TracingContext",
|
|
106
106
|
isOptional: true,
|
|
107
107
|
description: "AI tracing context for span hierarchy and metadata.",
|
|
108
|
+
properties: [
|
|
109
|
+
{
|
|
110
|
+
parameters: [{
|
|
111
|
+
name: "currentSpan",
|
|
112
|
+
type: "AISpan",
|
|
113
|
+
isOptional: true,
|
|
114
|
+
description: "Current AI span for creating child spans and adding metadata."
|
|
115
|
+
}]
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "tracingOptions",
|
|
121
|
+
type: "TracingOptions",
|
|
122
|
+
isOptional: true,
|
|
123
|
+
description: "Options for AI tracing configuration.",
|
|
124
|
+
properties: [
|
|
125
|
+
{
|
|
126
|
+
parameters: [{
|
|
127
|
+
name: "metadata",
|
|
128
|
+
type: "Record<string, any>",
|
|
129
|
+
isOptional: true,
|
|
130
|
+
description: "Metadata to add to the root trace span."
|
|
131
|
+
}]
|
|
132
|
+
}
|
|
133
|
+
]
|
|
108
134
|
},
|
|
109
135
|
{
|
|
110
136
|
name: "returnScorerData",
|
|
@@ -292,7 +318,7 @@ const aiSdkStream = await agent.streamVNext("message for agent", {
|
|
|
292
318
|
type: "TelemetrySettings",
|
|
293
319
|
isOptional: true,
|
|
294
320
|
description:
|
|
295
|
-
"Settings for telemetry collection during streaming.",
|
|
321
|
+
"Settings for OTLP telemetry collection during streaming (not AI tracing).",
|
|
296
322
|
properties: [
|
|
297
323
|
{
|
|
298
324
|
parameters: [{
|
|
@@ -525,7 +551,13 @@ const aiSdkStream = await agent.streamVNext("message for agent", {
|
|
|
525
551
|
{
|
|
526
552
|
name: "stream",
|
|
527
553
|
type: "MastraModelOutput<Output> | AISDKV5OutputStream<Output>",
|
|
528
|
-
description: "Returns a streaming interface based on the format parameter. When format is 'mastra' (default), returns MastraModelOutput. When format is 'aisdk', returns AISDKV5OutputStream for AI SDK v5 compatibility.",
|
|
554
|
+
description: "Returns a streaming interface based on the format parameter. When format is 'mastra' (default), returns MastraModelOutput with traceId property. When format is 'aisdk', returns AISDKV5OutputStream for AI SDK v5 compatibility.",
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
name: "traceId",
|
|
558
|
+
type: "string",
|
|
559
|
+
isOptional: true,
|
|
560
|
+
description: "The trace ID associated with this execution when AI tracing is enabled. Available via stream.traceId for Mastra format.",
|
|
529
561
|
},
|
|
530
562
|
]}
|
|
531
563
|
/>
|
|
@@ -53,6 +53,22 @@ if (result.status === "suspended") {
|
|
|
53
53
|
description: "The step to resume execution from",
|
|
54
54
|
isOptional: true,
|
|
55
55
|
},
|
|
56
|
+
{
|
|
57
|
+
name: "tracingOptions",
|
|
58
|
+
type: "TracingOptions",
|
|
59
|
+
isOptional: true,
|
|
60
|
+
description: "Options for AI tracing configuration.",
|
|
61
|
+
properties: [
|
|
62
|
+
{
|
|
63
|
+
parameters: [{
|
|
64
|
+
name: "metadata",
|
|
65
|
+
type: "Record<string, any>",
|
|
66
|
+
isOptional: true,
|
|
67
|
+
description: "Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags."
|
|
68
|
+
}]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
56
72
|
]}
|
|
57
73
|
/>
|
|
58
74
|
|
|
@@ -96,5 +112,5 @@ The stream emits various event types during workflow execution. Each event has a
|
|
|
96
112
|
## Related
|
|
97
113
|
|
|
98
114
|
- [Workflows overview](../../../docs/workflows/overview.mdx#run-workflow)
|
|
99
|
-
- [Workflow.createRunAsync()](
|
|
115
|
+
- [Workflow.createRunAsync()](../../../reference/workflows/workflow-methods/create-run.mdx)
|
|
100
116
|
- [Run.streamVNext()](./streamVNext.mdx)
|
|
@@ -35,6 +35,38 @@ const stream = await run.stream({
|
|
|
35
35
|
description: "Runtime context data to use during workflow execution",
|
|
36
36
|
isOptional: true,
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
name: "tracingContext",
|
|
40
|
+
type: "TracingContext",
|
|
41
|
+
isOptional: true,
|
|
42
|
+
description: "AI tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
43
|
+
properties: [
|
|
44
|
+
{
|
|
45
|
+
parameters: [{
|
|
46
|
+
name: "currentSpan",
|
|
47
|
+
type: "AISpan",
|
|
48
|
+
isOptional: true,
|
|
49
|
+
description: "Current AI span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution."
|
|
50
|
+
}]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "tracingOptions",
|
|
56
|
+
type: "TracingOptions",
|
|
57
|
+
isOptional: true,
|
|
58
|
+
description: "Options for AI tracing configuration.",
|
|
59
|
+
properties: [
|
|
60
|
+
{
|
|
61
|
+
parameters: [{
|
|
62
|
+
name: "metadata",
|
|
63
|
+
type: "Record<string, any>",
|
|
64
|
+
isOptional: true,
|
|
65
|
+
description: "Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags."
|
|
66
|
+
}]
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
38
70
|
]}
|
|
39
71
|
/>
|
|
40
72
|
|
|
@@ -52,6 +84,12 @@ const stream = await run.stream({
|
|
|
52
84
|
type: "() => Promise<WorkflowResult<TOutput, TSteps>>",
|
|
53
85
|
description: "A function that returns a promise resolving to the final workflow result",
|
|
54
86
|
},
|
|
87
|
+
{
|
|
88
|
+
name: "traceId",
|
|
89
|
+
type: "string",
|
|
90
|
+
isOptional: true,
|
|
91
|
+
description: "The trace ID associated with this execution when AI tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
92
|
+
},
|
|
55
93
|
]}
|
|
56
94
|
/>
|
|
57
95
|
|
|
@@ -84,4 +122,4 @@ The stream emits various event types during workflow execution. Each event has a
|
|
|
84
122
|
## Related
|
|
85
123
|
|
|
86
124
|
- [Workflows overview](../../../docs/workflows/overview.mdx#run-workflow)
|
|
87
|
-
- [Workflow.createRunAsync()](
|
|
125
|
+
- [Workflow.createRunAsync()](../../../reference/workflows/workflow-methods/create-run.mdx)
|
|
@@ -39,6 +39,38 @@ const stream = run.streamVNext({
|
|
|
39
39
|
description: "Runtime context data to use during workflow execution",
|
|
40
40
|
isOptional: true,
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
name: "tracingContext",
|
|
44
|
+
type: "TracingContext",
|
|
45
|
+
isOptional: true,
|
|
46
|
+
description: "AI tracing context for creating child spans and adding metadata.",
|
|
47
|
+
properties: [
|
|
48
|
+
{
|
|
49
|
+
parameters: [{
|
|
50
|
+
name: "currentSpan",
|
|
51
|
+
type: "AISpan",
|
|
52
|
+
isOptional: true,
|
|
53
|
+
description: "Current AI span for creating child spans and adding metadata."
|
|
54
|
+
}]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "tracingOptions",
|
|
60
|
+
type: "TracingOptions",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
description: "Options for AI tracing configuration.",
|
|
63
|
+
properties: [
|
|
64
|
+
{
|
|
65
|
+
parameters: [{
|
|
66
|
+
name: "metadata",
|
|
67
|
+
type: "Record<string, any>",
|
|
68
|
+
isOptional: true,
|
|
69
|
+
description: "Metadata to add to the root trace span."
|
|
70
|
+
}]
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
42
74
|
{
|
|
43
75
|
name: "closeOnSuspend",
|
|
44
76
|
type: "boolean",
|
|
@@ -72,6 +104,12 @@ const stream = run.streamVNext({
|
|
|
72
104
|
type: "Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cacheInputTokens?: number }>",
|
|
73
105
|
description: "A promise that resolves to token usage statistics",
|
|
74
106
|
},
|
|
107
|
+
{
|
|
108
|
+
name: "stream.traceId",
|
|
109
|
+
type: "string",
|
|
110
|
+
isOptional: true,
|
|
111
|
+
description: "The trace ID associated with this execution when AI tracing is enabled.",
|
|
112
|
+
},
|
|
75
113
|
]}
|
|
76
114
|
/>
|
|
77
115
|
|
|
@@ -102,5 +140,5 @@ The stream emits various event types during workflow execution. Each event has a
|
|
|
102
140
|
## Related
|
|
103
141
|
|
|
104
142
|
- [Workflows overview](../../../docs/workflows/overview.mdx#run-workflow)
|
|
105
|
-
- [Workflow.createRunAsync()](
|
|
143
|
+
- [Workflow.createRunAsync()](../../../reference/workflows/workflow-methods/create-run.mdx)
|
|
106
144
|
- [Run.resumeStreamVNext()](./resumeStreamVNext.mdx)
|
|
@@ -68,8 +68,41 @@ export const tool = createTool({
|
|
|
68
68
|
name: "execute",
|
|
69
69
|
type: "function",
|
|
70
70
|
description:
|
|
71
|
-
"The function that contains the tool's logic. It receives an object with `context` (the parsed input based on `inputSchema`), `runtimeContext`, and an object containing `abortSignal`.",
|
|
71
|
+
"The function that contains the tool's logic. It receives an object with `context` (the parsed input based on `inputSchema`), `runtimeContext`, `tracingContext`, and an object containing `abortSignal`.",
|
|
72
72
|
isOptional: false,
|
|
73
|
+
properties: [
|
|
74
|
+
{
|
|
75
|
+
parameters: [{
|
|
76
|
+
name: "context",
|
|
77
|
+
type: "z.infer<TInput>",
|
|
78
|
+
description: "The parsed input based on inputSchema"
|
|
79
|
+
}]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
parameters: [{
|
|
83
|
+
name: "runtimeContext",
|
|
84
|
+
type: "RuntimeContext",
|
|
85
|
+
isOptional: true,
|
|
86
|
+
description: "Runtime context for accessing shared state and dependencies"
|
|
87
|
+
}]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
parameters: [{
|
|
91
|
+
name: "tracingContext",
|
|
92
|
+
type: "TracingContext",
|
|
93
|
+
isOptional: true,
|
|
94
|
+
description: "AI tracing context for creating child spans and adding metadata. Automatically injected when the tool is called within a traced operation."
|
|
95
|
+
}]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
parameters: [{
|
|
99
|
+
name: "abortSignal",
|
|
100
|
+
type: "AbortSignal",
|
|
101
|
+
isOptional: true,
|
|
102
|
+
description: "Signal for aborting the tool execution"
|
|
103
|
+
}]
|
|
104
|
+
}
|
|
105
|
+
]
|
|
73
106
|
},
|
|
74
107
|
]}
|
|
75
108
|
/>
|
|
@@ -48,6 +48,38 @@ if (result.status === "suspended") {
|
|
|
48
48
|
description: "Optional run count for nested workflow execution",
|
|
49
49
|
isOptional: true,
|
|
50
50
|
},
|
|
51
|
+
{
|
|
52
|
+
name: "tracingContext",
|
|
53
|
+
type: "TracingContext",
|
|
54
|
+
isOptional: true,
|
|
55
|
+
description: "AI tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
56
|
+
properties: [
|
|
57
|
+
{
|
|
58
|
+
parameters: [{
|
|
59
|
+
name: "currentSpan",
|
|
60
|
+
type: "AISpan",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
description: "Current AI span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution."
|
|
63
|
+
}]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "tracingOptions",
|
|
69
|
+
type: "TracingOptions",
|
|
70
|
+
isOptional: true,
|
|
71
|
+
description: "Options for AI tracing configuration.",
|
|
72
|
+
properties: [
|
|
73
|
+
{
|
|
74
|
+
parameters: [{
|
|
75
|
+
name: "metadata",
|
|
76
|
+
type: "Record<string, any>",
|
|
77
|
+
isOptional: true,
|
|
78
|
+
description: "Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags."
|
|
79
|
+
}]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
51
83
|
]}
|
|
52
84
|
/>
|
|
53
85
|
|
|
@@ -60,6 +92,12 @@ if (result.status === "suspended") {
|
|
|
60
92
|
type: "Promise<WorkflowResult<TOutput, TSteps>>",
|
|
61
93
|
description: "A promise that resolves to the workflow execution result containing step outputs and status",
|
|
62
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: "traceId",
|
|
97
|
+
type: "string",
|
|
98
|
+
isOptional: true,
|
|
99
|
+
description: "The trace ID associated with this execution when AI tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
100
|
+
},
|
|
63
101
|
]}
|
|
64
102
|
/>
|
|
65
103
|
|
|
@@ -41,6 +41,38 @@ const result = await run.start({
|
|
|
41
41
|
description: "Optional writable stream for streaming workflow output",
|
|
42
42
|
isOptional: true,
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
name: "tracingContext",
|
|
46
|
+
type: "TracingContext",
|
|
47
|
+
isOptional: true,
|
|
48
|
+
description: "AI tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
49
|
+
properties: [
|
|
50
|
+
{
|
|
51
|
+
parameters: [{
|
|
52
|
+
name: "currentSpan",
|
|
53
|
+
type: "AISpan",
|
|
54
|
+
isOptional: true,
|
|
55
|
+
description: "Current AI span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution."
|
|
56
|
+
}]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "tracingOptions",
|
|
62
|
+
type: "TracingOptions",
|
|
63
|
+
isOptional: true,
|
|
64
|
+
description: "Options for AI tracing configuration.",
|
|
65
|
+
properties: [
|
|
66
|
+
{
|
|
67
|
+
parameters: [{
|
|
68
|
+
name: "metadata",
|
|
69
|
+
type: "Record<string, any>",
|
|
70
|
+
isOptional: true,
|
|
71
|
+
description: "Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags."
|
|
72
|
+
}]
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
},
|
|
44
76
|
]}
|
|
45
77
|
/>
|
|
46
78
|
|
|
@@ -53,6 +85,12 @@ const result = await run.start({
|
|
|
53
85
|
type: "Promise<WorkflowResult<TOutput, TSteps>>",
|
|
54
86
|
description: "A promise that resolves to the workflow execution result containing step outputs and status",
|
|
55
87
|
},
|
|
88
|
+
{
|
|
89
|
+
name: "traceId",
|
|
90
|
+
type: "string",
|
|
91
|
+
isOptional: true,
|
|
92
|
+
description: "The trace ID associated with this execution when AI tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
93
|
+
},
|
|
56
94
|
]}
|
|
57
95
|
/>
|
|
58
96
|
|
|
@@ -31,7 +31,7 @@ You can mix and match approaches within a single scorer - for example, use a fun
|
|
|
31
31
|
|
|
32
32
|
### Initializing a Scorer
|
|
33
33
|
|
|
34
|
-
Every scorer starts with the `createScorer` factory function, which requires a name and description, and optionally accepts a
|
|
34
|
+
Every scorer starts with the `createScorer` factory function, which requires a name and description, and optionally accepts a type specification and judge configuration.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { createScorer } from '@mastra/core/scores';
|
|
@@ -54,6 +54,21 @@ const glutenCheckerScorer = createScorer({
|
|
|
54
54
|
|
|
55
55
|
The judge configuration is only needed if you plan to use prompt objects in any step. Individual steps can override this default configuration with their own judge settings.
|
|
56
56
|
|
|
57
|
+
#### Agent Type for Agent Evaluation
|
|
58
|
+
|
|
59
|
+
For type safety and compatibility with both live agent scoring and trace scoring, use `type: 'agent'` when creating scorers for agent evaluation. This allows you to use the same scorer for an agent and also use it to score traces:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const myScorer = createScorer({
|
|
63
|
+
// ...
|
|
64
|
+
type: 'agent', // Automatically handles agent input/output types
|
|
65
|
+
})
|
|
66
|
+
.generateScore(({ run, results }) => {
|
|
67
|
+
// run.output is automatically typed as ScorerRunOutputForAgent
|
|
68
|
+
// run.input is automatically typed as ScorerRunInputForAgent
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
57
72
|
### Step-by-Step Breakdown
|
|
58
73
|
|
|
59
74
|
#### preprocess Step (Optional)
|