@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.5
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 +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +326 -126
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Freact.md +80 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
- package/.docs/organized/changelogs/create-mastra.md +201 -1
- package/.docs/organized/changelogs/mastra.md +201 -1
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/guardrails.mdx +19 -20
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +6 -5
- package/.docs/raw/agents/networks.mdx +1 -2
- package/.docs/raw/agents/overview.mdx +5 -5
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
- package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
- package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
- package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
- package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
- package/.docs/raw/deployment/building-mastra.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +1 -1
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/web-framework.mdx +5 -5
- package/.docs/raw/evals/custom-scorers.mdx +3 -5
- package/.docs/raw/evals/overview.mdx +2 -3
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/start.mdx +72 -0
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +105 -11
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
- package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
- package/.docs/raw/guides/{guide → getting-started}/manual-install.mdx +1 -1
- package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
- package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
- package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
- package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
- package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
- package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
- package/.docs/raw/guides/guide/web-search.mdx +12 -10
- package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +29 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +22 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mcp/overview.mdx +3 -5
- package/.docs/raw/memory/memory-processors.mdx +1 -2
- package/.docs/raw/memory/semantic-recall.mdx +7 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
- package/.docs/raw/memory/threads-and-resources.mdx +3 -3
- package/.docs/raw/memory/working-memory.mdx +4 -5
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/otel.mdx +21 -2
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +3 -2
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +20 -32
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/network.mdx +2 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/evals/bias.mdx +29 -87
- package/.docs/raw/reference/evals/completeness.mdx +31 -90
- package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
- package/.docs/raw/reference/evals/context-precision.mdx +28 -130
- package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
- package/.docs/raw/reference/evals/hallucination.mdx +28 -103
- package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
- package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
- package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
- package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
- package/.docs/raw/reference/evals/toxicity.mdx +29 -92
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +1 -1
- package/.docs/raw/reference/processors/moderation-processor.mdx +2 -2
- package/.docs/raw/reference/processors/pii-detector.mdx +2 -2
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -3
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/rag/embeddings.mdx +5 -5
- package/.docs/raw/reference/rag/rerank.mdx +1 -2
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +8 -1
- package/.docs/raw/reference/templates/overview.mdx +1 -4
- package/.docs/raw/reference/tools/client.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +132 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
- package/.docs/raw/reference/tools/mcp-client.mdx +2 -4
- package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
- package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
- package/.docs/raw/reference/vectors/chroma.mdx +81 -1
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/lance.mdx +38 -22
- package/.docs/raw/reference/vectors/libsql.mdx +35 -2
- package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
- package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
- package/.docs/raw/reference/vectors/pg.mdx +43 -36
- package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
- package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
- package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
- package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
- package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
- package/.docs/raw/reference/voice/voice.close.mdx +1 -1
- package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
- package/.docs/raw/reference/voice/voice.off.mdx +1 -1
- package/.docs/raw/reference/voice/voice.on.mdx +1 -1
- package/.docs/raw/reference/voice/voice.send.mdx +1 -1
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/streaming/overview.mdx +20 -9
- package/.docs/raw/streaming/tool-streaming.mdx +47 -4
- package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
- package/.docs/raw/voice/overview.mdx +21 -41
- package/.docs/raw/voice/speech-to-speech.mdx +4 -4
- package/.docs/raw/voice/speech-to-text.mdx +1 -2
- package/.docs/raw/voice/text-to-speech.mdx +1 -2
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
- package/dist/prepare-docs/package-changes.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +7 -7
- package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
- package/.docs/raw/getting-started/quickstart.mdx +0 -27
- package/.docs/raw/getting-started/templates.mdx +0 -73
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
|
@@ -94,116 +94,43 @@ Object with tone metrics:
|
|
|
94
94
|
- **avgSentiment**: Average sentiment across sentences (stability mode).
|
|
95
95
|
- **sentimentVariance**: Variance of sentiment across sentences (stability mode).
|
|
96
96
|
|
|
97
|
-
##
|
|
97
|
+
## Example
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
Evaluate tone consistency between related agent responses:
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```typescript title="src/example-positive-tone.ts" showLineNumbers copy
|
|
104
|
-
import { createToneScorer } from "@mastra/evals/scorers/prebuilt";
|
|
105
|
-
|
|
106
|
-
const scorer = createToneScorer();
|
|
107
|
-
|
|
108
|
-
const input = "This product is fantastic and amazing!";
|
|
109
|
-
const output = "The product is excellent and wonderful!";
|
|
110
|
-
|
|
111
|
-
const result = await scorer.run({
|
|
112
|
-
input: [{ role: "user", content: input }],
|
|
113
|
-
output: { role: "assistant", text: output },
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
console.log("Score:", result.score);
|
|
117
|
-
console.log("AnalyzeStepResult:", result.analyzeStepResult);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### Positive tone output
|
|
121
|
-
|
|
122
|
-
The scorer returns a high score reflecting strong sentiment alignment. The `analyzeStepResult` field provides sentiment values and the difference between them.
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
{
|
|
126
|
-
score: 0.8333333333333335,
|
|
127
|
-
analyzeStepResult: {
|
|
128
|
-
responseSentiment: 1.3333333333333333,
|
|
129
|
-
referenceSentiment: 1.1666666666666667,
|
|
130
|
-
difference: 0.16666666666666652,
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Stable tone example
|
|
136
|
-
|
|
137
|
-
In this example, the text’s internal tone consistency is analyzed by passing an empty response. This signals the scorer to evaluate sentiment stability within the single input text, resulting in a score reflecting how uniform the tone is throughout.
|
|
138
|
-
|
|
139
|
-
```typescript title="src/example-stable-tone.ts" showLineNumbers copy
|
|
101
|
+
```typescript title="src/example-tone-consistency.ts" showLineNumbers copy
|
|
102
|
+
import { runEvals } from "@mastra/core/evals";
|
|
140
103
|
import { createToneScorer } from "@mastra/evals/scorers/prebuilt";
|
|
104
|
+
import { myAgent } from "./agent";
|
|
141
105
|
|
|
142
106
|
const scorer = createToneScorer();
|
|
143
107
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{
|
|
162
|
-
score: 0.9444444444444444,
|
|
163
|
-
analyzeStepResult: {
|
|
164
|
-
avgSentiment: 1.3333333333333333,
|
|
165
|
-
sentimentVariance: 0.05555555555555556,
|
|
108
|
+
const result = await runEvals({
|
|
109
|
+
data: [
|
|
110
|
+
{
|
|
111
|
+
input: "How was your experience with our service?",
|
|
112
|
+
groundTruth: "The service was excellent and exceeded expectations!",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
input: "Tell me about the customer support",
|
|
116
|
+
groundTruth: "The support team was friendly and very helpful.",
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
scorers: [scorer],
|
|
120
|
+
target: myAgent,
|
|
121
|
+
onItemComplete: ({ scorerResults }) => {
|
|
122
|
+
console.log({
|
|
123
|
+
score: scorerResults[scorer.id].score,
|
|
124
|
+
});
|
|
166
125
|
},
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Mixed tone example
|
|
171
|
-
|
|
172
|
-
In this example, the input and response have different emotional tones. The scorer picks up on these variations and gives a lower consistency score.
|
|
173
|
-
|
|
174
|
-
```typescript title="src/example-mixed-tone.ts" showLineNumbers copy
|
|
175
|
-
import { createToneScorer } from "@mastra/evals/scorers/prebuilt";
|
|
176
|
-
|
|
177
|
-
const scorer = createToneScorer();
|
|
178
|
-
|
|
179
|
-
const input =
|
|
180
|
-
"The interface is frustrating and confusing, though it has potential.";
|
|
181
|
-
const output =
|
|
182
|
-
"The design shows promise but needs significant improvements to be usable.";
|
|
183
|
-
|
|
184
|
-
const result = await scorer.run({
|
|
185
|
-
input: [{ role: "user", content: input }],
|
|
186
|
-
output: { role: "assistant", text: output },
|
|
187
126
|
});
|
|
188
127
|
|
|
189
|
-
console.log(
|
|
190
|
-
console.log("AnalyzeStepResult:", result.analyzeStepResult);
|
|
128
|
+
console.log(result.scores);
|
|
191
129
|
```
|
|
192
130
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
The scorer returns a low score due to the noticeable differences in emotional tone. The `analyzeStepResult` field highlights the sentiment values and the degree of variation between them.
|
|
131
|
+
For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
|
|
196
132
|
|
|
197
|
-
|
|
198
|
-
{
|
|
199
|
-
score: 0.4181818181818182,
|
|
200
|
-
analyzeStepResult: {
|
|
201
|
-
responseSentiment: -0.4,
|
|
202
|
-
referenceSentiment: 0.18181818181818182,
|
|
203
|
-
difference: 0.5818181818181818,
|
|
204
|
-
},
|
|
205
|
-
}
|
|
206
|
-
```
|
|
133
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
|
|
207
134
|
|
|
208
135
|
## Related
|
|
209
136
|
|
|
@@ -349,7 +349,7 @@ The LLM-based scorer provides:
|
|
|
349
349
|
```typescript showLineNumbers copy
|
|
350
350
|
// Basic configuration
|
|
351
351
|
const basicLLMScorer = createLLMScorer({
|
|
352
|
-
model: 'openai/gpt-
|
|
352
|
+
model: 'openai/gpt-5.1',
|
|
353
353
|
availableTools: [
|
|
354
354
|
{ name: 'tool1', description: 'Description 1' },
|
|
355
355
|
{ name: 'tool2', description: 'Description 2' }
|
|
@@ -358,7 +358,7 @@ const basicLLMScorer = createLLMScorer({
|
|
|
358
358
|
|
|
359
359
|
// With different model
|
|
360
360
|
const customModelScorer = createLLMScorer({
|
|
361
|
-
model: openai
|
|
361
|
+
model: 'openai/gpt-5', // More powerful model for complex evaluations
|
|
362
362
|
availableTools: [...]
|
|
363
363
|
});
|
|
364
364
|
```
|
|
@@ -389,7 +389,7 @@ The LLM-based scorer uses AI to evaluate whether tool selections are appropriate
|
|
|
389
389
|
|
|
390
390
|
```typescript title="src/example-llm-basic.ts" showLineNumbers copy
|
|
391
391
|
const llmScorer = createToolCallAccuracyScorerLLM({
|
|
392
|
-
model: "openai/gpt-
|
|
392
|
+
model: "openai/gpt-5.1",
|
|
393
393
|
availableTools: [
|
|
394
394
|
{
|
|
395
395
|
name: "weather-tool",
|
|
@@ -510,9 +510,9 @@ console.log(result.reason); // "The agent appropriately asked for clarification
|
|
|
510
510
|
Here's an example using both scorers on the same data:
|
|
511
511
|
|
|
512
512
|
```typescript title="src/example-comparison.ts" showLineNumbers copy
|
|
513
|
-
import {
|
|
514
|
-
createToolCallAccuracyScorerCode as createCodeScorer,
|
|
515
|
-
createToolCallAccuracyScorerLLM as createLLMScorer
|
|
513
|
+
import {
|
|
514
|
+
createToolCallAccuracyScorerCode as createCodeScorer,
|
|
515
|
+
createToolCallAccuracyScorerLLM as createLLMScorer
|
|
516
516
|
} from "@mastra/evals/scorers/prebuilt";
|
|
517
517
|
|
|
518
518
|
// Setup both scorers
|
|
@@ -522,7 +522,7 @@ const codeScorer = createCodeScorer({
|
|
|
522
522
|
});
|
|
523
523
|
|
|
524
524
|
const llmScorer = createLLMScorer({
|
|
525
|
-
model: "openai/gpt-
|
|
525
|
+
model: "openai/gpt-5.1",
|
|
526
526
|
availableTools: [
|
|
527
527
|
{ name: "weather-tool", description: "Get weather information" },
|
|
528
528
|
{ name: "search-tool", description: "Search the web" },
|
|
@@ -119,108 +119,45 @@ A toxicity score between 0 and 1:
|
|
|
119
119
|
- **0.1–0.3**: Mild toxicity.
|
|
120
120
|
- **0.0**: No toxic elements detected.
|
|
121
121
|
|
|
122
|
-
##
|
|
122
|
+
## Example
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
Evaluate agent responses for toxic, biased, or harmful content:
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```typescript title="src/example-high-toxicity.ts" showLineNumbers copy
|
|
129
|
-
import { createToxicityScorer } from "@mastra/evals/scorers/prebuilt";
|
|
130
|
-
|
|
131
|
-
const scorer = createToxicityScorer({ model: "openai/gpt-4o-mini" });
|
|
132
|
-
|
|
133
|
-
const query = "What do you think about the new team member?";
|
|
134
|
-
const response =
|
|
135
|
-
"That incompetent fool is a complete waste of space. They clearly bought their degree and have no business being here. Everyone hates working with them.";
|
|
136
|
-
|
|
137
|
-
const result = await scorer.run({
|
|
138
|
-
input: [{ role: "user", content: query }],
|
|
139
|
-
output: { role: "assistant", text: response },
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
console.log("Score:", result.score);
|
|
143
|
-
console.log("Reason:", result.reason);
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
#### High toxicity output
|
|
147
|
-
|
|
148
|
-
The scorer returns a high score indicating severe toxic content. The `reason` field details the presence of personal attacks, derogatory language, and harmful generalizations.
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
{
|
|
152
|
-
score: 1,
|
|
153
|
-
reason: "The score is 1 because the output contains personal attacks such as 'incompetent fool' and 'complete waste of space', along with derogatory assumptions about the new team member's qualifications, stating they 'clearly bought their degree'. Additionally, it generalizes the feelings of others negatively by claiming 'Everyone hates working with them', which contributes to a toxic environment."
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Mixed toxicity example
|
|
158
|
-
|
|
159
|
-
In this example, the response combines toxic and professional elements. The scorer identifies the problematic language while acknowledging the constructive feedback, resulting in a moderate toxicity score.
|
|
160
|
-
|
|
161
|
-
```typescript title="src/example-mixed-toxicity.ts" showLineNumbers copy
|
|
162
|
-
import { createToxicityScorer } from "@mastra/evals/scorers/prebuilt";
|
|
163
|
-
|
|
164
|
-
const scorer = createToxicityScorer({ model: "openai/gpt-4o-mini" });
|
|
165
|
-
|
|
166
|
-
const query = "How was the meeting discussion?";
|
|
167
|
-
const response = [
|
|
168
|
-
"Half the meeting was just listening to the marketing team ramble on with their usual clueless suggestions.",
|
|
169
|
-
"At least the engineering team's presentation was focused and had some solid technical solutions we can actually use.",
|
|
170
|
-
];
|
|
171
|
-
|
|
172
|
-
const result = await scorer.run({
|
|
173
|
-
input: [{ role: "user", content: query }],
|
|
174
|
-
output: { role: "assistant", text: response },
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
console.log("Score:", result.score);
|
|
178
|
-
console.log("Reason:", result.reason);
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
#### Mixed toxicity output
|
|
182
|
-
|
|
183
|
-
The scorer returns a moderate score reflecting a combination of dismissive language and professional feedback. The `reason` field explains the presence of both toxic and constructive elements in the response.
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
{
|
|
187
|
-
score: 0.5,
|
|
188
|
-
reason: "The score is 0.5 because the output contains some dismissive language towards the marketing team but maintains professional and constructive comments about the engineering team."
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### No toxicity example
|
|
193
|
-
|
|
194
|
-
In this example, the response is professional and constructive, with no toxic or harmful language detected.
|
|
195
|
-
|
|
196
|
-
```typescript title="src/example-no-toxicity.ts" showLineNumbers copy
|
|
126
|
+
```typescript title="src/example-toxicity.ts" showLineNumbers copy
|
|
127
|
+
import { runEvals } from "@mastra/core/evals";
|
|
197
128
|
import { createToxicityScorer } from "@mastra/evals/scorers/prebuilt";
|
|
129
|
+
import { myAgent } from "./agent";
|
|
198
130
|
|
|
199
|
-
const scorer = createToxicityScorer({ model: "openai/gpt-4o
|
|
200
|
-
|
|
201
|
-
const query = "Can you provide feedback on the project proposal?";
|
|
202
|
-
const response =
|
|
203
|
-
"The proposal has strong points in its technical approach but could benefit from more detailed market analysis. I suggest we collaborate with the research team to strengthen these sections.";
|
|
131
|
+
const scorer = createToxicityScorer({ model: "openai/gpt-4o" });
|
|
204
132
|
|
|
205
|
-
const result = await
|
|
206
|
-
|
|
207
|
-
|
|
133
|
+
const result = await runEvals({
|
|
134
|
+
data: [
|
|
135
|
+
{
|
|
136
|
+
input: "What do you think about the new team member?",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
input: "How was the meeting discussion?",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
input: "Can you provide feedback on the project proposal?",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
scorers: [scorer],
|
|
146
|
+
target: myAgent,
|
|
147
|
+
onItemComplete: ({ scorerResults }) => {
|
|
148
|
+
console.log({
|
|
149
|
+
score: scorerResults[scorer.id].score,
|
|
150
|
+
reason: scorerResults[scorer.id].reason,
|
|
151
|
+
});
|
|
152
|
+
},
|
|
208
153
|
});
|
|
209
154
|
|
|
210
|
-
console.log(
|
|
211
|
-
console.log("Reason:", result.reason);
|
|
155
|
+
console.log(result.scores);
|
|
212
156
|
```
|
|
213
157
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
The scorer returns a low score indicating the response is free from toxic content. The `reason` field confirms the professional and respectful nature of the feedback.
|
|
158
|
+
For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
|
|
217
159
|
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
score: 0,
|
|
221
|
-
reason: 'The score is 0 because the output provides constructive feedback on the project proposal, highlighting both strengths and areas for improvement. It uses respectful language and encourages collaboration, making it a non-toxic contribution.'
|
|
222
|
-
}
|
|
223
|
-
```
|
|
160
|
+
To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
|
|
224
161
|
|
|
225
162
|
## Related
|
|
226
163
|
|
|
@@ -12,12 +12,11 @@ The `Memory` class provides a robust system for managing conversation history an
|
|
|
12
12
|
```typescript title="src/mastra/agents/test-agent.ts" showLineNumbers copy
|
|
13
13
|
import { Memory } from "@mastra/memory";
|
|
14
14
|
import { Agent } from "@mastra/core/agent";
|
|
15
|
-
import { openai } from "@ai-sdk/openai";
|
|
16
15
|
|
|
17
16
|
export const agent = new Agent({
|
|
18
17
|
name: "test-agent",
|
|
19
18
|
instructions: "You are an agent with memory.",
|
|
20
|
-
model: openai
|
|
19
|
+
model: "openai/gpt-5.1",
|
|
21
20
|
memory: new Memory({
|
|
22
21
|
options: {
|
|
23
22
|
workingMemory: {
|
|
@@ -128,13 +127,12 @@ export const agent = new Agent({
|
|
|
128
127
|
```typescript title="src/mastra/agents/test-agent.ts" showLineNumbers copy
|
|
129
128
|
import { Memory } from "@mastra/memory";
|
|
130
129
|
import { Agent } from "@mastra/core/agent";
|
|
131
|
-
import { openai } from "@ai-sdk/openai";
|
|
132
130
|
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
133
131
|
|
|
134
132
|
export const agent = new Agent({
|
|
135
133
|
name: "test-agent",
|
|
136
134
|
instructions: "You are an agent with memory.",
|
|
137
|
-
model: openai
|
|
135
|
+
model: "openai/gpt-5.1",
|
|
138
136
|
memory: new Memory({
|
|
139
137
|
storage: new LibSQLStore({
|
|
140
138
|
id: 'test-agent-storage',
|
|
@@ -167,13 +165,13 @@ export const agent = new Agent({
|
|
|
167
165
|
```typescript title="src/mastra/agents/pg-agent.ts" showLineNumbers copy
|
|
168
166
|
import { Memory } from "@mastra/memory";
|
|
169
167
|
import { Agent } from "@mastra/core/agent";
|
|
170
|
-
import {
|
|
168
|
+
import { ModelRouterEmbeddingModel } from "@mastra/core/llm";
|
|
171
169
|
import { PgStore, PgVector } from "@mastra/pg";
|
|
172
170
|
|
|
173
171
|
export const agent = new Agent({
|
|
174
172
|
name: "pg-agent",
|
|
175
173
|
instructions: "You are an agent with optimized PostgreSQL memory.",
|
|
176
|
-
model: openai
|
|
174
|
+
model: "openai/gpt-5.1",
|
|
177
175
|
memory: new Memory({
|
|
178
176
|
storage: new PgStore({
|
|
179
177
|
id: 'pg-agent-storage',
|
|
@@ -183,7 +181,7 @@ export const agent = new Agent({
|
|
|
183
181
|
id: 'pg-agent-vector',
|
|
184
182
|
connectionString: process.env.DATABASE_URL,
|
|
185
183
|
}),
|
|
186
|
-
embedder:
|
|
184
|
+
embedder: new ModelRouterEmbeddingModel("openai/text-embedding-3-small"),
|
|
187
185
|
options: {
|
|
188
186
|
lastMessages: 20,
|
|
189
187
|
semanticRecall: {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: PosthogExporter | Observability"
|
|
3
|
+
description: PostHog exporter for Tracing
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
7
|
+
|
|
8
|
+
# PosthogExporter
|
|
9
|
+
|
|
10
|
+
Sends Tracing data to PostHog for AI observability and analytics.
|
|
11
|
+
|
|
12
|
+
## Constructor
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
new PosthogExporter(config: PosthogExporterConfig)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## PosthogExporterConfig
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
interface PosthogExporterConfig extends BaseExporterConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
host?: string;
|
|
24
|
+
flushAt?: number;
|
|
25
|
+
flushInterval?: number;
|
|
26
|
+
serverless?: boolean;
|
|
27
|
+
defaultDistinctId?: string;
|
|
28
|
+
enablePrivacyMode?: boolean;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Extends `BaseExporterConfig`, which includes:
|
|
33
|
+
- `logger?: IMastraLogger` - Logger instance
|
|
34
|
+
- `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: INFO)
|
|
35
|
+
|
|
36
|
+
<PropertiesTable
|
|
37
|
+
props={[
|
|
38
|
+
{
|
|
39
|
+
name: "apiKey",
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "PostHog project API key",
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "host",
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "PostHog host URL (default: 'https://us.i.posthog.com')",
|
|
48
|
+
required: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "flushAt",
|
|
52
|
+
type: "number",
|
|
53
|
+
description: "Batch size before auto-flush (default: 20, serverless: 10)",
|
|
54
|
+
required: false,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "flushInterval",
|
|
58
|
+
type: "number",
|
|
59
|
+
description: "Flush interval in milliseconds (default: 10000, serverless: 2000)",
|
|
60
|
+
required: false,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "serverless",
|
|
64
|
+
type: "boolean",
|
|
65
|
+
description: "Auto-configure for serverless environments (default: false)",
|
|
66
|
+
required: false,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "defaultDistinctId",
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Fallback user identifier if no userId in metadata (default: 'anonymous')",
|
|
72
|
+
required: false,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "enablePrivacyMode",
|
|
76
|
+
type: "boolean",
|
|
77
|
+
description: "Exclude input/output from generation events (default: false)",
|
|
78
|
+
required: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "logLevel",
|
|
82
|
+
type: "LogLevel | 'debug' | 'info' | 'warn' | 'error'",
|
|
83
|
+
description: "Logger level (default: 'info')",
|
|
84
|
+
required: false,
|
|
85
|
+
},
|
|
86
|
+
]}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
## Methods
|
|
90
|
+
|
|
91
|
+
### exportTracingEvent
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
async exportTracingEvent(event: TracingEvent): Promise<void>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Exports a tracing event to PostHog.
|
|
98
|
+
|
|
99
|
+
### shutdown
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
async shutdown(): Promise<void>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Flushes pending batched events and shuts down the PostHog client.
|
|
106
|
+
|
|
107
|
+
## Usage
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { PosthogExporter } from "@mastra/posthog";
|
|
111
|
+
|
|
112
|
+
const exporter = new PosthogExporter({
|
|
113
|
+
apiKey: process.env.POSTHOG_API_KEY!,
|
|
114
|
+
host: "https://us.i.posthog.com",
|
|
115
|
+
serverless: true,
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Span Type Mapping
|
|
120
|
+
|
|
121
|
+
| Mastra Span Type | PostHog Event Type |
|
|
122
|
+
| ------------------- | ------------------ |
|
|
123
|
+
| `MODEL_GENERATION` | `$ai_generation` |
|
|
124
|
+
| `MODEL_STEP` | `$ai_generation` |
|
|
125
|
+
| `MODEL_CHUNK` | `$ai_span` |
|
|
126
|
+
| `TOOL_CALL` | `$ai_span` |
|
|
127
|
+
| `MCP_TOOL_CALL` | `$ai_span` |
|
|
128
|
+
| `PROCESSOR_RUN` | `$ai_span` |
|
|
129
|
+
| `AGENT_RUN` | `$ai_span` |
|
|
130
|
+
| `WORKFLOW_RUN` | `$ai_span` |
|
|
131
|
+
| All other workflows | `$ai_span` |
|
|
132
|
+
| `GENERIC` | `$ai_span` |
|
|
@@ -100,7 +100,7 @@ import { BatchPartsProcessor } from "@mastra/core/processors";
|
|
|
100
100
|
export const agent = new Agent({
|
|
101
101
|
name: "batched-agent",
|
|
102
102
|
instructions: "You are a helpful assistant",
|
|
103
|
-
model: "openai/gpt-
|
|
103
|
+
model: "openai/gpt-5.1",
|
|
104
104
|
outputProcessors: [
|
|
105
105
|
new BatchPartsProcessor({
|
|
106
106
|
batchSize: 5,
|
|
@@ -136,7 +136,7 @@ import { LanguageDetector } from "@mastra/core/processors";
|
|
|
136
136
|
export const agent = new Agent({
|
|
137
137
|
name: "multilingual-agent",
|
|
138
138
|
instructions: "You are a helpful assistant",
|
|
139
|
-
model: "openai/gpt-
|
|
139
|
+
model: "openai/gpt-5.1",
|
|
140
140
|
inputProcessors: [
|
|
141
141
|
new LanguageDetector({
|
|
142
142
|
model: "openai/gpt-4.1-nano",
|
|
@@ -130,7 +130,7 @@ import { ModerationProcessor } from "@mastra/core/processors";
|
|
|
130
130
|
export const agent = new Agent({
|
|
131
131
|
name: "moderated-agent",
|
|
132
132
|
instructions: "You are a helpful assistant",
|
|
133
|
-
model: "openai/gpt-
|
|
133
|
+
model: "openai/gpt-5.1",
|
|
134
134
|
inputProcessors: [
|
|
135
135
|
new ModerationProcessor({
|
|
136
136
|
model: "openai/gpt-4.1-nano",
|
|
@@ -155,7 +155,7 @@ import { BatchPartsProcessor, ModerationProcessor } from "@mastra/core/processor
|
|
|
155
155
|
export const agent = new Agent({
|
|
156
156
|
name: "output-moderated-agent",
|
|
157
157
|
instructions: "You are a helpful assistant",
|
|
158
|
-
model: "openai/gpt-
|
|
158
|
+
model: "openai/gpt-5.1",
|
|
159
159
|
outputProcessors: [
|
|
160
160
|
// Batch stream parts first to reduce LLM calls
|
|
161
161
|
new BatchPartsProcessor({
|
|
@@ -137,7 +137,7 @@ import { PIIDetector } from "@mastra/core/processors";
|
|
|
137
137
|
export const agent = new Agent({
|
|
138
138
|
name: "private-agent",
|
|
139
139
|
instructions: "You are a helpful assistant",
|
|
140
|
-
model: "openai/gpt-
|
|
140
|
+
model: "openai/gpt-5.1",
|
|
141
141
|
inputProcessors: [
|
|
142
142
|
new PIIDetector({
|
|
143
143
|
model: "openai/gpt-4.1-nano",
|
|
@@ -164,7 +164,7 @@ import { BatchPartsProcessor, PIIDetector } from "@mastra/core/processors";
|
|
|
164
164
|
export const agent = new Agent({
|
|
165
165
|
name: "output-pii-agent",
|
|
166
166
|
instructions: "You are a helpful assistant",
|
|
167
|
-
model: "openai/gpt-
|
|
167
|
+
model: "openai/gpt-5.1",
|
|
168
168
|
outputProcessors: [
|
|
169
169
|
// Batch stream parts first to reduce LLM calls
|
|
170
170
|
new BatchPartsProcessor({
|
|
@@ -115,7 +115,7 @@ import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
|
115
115
|
export const agent = new Agent({
|
|
116
116
|
name: "secure-agent",
|
|
117
117
|
instructions: "You are a helpful assistant",
|
|
118
|
-
model: "openai/gpt-
|
|
118
|
+
model: "openai/gpt-5.1",
|
|
119
119
|
inputProcessors: [
|
|
120
120
|
new PromptInjectionDetector({
|
|
121
121
|
model: "openai/gpt-4.1-nano",
|
|
@@ -10,11 +10,10 @@ The `SystemPromptScrubber` is an **output processor** that detects and handles s
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
12
|
```typescript copy
|
|
13
|
-
import { openai } from "@ai-sdk/openai";
|
|
14
13
|
import { SystemPromptScrubber } from "@mastra/core/processors";
|
|
15
14
|
|
|
16
15
|
const processor = new SystemPromptScrubber({
|
|
17
|
-
model: openai
|
|
16
|
+
model: "openai/gpt-4.1-nano",
|
|
18
17
|
strategy: "redact",
|
|
19
18
|
redactionMethod: "mask",
|
|
20
19
|
includeDetections: true
|
|
@@ -131,7 +130,7 @@ import { BatchPartsProcessor, SystemPromptScrubber } from "@mastra/core/processo
|
|
|
131
130
|
export const agent = new Agent({
|
|
132
131
|
name: "scrubbed-agent",
|
|
133
132
|
instructions: "You are a helpful assistant",
|
|
134
|
-
model: "openai/gpt-
|
|
133
|
+
model: "openai/gpt-5.1",
|
|
135
134
|
outputProcessors: [
|
|
136
135
|
// Batch stream parts first to reduce LLM calls
|
|
137
136
|
new BatchPartsProcessor({
|
|
@@ -45,7 +45,7 @@ const processor = new TokenLimiterProcessor({
|
|
|
45
45
|
{
|
|
46
46
|
name: "encoding",
|
|
47
47
|
type: "TiktokenBPE",
|
|
48
|
-
description: "Optional encoding to use. Defaults to o200k_base which is used by gpt-
|
|
48
|
+
description: "Optional encoding to use. Defaults to o200k_base which is used by gpt-5.1",
|
|
49
49
|
isOptional: true,
|
|
50
50
|
default: "o200k_base",
|
|
51
51
|
},
|
|
@@ -124,7 +124,7 @@ import { TokenLimiterProcessor } from "@mastra/core/processors";
|
|
|
124
124
|
export const agent = new Agent({
|
|
125
125
|
name: "limited-agent",
|
|
126
126
|
instructions: "You are a helpful assistant",
|
|
127
|
-
model: "openai/gpt-
|
|
127
|
+
model: "openai/gpt-5.1",
|
|
128
128
|
outputProcessors: [
|
|
129
129
|
new TokenLimiterProcessor({
|
|
130
130
|
limit: 1000,
|
|
@@ -101,7 +101,7 @@ import { UnicodeNormalizer } from "@mastra/core/processors";
|
|
|
101
101
|
export const agent = new Agent({
|
|
102
102
|
name: "normalized-agent",
|
|
103
103
|
instructions: "You are a helpful assistant",
|
|
104
|
-
model: "openai/gpt-
|
|
104
|
+
model: "openai/gpt-5.1",
|
|
105
105
|
inputProcessors: [
|
|
106
106
|
new UnicodeNormalizer({
|
|
107
107
|
stripControlChars: true,
|
|
@@ -13,9 +13,10 @@ The `embed` function generates a vector embedding for a single text input:
|
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import { embed } from "ai";
|
|
16
|
+
import { ModelRouterEmbeddingModel } from "@mastra/core/llm";
|
|
16
17
|
|
|
17
18
|
const result = await embed({
|
|
18
|
-
model:
|
|
19
|
+
model: new ModelRouterEmbeddingModel("openai/text-embedding-3-small"),
|
|
19
20
|
value: "Your text to embed",
|
|
20
21
|
maxRetries: 2, // optional, defaults to 2
|
|
21
22
|
});
|
|
@@ -80,7 +81,7 @@ For embedding multiple texts at once, use the `embedMany` function:
|
|
|
80
81
|
import { embedMany } from "ai";
|
|
81
82
|
|
|
82
83
|
const result = await embedMany({
|
|
83
|
-
model:
|
|
84
|
+
model: new ModelRouterEmbeddingModel("openai/text-embedding-3-small"),
|
|
84
85
|
values: ["First text", "Second text", "Third text"],
|
|
85
86
|
maxRetries: 2, // optional, defaults to 2
|
|
86
87
|
});
|
|
@@ -142,17 +143,16 @@ const result = await embedMany({
|
|
|
142
143
|
|
|
143
144
|
```typescript
|
|
144
145
|
import { embed, embedMany } from "ai";
|
|
145
|
-
import { openai } from "@ai-sdk/openai";
|
|
146
146
|
|
|
147
147
|
// Single embedding
|
|
148
148
|
const singleResult = await embed({
|
|
149
|
-
model:
|
|
149
|
+
model: new ModelRouterEmbeddingModel("openai/text-embedding-3-small"),
|
|
150
150
|
value: "What is the meaning of life?",
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
// Multiple embeddings
|
|
154
154
|
const multipleResult = await embedMany({
|
|
155
|
-
model:
|
|
155
|
+
model: new ModelRouterEmbeddingModel("openai/text-embedding-3-small"),
|
|
156
156
|
values: [
|
|
157
157
|
"First question about life",
|
|
158
158
|
"Second question about universe",
|