@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.6
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%2Fconvex.md +29 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +411 -211
- 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%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
- 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 +89 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +42 -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/agui.md +1 -0
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +26 -23
- package/.docs/raw/agents/networks.mdx +2 -2
- package/.docs/raw/agents/overview.mdx +27 -62
- package/.docs/raw/agents/processors.mdx +279 -0
- 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 +20 -27
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- 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/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/guide → getting-started}/manual-install.mdx +2 -2
- 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} +113 -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/{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/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- 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 +40 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +51 -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 +264 -79
- 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 +14 -7
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -3
- package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +25 -5
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +74 -8
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +43 -38
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- 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 +46 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- 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/deployer/netlify.mdx +1 -2
- 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/scorer-utils.mdx +362 -0
- 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/index.mdx +1 -0
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +10 -3
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +12 -5
- package/.docs/raw/reference/processors/pii-detector.mdx +12 -5
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +10 -3
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +3 -4
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- 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/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +64 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- 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 +76 -21
- 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/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- 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/google.mdx +159 -20
- 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/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run.mdx +13 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/server-db/mastra-server.mdx +30 -1
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +26 -15
- package/.docs/raw/streaming/tool-streaming.mdx +48 -5
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- 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/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +18 -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/agents/human-in-the-loop-with-tools.mdx +0 -90
- 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/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
- /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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Run.restart() | Workflows"
|
|
3
|
+
description: Documentation for the `Run.restart()` method in workflows, which restarts an active workflow run that lost connection to the server.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run.restart()
|
|
7
|
+
|
|
8
|
+
The `.restart()` method restarts an active workflow run that lost connection to the server, allowing you to continue execution from the moment it lost connection (the last active step).
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const run = await workflow.createRun();
|
|
14
|
+
|
|
15
|
+
const result = await run.start({ inputData: { value: "initial data" } });
|
|
16
|
+
|
|
17
|
+
//.. server connection lost,
|
|
18
|
+
|
|
19
|
+
const restartedResult = await run.restart();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
<PropertiesTable
|
|
25
|
+
content={[
|
|
26
|
+
{
|
|
27
|
+
name: "requestContext",
|
|
28
|
+
type: "RequestContext",
|
|
29
|
+
description: "Request Context data to use when resuming",
|
|
30
|
+
isOptional: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "tracingContext",
|
|
34
|
+
type: "TracingContext",
|
|
35
|
+
isOptional: true,
|
|
36
|
+
description:
|
|
37
|
+
"Tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.",
|
|
38
|
+
properties: [
|
|
39
|
+
{
|
|
40
|
+
parameters: [
|
|
41
|
+
{
|
|
42
|
+
name: "currentSpan",
|
|
43
|
+
type: "Span",
|
|
44
|
+
isOptional: true,
|
|
45
|
+
description:
|
|
46
|
+
"Current span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "tracingOptions",
|
|
54
|
+
type: "TracingOptions",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
description: "Options for Tracing configuration.",
|
|
57
|
+
properties: [
|
|
58
|
+
{
|
|
59
|
+
parameters: [
|
|
60
|
+
{
|
|
61
|
+
name: "metadata",
|
|
62
|
+
type: "Record<string, any>",
|
|
63
|
+
isOptional: true,
|
|
64
|
+
description:
|
|
65
|
+
"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
|
+
{
|
|
70
|
+
parameters: [
|
|
71
|
+
{
|
|
72
|
+
name: "requestContextKeys",
|
|
73
|
+
type: "string[]",
|
|
74
|
+
isOptional: true,
|
|
75
|
+
description:
|
|
76
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
parameters: [
|
|
82
|
+
{
|
|
83
|
+
name: "traceId",
|
|
84
|
+
type: "string",
|
|
85
|
+
isOptional: true,
|
|
86
|
+
description:
|
|
87
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
parameters: [
|
|
93
|
+
{
|
|
94
|
+
name: "parentSpanId",
|
|
95
|
+
type: "string",
|
|
96
|
+
isOptional: true,
|
|
97
|
+
description:
|
|
98
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
parameters: [
|
|
104
|
+
{
|
|
105
|
+
name: "tags",
|
|
106
|
+
type: "string[]",
|
|
107
|
+
isOptional: true,
|
|
108
|
+
description:
|
|
109
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
|
|
118
|
+
## Returns
|
|
119
|
+
|
|
120
|
+
<PropertiesTable
|
|
121
|
+
content={[
|
|
122
|
+
{
|
|
123
|
+
name: "result",
|
|
124
|
+
type: "Promise<WorkflowResult<TState, TOutput, TSteps>>",
|
|
125
|
+
description:
|
|
126
|
+
"A promise that resolves to the workflow execution result containing step outputs and status",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "traceId",
|
|
130
|
+
type: "string",
|
|
131
|
+
isOptional: true,
|
|
132
|
+
description:
|
|
133
|
+
"The trace ID associated with this execution when Tracing is enabled. Use this to correlate logs and debug execution flow.",
|
|
134
|
+
},
|
|
135
|
+
]}
|
|
136
|
+
/>
|
|
137
|
+
|
|
138
|
+
## Related
|
|
139
|
+
|
|
140
|
+
- [Workflows overview](/docs/v1/workflows/overview#running-workflows)
|
|
141
|
+
- [Restart workflows](/docs/v1/workflows/overview#restarting-active-workflow-runs)
|
|
142
|
+
- [Workflow.createRun()](../workflow-methods/create-run)
|
|
@@ -87,6 +87,50 @@ if (result.status === "suspended") {
|
|
|
87
87
|
},
|
|
88
88
|
],
|
|
89
89
|
},
|
|
90
|
+
{
|
|
91
|
+
parameters: [
|
|
92
|
+
{
|
|
93
|
+
name: "requestContextKeys",
|
|
94
|
+
type: "string[]",
|
|
95
|
+
isOptional: true,
|
|
96
|
+
description:
|
|
97
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
parameters: [
|
|
103
|
+
{
|
|
104
|
+
name: "traceId",
|
|
105
|
+
type: "string",
|
|
106
|
+
isOptional: true,
|
|
107
|
+
description:
|
|
108
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
parameters: [
|
|
114
|
+
{
|
|
115
|
+
name: "parentSpanId",
|
|
116
|
+
type: "string",
|
|
117
|
+
isOptional: true,
|
|
118
|
+
description:
|
|
119
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
parameters: [
|
|
125
|
+
{
|
|
126
|
+
name: "tags",
|
|
127
|
+
type: "string[]",
|
|
128
|
+
isOptional: true,
|
|
129
|
+
description:
|
|
130
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
90
134
|
],
|
|
91
135
|
},
|
|
92
136
|
{
|
|
@@ -78,6 +78,50 @@ const result = await run.start({
|
|
|
78
78
|
},
|
|
79
79
|
],
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
parameters: [
|
|
83
|
+
{
|
|
84
|
+
name: "requestContextKeys",
|
|
85
|
+
type: "string[]",
|
|
86
|
+
isOptional: true,
|
|
87
|
+
description:
|
|
88
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
parameters: [
|
|
94
|
+
{
|
|
95
|
+
name: "traceId",
|
|
96
|
+
type: "string",
|
|
97
|
+
isOptional: true,
|
|
98
|
+
description:
|
|
99
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
parameters: [
|
|
105
|
+
{
|
|
106
|
+
name: "parentSpanId",
|
|
107
|
+
type: "string",
|
|
108
|
+
isOptional: true,
|
|
109
|
+
description:
|
|
110
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
parameters: [
|
|
116
|
+
{
|
|
117
|
+
name: "tags",
|
|
118
|
+
type: "string[]",
|
|
119
|
+
isOptional: true,
|
|
120
|
+
description:
|
|
121
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
81
125
|
],
|
|
82
126
|
},
|
|
83
127
|
{
|
|
@@ -41,14 +41,14 @@ if (result.status === "suspended") {
|
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
name: "stream",
|
|
44
|
-
type: "(options?: StreamOptions) =>
|
|
45
|
-
description: "Monitors workflow execution as a stream of events",
|
|
44
|
+
type: "(options?: StreamOptions) => MastraWorkflowStream",
|
|
45
|
+
description: "Monitors workflow execution as a stream of events with enhanced streaming features",
|
|
46
46
|
required: true,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
name: "
|
|
50
|
-
type: "(options?:
|
|
51
|
-
description: "
|
|
49
|
+
name: "resumeStream",
|
|
50
|
+
type: "(options?: ResumeStreamOptions) => MastraWorkflowStream",
|
|
51
|
+
description: "Resumes a suspended workflow with streaming support",
|
|
52
52
|
required: true,
|
|
53
53
|
},
|
|
54
54
|
{
|
|
@@ -57,6 +57,12 @@ if (result.status === "suspended") {
|
|
|
57
57
|
description: "Cancels the workflow execution",
|
|
58
58
|
required: true,
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
name: "restart",
|
|
62
|
+
type: "(options?: RestartOptions) => Promise<WorkflowResult>",
|
|
63
|
+
description: "Restarts the workflow execution from last active step",
|
|
64
|
+
required: true,
|
|
65
|
+
},
|
|
60
66
|
]}
|
|
61
67
|
/>
|
|
62
68
|
|
|
@@ -92,3 +98,5 @@ A workflow run's `status` indicates its current execution state. The possible va
|
|
|
92
98
|
- [Run.start()](./run-methods/start)
|
|
93
99
|
- [Run.resume()](./run-methods/resume)
|
|
94
100
|
- [Run.cancel()](./run-methods/cancel)
|
|
101
|
+
- [Run.restart()](./run-methods/restart)
|
|
102
|
+
- [Run.stream()](/docs/v1/streaming/workflow-streaming)
|
|
@@ -103,6 +103,12 @@ const step1 = createStep({
|
|
|
103
103
|
description:
|
|
104
104
|
"The resume data matching the resumeSchema, when resuming the step from a suspended state. Only exists if the step is being resumed.",
|
|
105
105
|
},
|
|
106
|
+
{
|
|
107
|
+
name: "suspendData",
|
|
108
|
+
type: "z.infer<TSuspendSchema>",
|
|
109
|
+
description:
|
|
110
|
+
"The suspend data that was originally passed to suspend() when the step was suspended. Only exists if the step is being resumed and was previously suspended with data.",
|
|
111
|
+
},
|
|
106
112
|
{
|
|
107
113
|
name: "mastra",
|
|
108
114
|
type: "Mastra",
|
|
@@ -124,6 +130,12 @@ const step1 = createStep({
|
|
|
124
130
|
type: "(suspendPayload: any, suspendOptions?: { resumeLabel?: string }) => Promise<void>",
|
|
125
131
|
description: "Function to pause workflow execution",
|
|
126
132
|
},
|
|
133
|
+
{
|
|
134
|
+
name: "state",
|
|
135
|
+
type: "z.infer<TState>",
|
|
136
|
+
description:
|
|
137
|
+
"The current workflow state. Contains shared values that persist across all steps and suspend/resume cycles. The structure is defined by the step's stateSchema.",
|
|
138
|
+
},
|
|
127
139
|
{
|
|
128
140
|
name: "setState",
|
|
129
141
|
type: "(state: z.infer<TState>) => void",
|
|
@@ -154,5 +166,6 @@ const step1 = createStep({
|
|
|
154
166
|
|
|
155
167
|
## Related
|
|
156
168
|
|
|
169
|
+
- [Workflow state](/docs/v1/workflows/workflow-state)
|
|
157
170
|
- [Control flow](/docs/v1/workflows/control-flow)
|
|
158
171
|
- [Using agents and tools](/docs/v1/workflows/agents-and-tools)
|
|
@@ -88,6 +88,24 @@ export const workflow = createWorkflow({
|
|
|
88
88
|
]}
|
|
89
89
|
/>
|
|
90
90
|
|
|
91
|
+
## Running with initial state
|
|
92
|
+
|
|
93
|
+
When starting a workflow run, you can pass `initialState` to set the starting values for the workflow's state:
|
|
94
|
+
|
|
95
|
+
```typescript showLineNumbers copy
|
|
96
|
+
const run = await workflow.createRun();
|
|
97
|
+
|
|
98
|
+
const result = await run.start({
|
|
99
|
+
inputData: { value: "hello" },
|
|
100
|
+
initialState: {
|
|
101
|
+
counter: 0,
|
|
102
|
+
items: [],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The `initialState` object should match the structure defined in the workflow's `stateSchema`. See [Workflow State](/docs/v1/workflows/workflow-state) for more details.
|
|
108
|
+
|
|
91
109
|
## Workflow status
|
|
92
110
|
|
|
93
111
|
A workflow's `status` indicates its current execution state. The possible values are:
|
|
@@ -118,4 +136,5 @@ A workflow's `status` indicates its current execution state. The possible values
|
|
|
118
136
|
## Related
|
|
119
137
|
|
|
120
138
|
- [Step Class](./step)
|
|
139
|
+
- [Workflow State](/docs/v1/workflows/workflow-state)
|
|
121
140
|
- [Control flow](/docs/v1/workflows/control-flow)
|
|
@@ -240,7 +240,6 @@ const handleClientTool = async () => {
|
|
|
240
240
|
This is a standard Mastra [agent](../agents/overview#setting-up-agents) configured to return hex color codes, intended to work with the browser-based client tool defined above.
|
|
241
241
|
|
|
242
242
|
```typescript title="src/mastra/agents/color-agent" showLineNumbers copy
|
|
243
|
-
import { openai } from "@ai-sdk/openai";
|
|
244
243
|
import { Agent } from "@mastra/core/agent";
|
|
245
244
|
|
|
246
245
|
export const colorAgent = new Agent({
|
|
@@ -249,7 +248,7 @@ export const colorAgent = new Agent({
|
|
|
249
248
|
instructions: `You are a helpful CSS assistant.
|
|
250
249
|
You can change the background color of web pages.
|
|
251
250
|
Respond with a hex reference for the color requested by the user`,
|
|
252
|
-
model: openai
|
|
251
|
+
model: "openai/gpt-5.1",
|
|
253
252
|
});
|
|
254
253
|
```
|
|
255
254
|
|
|
@@ -36,7 +36,7 @@ export const mastra = new Mastra({
|
|
|
36
36
|
// ...
|
|
37
37
|
server: {
|
|
38
38
|
port: 3000, // Defaults to 4111
|
|
39
|
-
timeout: 10000, // Defaults to
|
|
39
|
+
timeout: 10000, // Defaults to 3 * 60 * 1000 (3 minutes)
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
42
|
```
|
|
@@ -87,3 +87,32 @@ export const mastra = new Mastra({
|
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
89
|
```
|
|
90
|
+
|
|
91
|
+
## Stream data redaction
|
|
92
|
+
|
|
93
|
+
When streaming agent responses over HTTP, Mastra automatically redacts sensitive information from stream chunks before sending them to clients. This prevents accidental exposure of:
|
|
94
|
+
|
|
95
|
+
- System prompts and agent instructions
|
|
96
|
+
- Tool definitions and their parameters
|
|
97
|
+
- API keys and other credentials in request bodies
|
|
98
|
+
- Internal configuration data
|
|
99
|
+
|
|
100
|
+
This redaction happens at the HTTP boundary, so internal callbacks like `onStepFinish` still have access to the full request data for debugging and observability purposes.
|
|
101
|
+
|
|
102
|
+
### Configuring redaction
|
|
103
|
+
|
|
104
|
+
By default, redaction is enabled. If you're using the server adapters directly (e.g., `@mastra/hono` or `@mastra/express`), you can configure this behavior:
|
|
105
|
+
|
|
106
|
+
```typescript title="Custom server setup" copy
|
|
107
|
+
import { HonoServerAdapter } from "@mastra/hono";
|
|
108
|
+
import { mastra } from "./mastra";
|
|
109
|
+
|
|
110
|
+
const adapter = new HonoServerAdapter({
|
|
111
|
+
mastra,
|
|
112
|
+
streamOptions: {
|
|
113
|
+
redact: true,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Set `redact: false` only for internal services or debugging scenarios where you need access to the full request data in stream responses.
|
|
@@ -187,7 +187,6 @@ export const weatherTool = createTool({
|
|
|
187
187
|
|
|
188
188
|
## Related
|
|
189
189
|
|
|
190
|
-
- [Request Context Example](/examples/v1/agents/request-context)
|
|
191
190
|
- [Agent Request Context](/docs/v1/agents/overview#using-requestcontext)
|
|
192
191
|
- [Workflow Request Context](../workflows/overview#using-requestcontext)
|
|
193
192
|
- [Tool Request Context](../mcp/overview#using-requestcontext)
|
|
@@ -489,12 +489,23 @@ console.log(result.messages); // MastraDBMessage[]
|
|
|
489
489
|
console.log(result.total); // Total count
|
|
490
490
|
console.log(result.hasMore); // Whether more pages exist
|
|
491
491
|
|
|
492
|
+
// Get messages from multiple threads at once
|
|
493
|
+
const multiThreadResult = await mastra
|
|
494
|
+
.getStorage()
|
|
495
|
+
.listMessages({
|
|
496
|
+
threadId: ["thread-1", "thread-2", "thread-3"],
|
|
497
|
+
page: 0,
|
|
498
|
+
perPage: 100
|
|
499
|
+
});
|
|
500
|
+
|
|
492
501
|
// Get messages by their IDs
|
|
493
502
|
const messages = await mastra
|
|
494
503
|
.getStorage()
|
|
495
504
|
.listMessagesById({ messageIds: messageIdArr });
|
|
496
505
|
```
|
|
497
506
|
|
|
507
|
+
The `threadId` parameter accepts either a single thread ID string or an array of thread IDs to query messages from multiple threads in a single request.
|
|
508
|
+
|
|
498
509
|
All message queries return `MastraDBMessage[]` format. If you need to convert messages to AI SDK formats for UI rendering, use the conversion utilities from `@mastra/ai-sdk/ui`:
|
|
499
510
|
|
|
500
511
|
```typescript copy
|
|
@@ -60,19 +60,30 @@ An agent stream provides access to various response properties:
|
|
|
60
60
|
|
|
61
61
|
AI SDK v5 uses `LanguageModelV2` for the model providers. If you are getting an error that you are using an AI SDK v4 model you will need to upgrade your model package to the next major version.
|
|
62
62
|
|
|
63
|
-
For integration with AI SDK v5, use `
|
|
63
|
+
For integration with AI SDK v5, use the `toAISdkV5Stream()` utility from `@mastra/ai-sdk` to convert Mastra streams to AI SDK-compatible format:
|
|
64
|
+
|
|
65
|
+
```typescript {2,9-12} showLineNumbers copy
|
|
66
|
+
import { toAISdkV5Stream } from "@mastra/ai-sdk";
|
|
64
67
|
|
|
65
|
-
```typescript {5} showLineNumbers copy
|
|
66
68
|
const testAgent = mastra.getAgent("testAgent");
|
|
67
69
|
|
|
68
|
-
const stream = await testAgent.stream(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
70
|
+
const stream = await testAgent.stream([
|
|
71
|
+
{ role: "user", content: "Help me organize my day" },
|
|
72
|
+
]);
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
// Convert to AI SDK v5 compatible stream
|
|
75
|
+
const aiSDKStream = toAISdkV5Stream(stream, { from: "agent" });
|
|
76
|
+
|
|
77
|
+
// Use with AI SDK v5 methods
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For converting messages to AI SDK v5 format, use the `toAISdkV5Messages()` utility from `@mastra/ai-sdk/ui`:
|
|
81
|
+
|
|
82
|
+
```typescript {1,4} showLineNumbers copy
|
|
83
|
+
import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
|
|
84
|
+
|
|
85
|
+
const messages = [{ role: "user", content: "Hello" }];
|
|
86
|
+
const aiSDKMessages = toAISdkV5Messages(messages);
|
|
76
87
|
```
|
|
77
88
|
|
|
78
89
|
### Using `Agent.network()`
|
|
@@ -121,14 +132,14 @@ console.log("Token usage:", await networkStream.usage);
|
|
|
121
132
|
|
|
122
133
|
Streaming from a workflow returns a sequence of structured events describing the run lifecycle, rather than incremental text chunks. This event-based format makes it possible to track and respond to workflow progress in real time once a run is created using `.createRun()`.
|
|
123
134
|
|
|
124
|
-
### Using `Run.
|
|
135
|
+
### Using `Run.stream()`
|
|
125
136
|
|
|
126
|
-
|
|
137
|
+
The `stream()` method returns a `ReadableStream` of events directly.
|
|
127
138
|
|
|
128
139
|
```typescript {3,9} showLineNumbers copy
|
|
129
140
|
const run = await testWorkflow.createRun();
|
|
130
141
|
|
|
131
|
-
const stream = await run.
|
|
142
|
+
const stream = await run.stream({
|
|
132
143
|
inputData: {
|
|
133
144
|
value: "initial data",
|
|
134
145
|
},
|
|
@@ -139,16 +150,16 @@ for await (const chunk of stream) {
|
|
|
139
150
|
}
|
|
140
151
|
```
|
|
141
152
|
|
|
142
|
-
> See Run.
|
|
153
|
+
> See [Run.stream()](/reference/v1/streaming/workflows/stream) method documentation for more information.
|
|
143
154
|
|
|
144
155
|
### Output from `Run.stream()`
|
|
145
156
|
|
|
146
|
-
The
|
|
157
|
+
The event structure includes `runId` and `from` at the top level, making it easier to identify and track workflow runs without digging into the payload.
|
|
147
158
|
|
|
148
159
|
```typescript
|
|
149
160
|
// ...
|
|
150
161
|
{
|
|
151
|
-
type: '
|
|
162
|
+
type: 'workflow-start',
|
|
152
163
|
runId: '1eeaf01a-d2bf-4e3f-8d1b-027795ccd3df',
|
|
153
164
|
from: 'WORKFLOW',
|
|
154
165
|
payload: {
|
|
@@ -18,8 +18,7 @@ By combining writable tool streams with agent streaming, you gain fine grained c
|
|
|
18
18
|
|
|
19
19
|
Agent streaming can be combined with tool calls, allowing tool outputs to be written directly into the agent’s streaming response. This makes it possible to surface tool activity as part of the overall interaction.
|
|
20
20
|
|
|
21
|
-
```typescript {
|
|
22
|
-
import { openai } from "@ai-sdk/openai";
|
|
21
|
+
```typescript {3,9} showLineNumbers copy
|
|
23
22
|
import { Agent } from "@mastra/core/agent";
|
|
24
23
|
|
|
25
24
|
import { testTool } from "../tools/test-tool";
|
|
@@ -28,7 +27,7 @@ export const testAgent = new Agent({
|
|
|
28
27
|
id: "test-agent",
|
|
29
28
|
name: "Test Agent",
|
|
30
29
|
instructions: "You are a weather agent.",
|
|
31
|
-
model: openai
|
|
30
|
+
model: "openai/gpt-5.1",
|
|
32
31
|
tools: { testTool },
|
|
33
32
|
});
|
|
34
33
|
```
|
|
@@ -117,9 +116,53 @@ for await (const chunk of stream) {
|
|
|
117
116
|
}
|
|
118
117
|
```
|
|
119
118
|
|
|
119
|
+
## Tool Lifecycle Hooks
|
|
120
|
+
|
|
121
|
+
Tools support lifecycle hooks that allow you to monitor different stages of tool execution during streaming. These hooks are particularly useful for logging or analytics.
|
|
122
|
+
|
|
123
|
+
### Example: Using onInputAvailable and onOutput
|
|
124
|
+
|
|
125
|
+
```typescript showLineNumbers copy
|
|
126
|
+
import { createTool } from "@mastra/core/tools";
|
|
127
|
+
import { z } from "zod";
|
|
128
|
+
|
|
129
|
+
export const weatherTool = createTool({
|
|
130
|
+
id: "weather-tool",
|
|
131
|
+
description: "Get weather information",
|
|
132
|
+
inputSchema: z.object({
|
|
133
|
+
city: z.string(),
|
|
134
|
+
}),
|
|
135
|
+
outputSchema: z.object({
|
|
136
|
+
temperature: z.number(),
|
|
137
|
+
conditions: z.string(),
|
|
138
|
+
}),
|
|
139
|
+
// Called when the complete input is available
|
|
140
|
+
onInputAvailable: ({ input, toolCallId }) => {
|
|
141
|
+
console.log(`Weather requested for: ${input.city}`);
|
|
142
|
+
},
|
|
143
|
+
execute: async (input) => {
|
|
144
|
+
const weather = await fetchWeather(input.city);
|
|
145
|
+
return weather;
|
|
146
|
+
},
|
|
147
|
+
// Called after successful execution
|
|
148
|
+
onOutput: ({ output, toolName }) => {
|
|
149
|
+
console.log(`${toolName} result: ${output.temperature}°F, ${output.conditions}`);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Available Hooks
|
|
155
|
+
|
|
156
|
+
- **onInputStart**: Called when tool call input streaming begins
|
|
157
|
+
- **onInputDelta**: Called for each chunk of input as it streams in
|
|
158
|
+
- **onInputAvailable**: Called when complete input is parsed and validated
|
|
159
|
+
- **onOutput**: Called after the tool successfully executes with the output
|
|
160
|
+
|
|
161
|
+
For detailed documentation on all lifecycle hooks, see the [createTool() reference](/reference/v1/tools/create-tool#tool-lifecycle-hooks).
|
|
162
|
+
|
|
120
163
|
## Tool using an agent
|
|
121
164
|
|
|
122
|
-
Pipe an agent
|
|
165
|
+
Pipe an agent's `fullStream` to the tool's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the tool run.
|
|
123
166
|
|
|
124
167
|
```typescript showLineNumbers copy
|
|
125
168
|
import { createTool } from "@mastra/core/tools";
|
|
@@ -133,7 +176,7 @@ export const testTool = createTool({
|
|
|
133
176
|
const testAgent = context?.mastra?.getAgent("testAgent");
|
|
134
177
|
const stream = await testAgent?.stream(`What is the weather in ${city}?`);
|
|
135
178
|
|
|
136
|
-
await stream!.
|
|
179
|
+
await stream!.fullStream.pipeTo(context?.writer!);
|
|
137
180
|
|
|
138
181
|
return {
|
|
139
182
|
value: await stream!.text,
|
|
@@ -16,12 +16,6 @@ By combining writable workflow streams with agent streaming, you gain fine-grain
|
|
|
16
16
|
|
|
17
17
|
### Using the `writer` argument
|
|
18
18
|
|
|
19
|
-
:::warning
|
|
20
|
-
|
|
21
|
-
The writer is only available when using `streamVNext`.
|
|
22
|
-
|
|
23
|
-
:::
|
|
24
|
-
|
|
25
19
|
The `writer` argument is passed to a workflow step's `execute` function and can be used to emit custom events, data, or values into the active stream. This enables workflow steps to provide intermediate results or status updates while execution is still in progress.
|
|
26
20
|
|
|
27
21
|
:::warning
|
|
@@ -66,7 +60,7 @@ const testWorkflow = mastra.getWorkflow("testWorkflow");
|
|
|
66
60
|
|
|
67
61
|
const run = await testWorkflow.createRun();
|
|
68
62
|
|
|
69
|
-
const stream = await run.
|
|
63
|
+
const stream = await run.stream({
|
|
70
64
|
inputData: {
|
|
71
65
|
value: "initial data",
|
|
72
66
|
},
|
|
@@ -77,8 +71,8 @@ for await (const chunk of stream) {
|
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
if (result!.status === "suspended") {
|
|
80
|
-
// if the workflow is suspended, we can resume it with the
|
|
81
|
-
const resumedStream = await run.
|
|
74
|
+
// if the workflow is suspended, we can resume it with the resumeStream method
|
|
75
|
+
const resumedStream = await run.resumeStream({
|
|
82
76
|
resumeData: { value: "resume data" },
|
|
83
77
|
});
|
|
84
78
|
|
|
@@ -90,10 +84,10 @@ if (result!.status === "suspended") {
|
|
|
90
84
|
|
|
91
85
|
### Resuming an interrupted workflow stream
|
|
92
86
|
|
|
93
|
-
If a workflow stream is closed or interrupted for any reason, you can resume it with the `
|
|
87
|
+
If a workflow stream is closed or interrupted for any reason, you can resume it with the `resumeStream` method. This will return a new `ReadableStream` that you can use to observe the workflow events.
|
|
94
88
|
|
|
95
89
|
```typescript showLineNumbers copy
|
|
96
|
-
const newStream = await run.
|
|
90
|
+
const newStream = await run.resumeStream();
|
|
97
91
|
|
|
98
92
|
for await (const chunk of newStream) {
|
|
99
93
|
console.log(chunk);
|
|
@@ -110,7 +110,6 @@ You can then add this tool to your Mastra agent just like any other tool:
|
|
|
110
110
|
|
|
111
111
|
```typescript title="src/mastra/agents/mixedToolsAgent.ts"
|
|
112
112
|
import { Agent } from "@mastra/core/agent";
|
|
113
|
-
import { openai } from "@ai-sdk/openai";
|
|
114
113
|
import { vercelWeatherTool } from "../tools/vercelWeatherTool"; // Vercel AI SDK tool
|
|
115
114
|
import { mastraTool } from "../tools/mastraTool"; // Mastra createTool tool
|
|
116
115
|
|
|
@@ -118,7 +117,7 @@ export const mixedToolsAgent = new Agent({
|
|
|
118
117
|
id: "mixed-tools-agent",
|
|
119
118
|
name: "Mixed Tools Agent",
|
|
120
119
|
instructions: "You can use tools defined in different formats.",
|
|
121
|
-
model: openai
|
|
120
|
+
model: "openai/gpt-5.1",
|
|
122
121
|
tools: {
|
|
123
122
|
weatherVercel: vercelWeatherTool,
|
|
124
123
|
someMastraTool: mastraTool,
|