@mastra/mcp-docs-server 1.1.5 → 1.1.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/docs/agents/adding-voice.md +349 -0
- package/.docs/docs/agents/agent-approval.md +558 -0
- package/.docs/docs/agents/agent-memory.md +209 -0
- package/.docs/docs/agents/guardrails.md +374 -0
- package/.docs/docs/agents/network-approval.md +275 -0
- package/.docs/docs/agents/networks.md +299 -0
- package/.docs/docs/agents/overview.md +304 -0
- package/.docs/docs/agents/processors.md +622 -0
- package/.docs/docs/agents/structured-output.md +273 -0
- package/.docs/docs/agents/supervisor-agents.md +304 -0
- package/.docs/docs/agents/using-tools.md +214 -0
- package/.docs/docs/build-with-ai/mcp-docs-server.md +238 -0
- package/.docs/docs/build-with-ai/skills.md +35 -0
- package/.docs/docs/community/contributing-templates.md +3 -0
- package/.docs/docs/community/discord.md +9 -0
- package/.docs/docs/community/licensing.md +66 -0
- package/.docs/docs/deployment/cloud-providers.md +15 -0
- package/.docs/docs/deployment/mastra-server.md +122 -0
- package/.docs/docs/deployment/monorepo.md +142 -0
- package/.docs/docs/deployment/overview.md +62 -0
- package/.docs/docs/deployment/studio.md +239 -0
- package/.docs/docs/deployment/web-framework.md +52 -0
- package/.docs/docs/deployment/workflow-runners.md +9 -0
- package/.docs/docs/evals/built-in-scorers.md +47 -0
- package/.docs/docs/evals/custom-scorers.md +519 -0
- package/.docs/docs/evals/overview.md +141 -0
- package/.docs/docs/evals/running-in-ci.md +124 -0
- package/.docs/docs/getting-started/build-with-ai.md +68 -0
- package/.docs/docs/getting-started/manual-install.md +226 -0
- package/.docs/docs/getting-started/project-structure.md +60 -0
- package/.docs/docs/getting-started/start.md +28 -0
- package/.docs/docs/getting-started/studio.md +101 -0
- package/.docs/docs/index.md +43 -0
- package/.docs/docs/mastra-cloud/deployment.md +77 -0
- package/.docs/docs/mastra-cloud/observability.md +38 -0
- package/.docs/docs/mastra-cloud/overview.md +23 -0
- package/.docs/docs/mastra-cloud/setup.md +42 -0
- package/.docs/docs/mastra-cloud/studio.md +24 -0
- package/.docs/docs/mastra-code/configuration.md +299 -0
- package/.docs/docs/mastra-code/customization.md +228 -0
- package/.docs/docs/mastra-code/modes.md +104 -0
- package/.docs/docs/mastra-code/overview.md +135 -0
- package/.docs/docs/mastra-code/tools.md +229 -0
- package/.docs/docs/mcp/overview.md +373 -0
- package/.docs/docs/mcp/publishing-mcp-server.md +95 -0
- package/.docs/docs/memory/memory-processors.md +314 -0
- package/.docs/docs/memory/message-history.md +260 -0
- package/.docs/docs/memory/observational-memory.md +248 -0
- package/.docs/docs/memory/overview.md +45 -0
- package/.docs/docs/memory/semantic-recall.md +272 -0
- package/.docs/docs/memory/storage.md +261 -0
- package/.docs/docs/memory/working-memory.md +400 -0
- package/.docs/docs/observability/datasets/overview.md +198 -0
- package/.docs/docs/observability/datasets/running-experiments.md +274 -0
- package/.docs/docs/observability/logging.md +99 -0
- package/.docs/docs/observability/overview.md +70 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +209 -0
- package/.docs/docs/observability/tracing/exporters/arize.md +272 -0
- package/.docs/docs/observability/tracing/exporters/braintrust.md +111 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +127 -0
- package/.docs/docs/observability/tracing/exporters/datadog.md +187 -0
- package/.docs/docs/observability/tracing/exporters/default.md +209 -0
- package/.docs/docs/observability/tracing/exporters/laminar.md +100 -0
- package/.docs/docs/observability/tracing/exporters/langfuse.md +213 -0
- package/.docs/docs/observability/tracing/exporters/langsmith.md +198 -0
- package/.docs/docs/observability/tracing/exporters/otel.md +476 -0
- package/.docs/docs/observability/tracing/exporters/posthog.md +148 -0
- package/.docs/docs/observability/tracing/exporters/sentry.md +208 -0
- package/.docs/docs/observability/tracing/overview.md +1112 -0
- package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +300 -0
- package/.docs/docs/rag/chunking-and-embedding.md +183 -0
- package/.docs/docs/rag/graph-rag.md +215 -0
- package/.docs/docs/rag/overview.md +72 -0
- package/.docs/docs/rag/retrieval.md +515 -0
- package/.docs/docs/rag/vector-databases.md +645 -0
- package/.docs/docs/server/auth/auth0.md +220 -0
- package/.docs/docs/server/auth/better-auth.md +203 -0
- package/.docs/docs/server/auth/clerk.md +132 -0
- package/.docs/docs/server/auth/composite-auth.md +234 -0
- package/.docs/docs/server/auth/custom-auth-provider.md +513 -0
- package/.docs/docs/server/auth/firebase.md +272 -0
- package/.docs/docs/server/auth/jwt.md +110 -0
- package/.docs/docs/server/auth/simple-auth.md +180 -0
- package/.docs/docs/server/auth/supabase.md +117 -0
- package/.docs/docs/server/auth/workos.md +186 -0
- package/.docs/docs/server/auth.md +38 -0
- package/.docs/docs/server/custom-adapters.md +378 -0
- package/.docs/docs/server/custom-api-routes.md +267 -0
- package/.docs/docs/server/mastra-client.md +243 -0
- package/.docs/docs/server/mastra-server.md +71 -0
- package/.docs/docs/server/middleware.md +225 -0
- package/.docs/docs/server/request-context.md +471 -0
- package/.docs/docs/server/server-adapters.md +547 -0
- package/.docs/docs/streaming/events.md +237 -0
- package/.docs/docs/streaming/overview.md +175 -0
- package/.docs/docs/streaming/tool-streaming.md +175 -0
- package/.docs/docs/streaming/workflow-streaming.md +109 -0
- package/.docs/docs/voice/overview.md +959 -0
- package/.docs/docs/voice/speech-to-speech.md +102 -0
- package/.docs/docs/voice/speech-to-text.md +79 -0
- package/.docs/docs/voice/text-to-speech.md +83 -0
- package/.docs/docs/workflows/agents-and-tools.md +166 -0
- package/.docs/docs/workflows/control-flow.md +822 -0
- package/.docs/docs/workflows/error-handling.md +360 -0
- package/.docs/docs/workflows/human-in-the-loop.md +215 -0
- package/.docs/docs/workflows/overview.md +370 -0
- package/.docs/docs/workflows/snapshots.md +238 -0
- package/.docs/docs/workflows/suspend-and-resume.md +205 -0
- package/.docs/docs/workflows/time-travel.md +309 -0
- package/.docs/docs/workflows/workflow-state.md +181 -0
- package/.docs/docs/workspace/filesystem.md +164 -0
- package/.docs/docs/workspace/overview.md +239 -0
- package/.docs/docs/workspace/sandbox.md +63 -0
- package/.docs/docs/workspace/search.md +243 -0
- package/.docs/docs/workspace/skills.md +169 -0
- package/.docs/guides/agent-frameworks/ai-sdk.md +140 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +1499 -0
- package/.docs/guides/build-your-ui/assistant-ui.md +156 -0
- package/.docs/guides/build-your-ui/copilotkit.md +289 -0
- package/.docs/guides/deployment/amazon-ec2.md +130 -0
- package/.docs/guides/deployment/aws-lambda.md +248 -0
- package/.docs/guides/deployment/azure-app-services.md +114 -0
- package/.docs/guides/deployment/cloudflare.md +99 -0
- package/.docs/guides/deployment/digital-ocean.md +168 -0
- package/.docs/guides/deployment/inngest.md +682 -0
- package/.docs/guides/deployment/netlify.md +77 -0
- package/.docs/guides/deployment/vercel.md +101 -0
- package/.docs/guides/getting-started/astro.md +398 -0
- package/.docs/guides/getting-started/electron.md +504 -0
- package/.docs/guides/getting-started/express.md +251 -0
- package/.docs/guides/getting-started/hono.md +190 -0
- package/.docs/guides/getting-started/next-js.md +347 -0
- package/.docs/guides/getting-started/nuxt.md +497 -0
- package/.docs/guides/getting-started/quickstart.md +67 -0
- package/.docs/guides/getting-started/sveltekit.md +296 -0
- package/.docs/guides/getting-started/vite-react.md +425 -0
- package/.docs/guides/guide/ai-recruiter.md +226 -0
- package/.docs/guides/guide/chef-michel.md +211 -0
- package/.docs/guides/guide/code-review-bot.md +226 -0
- package/.docs/guides/guide/dev-assistant.md +307 -0
- package/.docs/guides/guide/docs-manager.md +238 -0
- package/.docs/guides/guide/github-actions-pr-description.md +236 -0
- package/.docs/guides/guide/notes-mcp-server.md +416 -0
- package/.docs/guides/guide/research-assistant.md +348 -0
- package/.docs/guides/guide/research-coordinator.md +416 -0
- package/.docs/guides/guide/stock-agent.md +132 -0
- package/.docs/guides/guide/web-search.md +320 -0
- package/.docs/guides/guide/whatsapp-chat-bot.md +405 -0
- package/.docs/guides/index.md +3 -0
- package/.docs/guides/migrations/agentnetwork.md +97 -0
- package/.docs/guides/migrations/ai-sdk-v4-to-v5.md +112 -0
- package/.docs/guides/migrations/network-to-supervisor.md +261 -0
- package/.docs/guides/migrations/upgrade-to-v1/agent.md +404 -0
- package/.docs/guides/migrations/upgrade-to-v1/cli.md +57 -0
- package/.docs/guides/migrations/upgrade-to-v1/client.md +337 -0
- package/.docs/guides/migrations/upgrade-to-v1/deployment.md +37 -0
- package/.docs/guides/migrations/upgrade-to-v1/evals.md +239 -0
- package/.docs/guides/migrations/upgrade-to-v1/mastra.md +143 -0
- package/.docs/guides/migrations/upgrade-to-v1/mcp.md +97 -0
- package/.docs/guides/migrations/upgrade-to-v1/memory.md +285 -0
- package/.docs/guides/migrations/upgrade-to-v1/overview.md +119 -0
- package/.docs/guides/migrations/upgrade-to-v1/processors.md +68 -0
- package/.docs/guides/migrations/upgrade-to-v1/rag.md +42 -0
- package/.docs/guides/migrations/upgrade-to-v1/storage.md +553 -0
- package/.docs/guides/migrations/upgrade-to-v1/tools.md +180 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +412 -0
- package/.docs/guides/migrations/upgrade-to-v1/vectors.md +87 -0
- package/.docs/guides/migrations/upgrade-to-v1/voice.md +30 -0
- package/.docs/guides/migrations/upgrade-to-v1/workflows.md +341 -0
- package/.docs/guides/migrations/vnext-to-standard-apis.md +362 -0
- package/.docs/models/embeddings.md +161 -0
- package/.docs/models/gateways/azure-openai.md +128 -0
- package/.docs/models/gateways/custom-gateways.md +545 -0
- package/.docs/models/gateways/netlify.md +88 -0
- package/.docs/models/gateways/openrouter.md +219 -0
- package/.docs/models/gateways/vercel.md +225 -0
- package/.docs/models/gateways.md +14 -0
- package/.docs/models/index.md +286 -0
- package/.docs/models/providers/302ai.md +134 -0
- package/.docs/models/providers/abacus.md +125 -0
- package/.docs/models/providers/agentrouter.md +90 -0
- package/.docs/models/providers/aihubmix.md +107 -0
- package/.docs/models/providers/alibaba-cn.md +135 -0
- package/.docs/models/providers/alibaba.md +111 -0
- package/.docs/models/providers/amazon-bedrock.md +33 -0
- package/.docs/models/providers/anthropic.md +153 -0
- package/.docs/models/providers/azure.md +33 -0
- package/.docs/models/providers/bailing.md +72 -0
- package/.docs/models/providers/baseten.md +77 -0
- package/.docs/models/providers/berget.md +78 -0
- package/.docs/models/providers/cerebras.md +101 -0
- package/.docs/models/providers/chutes.md +136 -0
- package/.docs/models/providers/cloudflare-ai-gateway.md +33 -0
- package/.docs/models/providers/cloudflare-workers-ai.md +109 -0
- package/.docs/models/providers/cohere.md +33 -0
- package/.docs/models/providers/cortecs.md +91 -0
- package/.docs/models/providers/deepinfra.md +112 -0
- package/.docs/models/providers/deepseek.md +88 -0
- package/.docs/models/providers/fastrouter.md +84 -0
- package/.docs/models/providers/fireworks-ai.md +89 -0
- package/.docs/models/providers/firmware.md +85 -0
- package/.docs/models/providers/friendli.md +78 -0
- package/.docs/models/providers/github-models.md +125 -0
- package/.docs/models/providers/google-vertex.md +33 -0
- package/.docs/models/providers/google.md +159 -0
- package/.docs/models/providers/groq.md +107 -0
- package/.docs/models/providers/helicone.md +161 -0
- package/.docs/models/providers/huggingface.md +90 -0
- package/.docs/models/providers/iflowcn.md +84 -0
- package/.docs/models/providers/inception.md +72 -0
- package/.docs/models/providers/inference.md +79 -0
- package/.docs/models/providers/io-intelligence.md +87 -0
- package/.docs/models/providers/io-net.md +87 -0
- package/.docs/models/providers/jiekou.md +131 -0
- package/.docs/models/providers/kilo.md +333 -0
- package/.docs/models/providers/kimi-for-coding.md +100 -0
- package/.docs/models/providers/kuae-cloud-coding-plan.md +71 -0
- package/.docs/models/providers/llama.md +77 -0
- package/.docs/models/providers/lmstudio.md +73 -0
- package/.docs/models/providers/lucidquery.md +72 -0
- package/.docs/models/providers/minimax-cn-coding-plan.md +102 -0
- package/.docs/models/providers/minimax-cn.md +102 -0
- package/.docs/models/providers/minimax-coding-plan.md +102 -0
- package/.docs/models/providers/minimax.md +104 -0
- package/.docs/models/providers/mistral.md +124 -0
- package/.docs/models/providers/moark.md +72 -0
- package/.docs/models/providers/modelscope.md +77 -0
- package/.docs/models/providers/moonshotai-cn.md +76 -0
- package/.docs/models/providers/moonshotai.md +76 -0
- package/.docs/models/providers/morph.md +73 -0
- package/.docs/models/providers/nano-gpt.md +103 -0
- package/.docs/models/providers/nebius.md +116 -0
- package/.docs/models/providers/nova.md +72 -0
- package/.docs/models/providers/novita-ai.md +154 -0
- package/.docs/models/providers/nvidia.md +141 -0
- package/.docs/models/providers/ollama-cloud.md +103 -0
- package/.docs/models/providers/ollama.md +33 -0
- package/.docs/models/providers/openai.md +193 -0
- package/.docs/models/providers/opencode.md +100 -0
- package/.docs/models/providers/ovhcloud.md +83 -0
- package/.docs/models/providers/perplexity.md +100 -0
- package/.docs/models/providers/poe.md +183 -0
- package/.docs/models/providers/privatemode-ai.md +75 -0
- package/.docs/models/providers/requesty.md +90 -0
- package/.docs/models/providers/scaleway.md +84 -0
- package/.docs/models/providers/siliconflow-cn.md +138 -0
- package/.docs/models/providers/siliconflow.md +140 -0
- package/.docs/models/providers/stackit.md +78 -0
- package/.docs/models/providers/stepfun.md +73 -0
- package/.docs/models/providers/submodel.md +79 -0
- package/.docs/models/providers/synthetic.md +96 -0
- package/.docs/models/providers/togetherai.md +115 -0
- package/.docs/models/providers/upstage.md +73 -0
- package/.docs/models/providers/venice.md +95 -0
- package/.docs/models/providers/vivgrid.md +106 -0
- package/.docs/models/providers/vultr.md +75 -0
- package/.docs/models/providers/wandb.md +80 -0
- package/.docs/models/providers/xai.md +141 -0
- package/.docs/models/providers/xiaomi.md +71 -0
- package/.docs/models/providers/zai-coding-plan.md +80 -0
- package/.docs/models/providers/zai.md +79 -0
- package/.docs/models/providers/zenmux.md +161 -0
- package/.docs/models/providers/zhipuai-coding-plan.md +79 -0
- package/.docs/models/providers/zhipuai.md +79 -0
- package/.docs/models/providers.md +81 -0
- package/.docs/reference/agents/agent.md +141 -0
- package/.docs/reference/agents/generate.md +186 -0
- package/.docs/reference/agents/generateLegacy.md +173 -0
- package/.docs/reference/agents/getDefaultGenerateOptions.md +36 -0
- package/.docs/reference/agents/getDefaultOptions.md +34 -0
- package/.docs/reference/agents/getDefaultStreamOptions.md +36 -0
- package/.docs/reference/agents/getDescription.md +21 -0
- package/.docs/reference/agents/getInstructions.md +34 -0
- package/.docs/reference/agents/getLLM.md +37 -0
- package/.docs/reference/agents/getMemory.md +34 -0
- package/.docs/reference/agents/getModel.md +34 -0
- package/.docs/reference/agents/getTools.md +29 -0
- package/.docs/reference/agents/getVoice.md +34 -0
- package/.docs/reference/agents/listAgents.md +35 -0
- package/.docs/reference/agents/listScorers.md +34 -0
- package/.docs/reference/agents/listTools.md +34 -0
- package/.docs/reference/agents/listWorkflows.md +34 -0
- package/.docs/reference/agents/network.md +133 -0
- package/.docs/reference/ai-sdk/chat-route.md +82 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +53 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +37 -0
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +55 -0
- package/.docs/reference/ai-sdk/network-route.md +74 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +231 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +79 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +76 -0
- package/.docs/reference/ai-sdk/with-mastra.md +59 -0
- package/.docs/reference/ai-sdk/workflow-route.md +79 -0
- package/.docs/reference/auth/auth0.md +73 -0
- package/.docs/reference/auth/better-auth.md +71 -0
- package/.docs/reference/auth/clerk.md +36 -0
- package/.docs/reference/auth/firebase.md +80 -0
- package/.docs/reference/auth/jwt.md +26 -0
- package/.docs/reference/auth/supabase.md +33 -0
- package/.docs/reference/auth/workos.md +84 -0
- package/.docs/reference/cli/create-mastra.md +137 -0
- package/.docs/reference/cli/mastra.md +336 -0
- package/.docs/reference/client-js/agents.md +437 -0
- package/.docs/reference/client-js/error-handling.md +16 -0
- package/.docs/reference/client-js/logs.md +24 -0
- package/.docs/reference/client-js/mastra-client.md +63 -0
- package/.docs/reference/client-js/memory.md +221 -0
- package/.docs/reference/client-js/observability.md +72 -0
- package/.docs/reference/client-js/telemetry.md +20 -0
- package/.docs/reference/client-js/tools.md +44 -0
- package/.docs/reference/client-js/vectors.md +79 -0
- package/.docs/reference/client-js/workflows.md +199 -0
- package/.docs/reference/configuration.md +752 -0
- package/.docs/reference/core/addGateway.md +42 -0
- package/.docs/reference/core/getAgent.md +21 -0
- package/.docs/reference/core/getAgentById.md +21 -0
- package/.docs/reference/core/getDeployer.md +22 -0
- package/.docs/reference/core/getGateway.md +38 -0
- package/.docs/reference/core/getGatewayById.md +41 -0
- package/.docs/reference/core/getLogger.md +22 -0
- package/.docs/reference/core/getMCPServer.md +47 -0
- package/.docs/reference/core/getMCPServerById.md +55 -0
- package/.docs/reference/core/getMemory.md +50 -0
- package/.docs/reference/core/getScorer.md +54 -0
- package/.docs/reference/core/getScorerById.md +54 -0
- package/.docs/reference/core/getServer.md +22 -0
- package/.docs/reference/core/getStorage.md +22 -0
- package/.docs/reference/core/getStoredAgentById.md +89 -0
- package/.docs/reference/core/getTelemetry.md +22 -0
- package/.docs/reference/core/getVector.md +22 -0
- package/.docs/reference/core/getWorkflow.md +42 -0
- package/.docs/reference/core/listAgents.md +21 -0
- package/.docs/reference/core/listGateways.md +40 -0
- package/.docs/reference/core/listLogs.md +38 -0
- package/.docs/reference/core/listLogsByRunId.md +36 -0
- package/.docs/reference/core/listMCPServers.md +55 -0
- package/.docs/reference/core/listMemory.md +56 -0
- package/.docs/reference/core/listScorers.md +29 -0
- package/.docs/reference/core/listStoredAgents.md +93 -0
- package/.docs/reference/core/listVectors.md +22 -0
- package/.docs/reference/core/listWorkflows.md +21 -0
- package/.docs/reference/core/mastra-class.md +66 -0
- package/.docs/reference/core/mastra-model-gateway.md +153 -0
- package/.docs/reference/core/setLogger.md +26 -0
- package/.docs/reference/core/setStorage.md +27 -0
- package/.docs/reference/datasets/addItem.md +37 -0
- package/.docs/reference/datasets/addItems.md +35 -0
- package/.docs/reference/datasets/compareExperiments.md +52 -0
- package/.docs/reference/datasets/create.md +51 -0
- package/.docs/reference/datasets/dataset.md +82 -0
- package/.docs/reference/datasets/datasets-manager.md +94 -0
- package/.docs/reference/datasets/delete.md +25 -0
- package/.docs/reference/datasets/deleteExperiment.md +27 -0
- package/.docs/reference/datasets/deleteItem.md +27 -0
- package/.docs/reference/datasets/deleteItems.md +29 -0
- package/.docs/reference/datasets/get.md +31 -0
- package/.docs/reference/datasets/getDetails.md +47 -0
- package/.docs/reference/datasets/getExperiment.md +30 -0
- package/.docs/reference/datasets/getItem.md +33 -0
- package/.docs/reference/datasets/getItemHistory.md +31 -0
- package/.docs/reference/datasets/list.md +31 -0
- package/.docs/reference/datasets/listExperimentResults.md +39 -0
- package/.docs/reference/datasets/listExperiments.md +33 -0
- package/.docs/reference/datasets/listItems.md +46 -0
- package/.docs/reference/datasets/listVersions.md +33 -0
- package/.docs/reference/datasets/startExperiment.md +62 -0
- package/.docs/reference/datasets/startExperimentAsync.md +43 -0
- package/.docs/reference/datasets/update.md +48 -0
- package/.docs/reference/datasets/updateItem.md +38 -0
- package/.docs/reference/deployer/cloudflare.md +79 -0
- package/.docs/reference/deployer/netlify.md +80 -0
- package/.docs/reference/deployer/vercel.md +91 -0
- package/.docs/reference/deployer.md +100 -0
- package/.docs/reference/evals/answer-relevancy.md +105 -0
- package/.docs/reference/evals/answer-similarity.md +99 -0
- package/.docs/reference/evals/bias.md +120 -0
- package/.docs/reference/evals/completeness.md +136 -0
- package/.docs/reference/evals/content-similarity.md +101 -0
- package/.docs/reference/evals/context-precision.md +196 -0
- package/.docs/reference/evals/context-relevance.md +531 -0
- package/.docs/reference/evals/create-scorer.md +270 -0
- package/.docs/reference/evals/faithfulness.md +114 -0
- package/.docs/reference/evals/hallucination.md +213 -0
- package/.docs/reference/evals/keyword-coverage.md +128 -0
- package/.docs/reference/evals/mastra-scorer.md +123 -0
- package/.docs/reference/evals/noise-sensitivity.md +675 -0
- package/.docs/reference/evals/prompt-alignment.md +614 -0
- package/.docs/reference/evals/run-evals.md +179 -0
- package/.docs/reference/evals/scorer-utils.md +326 -0
- package/.docs/reference/evals/textual-difference.md +113 -0
- package/.docs/reference/evals/tone-consistency.md +119 -0
- package/.docs/reference/evals/tool-call-accuracy.md +533 -0
- package/.docs/reference/evals/toxicity.md +123 -0
- package/.docs/reference/harness/harness-class.md +708 -0
- package/.docs/reference/index.md +277 -0
- package/.docs/reference/logging/pino-logger.md +117 -0
- package/.docs/reference/mastra-code/createMastraCode.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +199 -0
- package/.docs/reference/memory/cloneThread.md +130 -0
- package/.docs/reference/memory/createThread.md +68 -0
- package/.docs/reference/memory/deleteMessages.md +38 -0
- package/.docs/reference/memory/getThreadById.md +24 -0
- package/.docs/reference/memory/listThreads.md +145 -0
- package/.docs/reference/memory/memory-class.md +147 -0
- package/.docs/reference/memory/observational-memory.md +565 -0
- package/.docs/reference/memory/recall.md +91 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +131 -0
- package/.docs/reference/observability/tracing/configuration.md +178 -0
- package/.docs/reference/observability/tracing/exporters/arize.md +141 -0
- package/.docs/reference/observability/tracing/exporters/braintrust.md +93 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +163 -0
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +138 -0
- package/.docs/reference/observability/tracing/exporters/datadog.md +116 -0
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +174 -0
- package/.docs/reference/observability/tracing/exporters/laminar.md +78 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +134 -0
- package/.docs/reference/observability/tracing/exporters/langsmith.md +108 -0
- package/.docs/reference/observability/tracing/exporters/otel.md +199 -0
- package/.docs/reference/observability/tracing/exporters/posthog.md +92 -0
- package/.docs/reference/observability/tracing/exporters/sentry.md +184 -0
- package/.docs/reference/observability/tracing/instances.md +107 -0
- package/.docs/reference/observability/tracing/interfaces.md +743 -0
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +144 -0
- package/.docs/reference/observability/tracing/spans.md +224 -0
- package/.docs/reference/processors/batch-parts-processor.md +61 -0
- package/.docs/reference/processors/language-detector.md +82 -0
- package/.docs/reference/processors/message-history-processor.md +85 -0
- package/.docs/reference/processors/moderation-processor.md +104 -0
- package/.docs/reference/processors/pii-detector.md +108 -0
- package/.docs/reference/processors/processor-interface.md +521 -0
- package/.docs/reference/processors/prompt-injection-detector.md +72 -0
- package/.docs/reference/processors/semantic-recall-processor.md +117 -0
- package/.docs/reference/processors/system-prompt-scrubber.md +80 -0
- package/.docs/reference/processors/token-limiter-processor.md +115 -0
- package/.docs/reference/processors/tool-call-filter.md +85 -0
- package/.docs/reference/processors/tool-search-processor.md +111 -0
- package/.docs/reference/processors/unicode-normalizer.md +62 -0
- package/.docs/reference/processors/working-memory-processor.md +152 -0
- package/.docs/reference/rag/chunk.md +221 -0
- package/.docs/reference/rag/database-config.md +261 -0
- package/.docs/reference/rag/document.md +114 -0
- package/.docs/reference/rag/embeddings.md +92 -0
- package/.docs/reference/rag/extract-params.md +168 -0
- package/.docs/reference/rag/graph-rag.md +111 -0
- package/.docs/reference/rag/metadata-filters.md +216 -0
- package/.docs/reference/rag/rerank.md +75 -0
- package/.docs/reference/rag/rerankWithScorer.md +80 -0
- package/.docs/reference/server/create-route.md +262 -0
- package/.docs/reference/server/express-adapter.md +176 -0
- package/.docs/reference/server/fastify-adapter.md +90 -0
- package/.docs/reference/server/hono-adapter.md +162 -0
- package/.docs/reference/server/koa-adapter.md +127 -0
- package/.docs/reference/server/mastra-server.md +298 -0
- package/.docs/reference/server/register-api-route.md +249 -0
- package/.docs/reference/server/routes.md +306 -0
- package/.docs/reference/storage/cloudflare-d1.md +218 -0
- package/.docs/reference/storage/cloudflare.md +88 -0
- package/.docs/reference/storage/composite.md +235 -0
- package/.docs/reference/storage/convex.md +161 -0
- package/.docs/reference/storage/dynamodb.md +282 -0
- package/.docs/reference/storage/lance.md +131 -0
- package/.docs/reference/storage/libsql.md +135 -0
- package/.docs/reference/storage/mongodb.md +262 -0
- package/.docs/reference/storage/mssql.md +157 -0
- package/.docs/reference/storage/overview.md +121 -0
- package/.docs/reference/storage/postgresql.md +526 -0
- package/.docs/reference/storage/upstash.md +160 -0
- package/.docs/reference/streaming/ChunkType.md +292 -0
- package/.docs/reference/streaming/agents/MastraModelOutput.md +182 -0
- package/.docs/reference/streaming/agents/stream.md +221 -0
- package/.docs/reference/streaming/agents/streamLegacy.md +142 -0
- package/.docs/reference/streaming/workflows/observeStream.md +42 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +61 -0
- package/.docs/reference/streaming/workflows/stream.md +88 -0
- package/.docs/reference/streaming/workflows/timeTravelStream.md +142 -0
- package/.docs/reference/templates/overview.md +194 -0
- package/.docs/reference/tools/create-tool.md +237 -0
- package/.docs/reference/tools/document-chunker-tool.md +89 -0
- package/.docs/reference/tools/graph-rag-tool.md +182 -0
- package/.docs/reference/tools/mcp-client.md +954 -0
- package/.docs/reference/tools/mcp-server.md +1271 -0
- package/.docs/reference/tools/vector-query-tool.md +459 -0
- package/.docs/reference/vectors/astra.md +121 -0
- package/.docs/reference/vectors/chroma.md +264 -0
- package/.docs/reference/vectors/convex.md +300 -0
- package/.docs/reference/vectors/couchbase.md +226 -0
- package/.docs/reference/vectors/duckdb.md +318 -0
- package/.docs/reference/vectors/elasticsearch.md +189 -0
- package/.docs/reference/vectors/lance.md +220 -0
- package/.docs/reference/vectors/libsql.md +305 -0
- package/.docs/reference/vectors/mongodb.md +295 -0
- package/.docs/reference/vectors/opensearch.md +99 -0
- package/.docs/reference/vectors/pg.md +408 -0
- package/.docs/reference/vectors/pinecone.md +168 -0
- package/.docs/reference/vectors/qdrant.md +222 -0
- package/.docs/reference/vectors/s3vectors.md +277 -0
- package/.docs/reference/vectors/turbopuffer.md +157 -0
- package/.docs/reference/vectors/upstash.md +294 -0
- package/.docs/reference/vectors/vectorize.md +147 -0
- package/.docs/reference/voice/azure.md +148 -0
- package/.docs/reference/voice/cloudflare.md +83 -0
- package/.docs/reference/voice/composite-voice.md +121 -0
- package/.docs/reference/voice/deepgram.md +79 -0
- package/.docs/reference/voice/elevenlabs.md +98 -0
- package/.docs/reference/voice/google-gemini-live.md +378 -0
- package/.docs/reference/voice/google.md +228 -0
- package/.docs/reference/voice/mastra-voice.md +311 -0
- package/.docs/reference/voice/murf.md +122 -0
- package/.docs/reference/voice/openai-realtime.md +203 -0
- package/.docs/reference/voice/openai.md +88 -0
- package/.docs/reference/voice/playai.md +80 -0
- package/.docs/reference/voice/sarvam.md +126 -0
- package/.docs/reference/voice/speechify.md +75 -0
- package/.docs/reference/voice/voice.addInstructions.md +55 -0
- package/.docs/reference/voice/voice.addTools.md +67 -0
- package/.docs/reference/voice/voice.answer.md +54 -0
- package/.docs/reference/voice/voice.close.md +51 -0
- package/.docs/reference/voice/voice.connect.md +94 -0
- package/.docs/reference/voice/voice.events.md +37 -0
- package/.docs/reference/voice/voice.getSpeakers.md +129 -0
- package/.docs/reference/voice/voice.listen.md +164 -0
- package/.docs/reference/voice/voice.off.md +54 -0
- package/.docs/reference/voice/voice.on.md +111 -0
- package/.docs/reference/voice/voice.send.md +65 -0
- package/.docs/reference/voice/voice.speak.md +157 -0
- package/.docs/reference/voice/voice.updateConfig.md +60 -0
- package/.docs/reference/workflows/run-methods/cancel.md +86 -0
- package/.docs/reference/workflows/run-methods/restart.md +33 -0
- package/.docs/reference/workflows/run-methods/resume.md +59 -0
- package/.docs/reference/workflows/run-methods/start.md +58 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +67 -0
- package/.docs/reference/workflows/run-methods/timeTravel.md +142 -0
- package/.docs/reference/workflows/run.md +59 -0
- package/.docs/reference/workflows/step.md +119 -0
- package/.docs/reference/workflows/workflow-methods/branch.md +25 -0
- package/.docs/reference/workflows/workflow-methods/commit.md +17 -0
- package/.docs/reference/workflows/workflow-methods/create-run.md +63 -0
- package/.docs/reference/workflows/workflow-methods/dountil.md +25 -0
- package/.docs/reference/workflows/workflow-methods/dowhile.md +25 -0
- package/.docs/reference/workflows/workflow-methods/foreach.md +118 -0
- package/.docs/reference/workflows/workflow-methods/map.md +93 -0
- package/.docs/reference/workflows/workflow-methods/parallel.md +21 -0
- package/.docs/reference/workflows/workflow-methods/sleep.md +35 -0
- package/.docs/reference/workflows/workflow-methods/sleepUntil.md +35 -0
- package/.docs/reference/workflows/workflow-methods/then.md +21 -0
- package/.docs/reference/workflows/workflow.md +157 -0
- package/.docs/reference/workspace/e2b-sandbox.md +289 -0
- package/.docs/reference/workspace/filesystem.md +255 -0
- package/.docs/reference/workspace/gcs-filesystem.md +174 -0
- package/.docs/reference/workspace/local-filesystem.md +343 -0
- package/.docs/reference/workspace/local-sandbox.md +301 -0
- package/.docs/reference/workspace/s3-filesystem.md +175 -0
- package/.docs/reference/workspace/sandbox.md +87 -0
- package/.docs/reference/workspace/workspace-class.md +244 -0
- package/CHANGELOG.md +16 -0
- package/package.json +6 -6
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Building an Agent that can search the web
|
|
2
|
+
|
|
3
|
+
When building a web search agent, you have two main strategies to consider:
|
|
4
|
+
|
|
5
|
+
1. **Native search tools from the LLM**: Certain language models offer integrated web search capabilities that work out of the box.
|
|
6
|
+
2. **Implement a custom search tool**: Develop your own integration with a search provider's API to handle queries and retrieve results.
|
|
7
|
+
|
|
8
|
+
## Prerequisites
|
|
9
|
+
|
|
10
|
+
- Node.js `v22.13.0` or later installed
|
|
11
|
+
- An API key from a supported [Model Provider](https://mastra.ai/models)
|
|
12
|
+
- An existing Mastra project (Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) to set up a new project)
|
|
13
|
+
|
|
14
|
+
## Using native search tools
|
|
15
|
+
|
|
16
|
+
Some LLM providers include built-in web search capabilities that can be used directly without additional API integrations. OpenAI's GPT-4o-mini and Google's Gemini 2.5 Flash both offer native search tools that the model can invoke during generation.
|
|
17
|
+
|
|
18
|
+
1. Install dependencies
|
|
19
|
+
|
|
20
|
+
**Open AI**:
|
|
21
|
+
|
|
22
|
+
**npm**:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @ai-sdk/openai
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**pnpm**:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add @ai-sdk/openai
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Yarn**:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
yarn add @ai-sdk/openai
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Bun**:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bun add @ai-sdk/openai
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Gemini**:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @ai-sdk/openai
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Tab 3**:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pnpm add @ai-sdk/openai
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Tab 4**:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
yarn add @ai-sdk/openai
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Tab 5**:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
bun add @ai-sdk/openai
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Tab 6**:
|
|
71
|
+
|
|
72
|
+
**npm**:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install @ai-sdk/google
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**pnpm**:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pnpm add @ai-sdk/google
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Yarn**:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
yarn add @ai-sdk/google
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Bun**:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
bun add @ai-sdk/google
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Tab 7**:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npm install @ai-sdk/google
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Tab 8**:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm add @ai-sdk/google
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Tab 9**:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
yarn add @ai-sdk/google
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Tab 10**:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
bun add @ai-sdk/google
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
2. Create a new file `src/mastra/agents/searchAgent.ts` and define your agent:
|
|
121
|
+
|
|
122
|
+
**Open AI**:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { Agent } from '@mastra/core/agent'
|
|
126
|
+
|
|
127
|
+
export const searchAgent = new Agent({
|
|
128
|
+
id: 'search-agent',
|
|
129
|
+
name: 'Search Agent',
|
|
130
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
131
|
+
model: 'openai/gpt-5.1',
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Gemini**:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { Agent } from '@mastra/core/agent'
|
|
139
|
+
|
|
140
|
+
export const searchAgent = new Agent({
|
|
141
|
+
id: 'search-agent',
|
|
142
|
+
name: 'Search Agent',
|
|
143
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
144
|
+
model: 'google/gemini-2.5-flash',
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
3. Setup the tool:
|
|
149
|
+
|
|
150
|
+
**Open AI**:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { openai } from '@ai-sdk/openai'
|
|
154
|
+
import { Agent } from '@mastra/core/agent'
|
|
155
|
+
|
|
156
|
+
export const searchAgent = new Agent({
|
|
157
|
+
id: 'search-agent',
|
|
158
|
+
name: 'Search Agent',
|
|
159
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
160
|
+
model: 'openai/gpt-5.1',
|
|
161
|
+
tools: {
|
|
162
|
+
webSearch: openai.tools.webSearch(),
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Gemini**:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { google } from '@ai-sdk/google'
|
|
171
|
+
import { Agent } from '@mastra/core/agent'
|
|
172
|
+
|
|
173
|
+
export const searchAgent = new Agent({
|
|
174
|
+
id: 'search-agent',
|
|
175
|
+
name: 'Search Agent',
|
|
176
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
177
|
+
model: 'google/gemini-2.5-flash',
|
|
178
|
+
tools: {
|
|
179
|
+
webSearch: google.tools.googleSearch({
|
|
180
|
+
mode: 'MODE_DYNAMIC',
|
|
181
|
+
}),
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
4. In your `src/mastra/index.ts` file, register the agent:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { Mastra } from '@mastra/core'
|
|
190
|
+
import { searchAgent } from './agents/searchAgent'
|
|
191
|
+
|
|
192
|
+
export const mastra = new Mastra({
|
|
193
|
+
agents: { searchAgent },
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
5. You can test your agent with [Studio](https://mastra.ai/docs/getting-started/studio) using the `mastra dev` command:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
mastra dev
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Inside Studio navigate to the **"Search Agent"** and ask it: "What happened last week in AI news?"
|
|
204
|
+
|
|
205
|
+
## Using Search APIs
|
|
206
|
+
|
|
207
|
+
For more control over search behavior, you can integrate external search APIs as custom tools. [Exa](https://exa.ai/) is a search engine built specifically for AI applications, offering semantic search, configurable filters (category, domain, date range), and the ability to retrieve full page contents. The search API is wrapped in a Mastra tool that defines the input schema, output format, and execution logic.
|
|
208
|
+
|
|
209
|
+
1. Install dependencies
|
|
210
|
+
|
|
211
|
+
**npm**:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm install exa-js
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**pnpm**:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
pnpm add exa-js
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Yarn**:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
yarn add exa-js
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Bun**:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
bun add exa-js
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
2. Create a new file `src/mastra/agents/searchAgent.ts` and define your agent:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { Agent } from '@mastra/core/agent'
|
|
239
|
+
|
|
240
|
+
export const searchAgent = new Agent({
|
|
241
|
+
id: 'search-agent',
|
|
242
|
+
name: 'Search Agent',
|
|
243
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
244
|
+
model: 'openai/gpt-5.1',
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
3. Setup the tool
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { createTool } from '@mastra/core/tools'
|
|
252
|
+
import z from 'zod'
|
|
253
|
+
import Exa from 'exa-js'
|
|
254
|
+
|
|
255
|
+
export const exa = new Exa(process.env.EXA_API_KEY)
|
|
256
|
+
|
|
257
|
+
export const webSearch = createTool({
|
|
258
|
+
id: 'exa-web-search',
|
|
259
|
+
description: 'Search the web',
|
|
260
|
+
inputSchema: z.object({
|
|
261
|
+
query: z.string().min(1).max(50).describe('The search query'),
|
|
262
|
+
}),
|
|
263
|
+
outputSchema: z.array(
|
|
264
|
+
z.object({
|
|
265
|
+
title: z.string().nullable(),
|
|
266
|
+
url: z.string(),
|
|
267
|
+
content: z.string(),
|
|
268
|
+
publishedDate: z.string().optional(),
|
|
269
|
+
}),
|
|
270
|
+
),
|
|
271
|
+
execute: async inputData => {
|
|
272
|
+
const { results } = await exa.searchAndContents(inputData.query, {
|
|
273
|
+
livecrawl: 'always',
|
|
274
|
+
numResults: 2,
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
return results.map(result => ({
|
|
278
|
+
title: result.title,
|
|
279
|
+
url: result.url,
|
|
280
|
+
content: result.text.slice(0, 500),
|
|
281
|
+
publishedDate: result.publishedDate,
|
|
282
|
+
}))
|
|
283
|
+
},
|
|
284
|
+
})
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
4. Add to your Agent
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { webSearch } from './tools/searchTool'
|
|
291
|
+
|
|
292
|
+
export const searchAgent = new Agent({
|
|
293
|
+
id: 'search-agent',
|
|
294
|
+
name: 'Search Agent',
|
|
295
|
+
instructions: 'You are a search agent that can search the web for information.',
|
|
296
|
+
model: 'openai/gpt-5.1',
|
|
297
|
+
tools: {
|
|
298
|
+
webSearch,
|
|
299
|
+
},
|
|
300
|
+
})
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
5. In your `src/mastra/index.ts` file, register the agent:
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
import { Mastra } from '@mastra/core'
|
|
307
|
+
import { searchAgent } from './agents/searchAgent'
|
|
308
|
+
|
|
309
|
+
export const mastra = new Mastra({
|
|
310
|
+
agents: { searchAgent },
|
|
311
|
+
})
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
6. You can test your agent with [Studio](https://mastra.ai/docs/getting-started/studio) using the `mastra dev` command:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
mastra dev
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Inside Studio navigate to the **"Search Agent"** and ask it: "What happened last week in AI news?"
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# WhatsApp Chat Bot
|
|
2
|
+
|
|
3
|
+
This guide demonstrates how to create a WhatsApp chat bot using Mastra agents and workflows. The bot receives incoming WhatsApp messages via webhook, processes them through an AI agent, breaks responses into natural text messages, and sends them back via the WhatsApp Business API.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
This example requires a WhatsApp Business API setup and uses the `anthropic` model. Add these environment variables to your `.env` file:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ANTHROPIC_API_KEY=<your-anthropic-api-key>
|
|
11
|
+
WHATSAPP_VERIFY_TOKEN=<your-verify-token>
|
|
12
|
+
WHATSAPP_ACCESS_TOKEN=<your-whatsapp-access-token>
|
|
13
|
+
WHATSAPP_BUSINESS_PHONE_NUMBER_ID=<your-phone-number-id>
|
|
14
|
+
WHATSAPP_API_VERSION=v22.0
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Creating the WhatsApp client
|
|
18
|
+
|
|
19
|
+
This client handles sending messages to users via the WhatsApp Business API.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// Simple WhatsApp Business API client for sending messages
|
|
23
|
+
|
|
24
|
+
interface SendMessageParams {
|
|
25
|
+
to: string
|
|
26
|
+
message: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function sendWhatsAppMessage({ to, message }: SendMessageParams) {
|
|
30
|
+
// Get environment variables for WhatsApp API
|
|
31
|
+
const apiVersion = process.env.WHATSAPP_API_VERSION || 'v22.0'
|
|
32
|
+
const phoneNumberId = process.env.WHATSAPP_BUSINESS_PHONE_NUMBER_ID
|
|
33
|
+
const accessToken = process.env.WHATSAPP_ACCESS_TOKEN
|
|
34
|
+
|
|
35
|
+
// Check if required environment variables are set
|
|
36
|
+
if (!phoneNumberId || !accessToken) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// WhatsApp Business API endpoint
|
|
41
|
+
const url = `https://graph.facebook.com/${apiVersion}/${phoneNumberId}/messages`
|
|
42
|
+
|
|
43
|
+
// Message payload following WhatsApp API format
|
|
44
|
+
const payload = {
|
|
45
|
+
messaging_product: 'whatsapp',
|
|
46
|
+
recipient_type: 'individual',
|
|
47
|
+
to: to,
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: {
|
|
50
|
+
body: message,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
// Send message via WhatsApp Business API
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: {
|
|
59
|
+
'Content-Type': 'application/json',
|
|
60
|
+
Authorization: `Bearer ${accessToken}`,
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify(payload),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const result = await response.json()
|
|
66
|
+
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
console.log(`✅ WhatsApp message sent to ${to}: "${message}"`)
|
|
69
|
+
return true
|
|
70
|
+
} else {
|
|
71
|
+
console.error('❌ Failed to send WhatsApp message:', result)
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('❌ Error sending WhatsApp message:', error)
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Creating the chat agent
|
|
82
|
+
|
|
83
|
+
This agent handles the main conversation logic with a friendly, conversational personality.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { Agent } from '@mastra/core/agent'
|
|
87
|
+
import { Memory } from '@mastra/memory'
|
|
88
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
89
|
+
|
|
90
|
+
export const chatAgent = new Agent({
|
|
91
|
+
id: 'chat-agent',
|
|
92
|
+
name: 'Chat Agent',
|
|
93
|
+
instructions: `
|
|
94
|
+
You are a helpful, friendly, and knowledgeable AI assistant that loves to chat with users via WhatsApp.
|
|
95
|
+
|
|
96
|
+
Your personality:
|
|
97
|
+
- Warm, approachable, and conversational
|
|
98
|
+
- Enthusiastic about helping with any topic
|
|
99
|
+
- Use a casual, friendly tone like you're chatting with a friend
|
|
100
|
+
- Be concise but informative
|
|
101
|
+
- Show genuine interest in the user's questions
|
|
102
|
+
|
|
103
|
+
Your capabilities:
|
|
104
|
+
- Answer questions on a wide variety of topics
|
|
105
|
+
- Provide helpful advice and suggestions
|
|
106
|
+
- Engage in casual conversation
|
|
107
|
+
- Help with problem-solving and creative tasks
|
|
108
|
+
- Explain complex topics in simple terms
|
|
109
|
+
|
|
110
|
+
Guidelines:
|
|
111
|
+
- Keep responses informative but not overwhelming
|
|
112
|
+
- Ask follow-up questions when appropriate
|
|
113
|
+
- Be encouraging and positive
|
|
114
|
+
- If you don't know something, admit it honestly
|
|
115
|
+
- Adapt your communication style to match the user's tone
|
|
116
|
+
- Remember this is WhatsApp, so keep it conversational and natural
|
|
117
|
+
|
|
118
|
+
Always aim to be helpful while maintaining a friendly, approachable conversation style.
|
|
119
|
+
`,
|
|
120
|
+
model: 'anthropic/claude-4-sonnet-20250514',
|
|
121
|
+
memory: new Memory({
|
|
122
|
+
storage: new LibSQLStore({
|
|
123
|
+
id: 'agent-storage',
|
|
124
|
+
url: 'file:../mastra.db',
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Creating the text message agent
|
|
131
|
+
|
|
132
|
+
This agent converts longer responses into natural, bite-sized text messages suitable for WhatsApp.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { Agent } from '@mastra/core/agent'
|
|
136
|
+
import { Memory } from '@mastra/memory'
|
|
137
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
138
|
+
|
|
139
|
+
export const textMessageAgent = new Agent({
|
|
140
|
+
id: 'text-message-agent',
|
|
141
|
+
name: 'Text Message Agent',
|
|
142
|
+
instructions: `
|
|
143
|
+
You are a text message converter that takes formal or lengthy text and breaks it down into natural, casual text messages.
|
|
144
|
+
|
|
145
|
+
Your job is to:
|
|
146
|
+
- Convert any input text into 5-8 short, casual text messages
|
|
147
|
+
- Each message should be 1-2 sentences maximum
|
|
148
|
+
- Use natural, friendly texting language (contractions, casual tone)
|
|
149
|
+
- Maintain all the important information from the original text
|
|
150
|
+
- Make it feel like you're texting a friend
|
|
151
|
+
- Use appropriate emojis sparingly to add personality
|
|
152
|
+
- Keep the conversational flow logical and easy to follow
|
|
153
|
+
|
|
154
|
+
Think of it like you're explaining something exciting to a friend via text - break it into bite-sized, engaging messages that don't overwhelm them with a long paragraph.
|
|
155
|
+
|
|
156
|
+
Always return exactly 5-8 messages in the messages array.
|
|
157
|
+
`,
|
|
158
|
+
model: 'anthropic/claude-4-sonnet-20250514',
|
|
159
|
+
memory: new Memory({
|
|
160
|
+
storage: new LibSQLStore({
|
|
161
|
+
id: 'agent-storage',
|
|
162
|
+
url: 'file:../mastra.db',
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
})
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Creating the chat workflow
|
|
169
|
+
|
|
170
|
+
This workflow orchestrates the entire chat process: generating a response, breaking it into messages, and sending them via WhatsApp.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows'
|
|
174
|
+
import { z } from 'zod'
|
|
175
|
+
import { sendWhatsAppMessage } from '../../whatsapp-client'
|
|
176
|
+
|
|
177
|
+
const respondToMessage = createStep({
|
|
178
|
+
id: 'respond-to-message',
|
|
179
|
+
description: 'Generate response to user message',
|
|
180
|
+
inputSchema: z.object({ userMessage: z.string() }),
|
|
181
|
+
outputSchema: z.object({ response: z.string() }),
|
|
182
|
+
execute: async ({ inputData, mastra }) => {
|
|
183
|
+
const agent = mastra?.getAgent('chatAgent')
|
|
184
|
+
if (!agent) {
|
|
185
|
+
throw new Error('Chat agent not found')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const response = await agent.generate([{ role: 'user', content: inputData.userMessage }])
|
|
189
|
+
|
|
190
|
+
return { response: response.text }
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const breakIntoMessages = createStep({
|
|
195
|
+
id: 'break-into-messages',
|
|
196
|
+
description: 'Breaks response into text messages',
|
|
197
|
+
inputSchema: z.object({ prompt: z.string() }),
|
|
198
|
+
outputSchema: z.object({ messages: z.array(z.string()) }),
|
|
199
|
+
execute: async ({ inputData, mastra }) => {
|
|
200
|
+
const agent = mastra?.getAgent('textMessageAgent')
|
|
201
|
+
if (!agent) {
|
|
202
|
+
throw new Error('Text Message agent not found')
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const response = await agent.generate([{ role: 'user', content: inputData.prompt }], {
|
|
206
|
+
structuredOutput: {
|
|
207
|
+
schema: z.object({
|
|
208
|
+
messages: z.array(z.string()),
|
|
209
|
+
}),
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
if (!response.object) throw new Error('Error generating messages')
|
|
214
|
+
|
|
215
|
+
return response.object
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
const sendMessages = createStep({
|
|
220
|
+
id: 'send-messages',
|
|
221
|
+
description: 'Sends text messages via WhatsApp',
|
|
222
|
+
inputSchema: z.object({
|
|
223
|
+
messages: z.array(z.string()),
|
|
224
|
+
userPhone: z.string(),
|
|
225
|
+
}),
|
|
226
|
+
outputSchema: z.object({ sentCount: z.number() }),
|
|
227
|
+
execute: async ({ inputData }) => {
|
|
228
|
+
const { messages, userPhone } = inputData
|
|
229
|
+
|
|
230
|
+
console.log(`\n🔥 Sending ${messages.length} WhatsApp messages to ${userPhone}...`)
|
|
231
|
+
|
|
232
|
+
let sentCount = 0
|
|
233
|
+
|
|
234
|
+
// Send each message with a small delay for natural flow
|
|
235
|
+
for (let i = 0; i < messages.length; i++) {
|
|
236
|
+
const success = await sendWhatsAppMessage({
|
|
237
|
+
to: userPhone,
|
|
238
|
+
message: messages[i],
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
if (success) {
|
|
242
|
+
sentCount++
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Add delay between messages for natural texting rhythm
|
|
246
|
+
if (i < messages.length - 1) {
|
|
247
|
+
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
console.log(`\n✅ Successfully sent ${sentCount}/${messages.length} WhatsApp messages\n`)
|
|
252
|
+
|
|
253
|
+
return { sentCount }
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
export const chatWorkflow = createWorkflow({
|
|
258
|
+
id: 'chat-workflow',
|
|
259
|
+
inputSchema: z.object({ userMessage: z.string() }),
|
|
260
|
+
outputSchema: z.object({ sentCount: z.number() }),
|
|
261
|
+
})
|
|
262
|
+
.then(respondToMessage)
|
|
263
|
+
.map(async ({ inputData }) => ({
|
|
264
|
+
prompt: `Break this AI response into 3-8 casual, friendly text messages that feel natural for WhatsApp conversation:\n\n${inputData.response}`,
|
|
265
|
+
}))
|
|
266
|
+
.then(breakIntoMessages)
|
|
267
|
+
.map(async ({ inputData, getInitData }) => {
|
|
268
|
+
// Parse the original stringified input to get user phone
|
|
269
|
+
const initData = getInitData<typeof chatWorkflow>()
|
|
270
|
+
const webhookData = JSON.parse(initData.userMessage)
|
|
271
|
+
const userPhone = webhookData.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.from || 'unknown'
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
messages: inputData.messages,
|
|
275
|
+
userPhone,
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
.then(sendMessages)
|
|
279
|
+
|
|
280
|
+
chatWorkflow.commit()
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Setting up Mastra configuration
|
|
284
|
+
|
|
285
|
+
Configure your Mastra instance with the agents, workflow, and WhatsApp webhook endpoints.
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { Mastra } from '@mastra/core'
|
|
289
|
+
import { registerApiRoute } from '@mastra/core/server'
|
|
290
|
+
import { PinoLogger } from '@mastra/loggers'
|
|
291
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
292
|
+
|
|
293
|
+
import { chatWorkflow } from './workflows/chat-workflow'
|
|
294
|
+
import { textMessageAgent } from './agents/text-message-agent'
|
|
295
|
+
import { chatAgent } from './agents/chat-agent'
|
|
296
|
+
|
|
297
|
+
export const mastra = new Mastra({
|
|
298
|
+
workflows: { chatWorkflow },
|
|
299
|
+
agents: { textMessageAgent, chatAgent },
|
|
300
|
+
storage: new LibSQLStore({
|
|
301
|
+
id: 'agent-storage',
|
|
302
|
+
url: ':memory:',
|
|
303
|
+
}),
|
|
304
|
+
logger: new PinoLogger({
|
|
305
|
+
name: 'Mastra',
|
|
306
|
+
level: 'info',
|
|
307
|
+
}),
|
|
308
|
+
server: {
|
|
309
|
+
apiRoutes: [
|
|
310
|
+
registerApiRoute('/whatsapp', {
|
|
311
|
+
method: 'GET',
|
|
312
|
+
handler: async c => {
|
|
313
|
+
const verifyToken = process.env.WHATSAPP_VERIFY_TOKEN
|
|
314
|
+
const {
|
|
315
|
+
'hub.mode': mode,
|
|
316
|
+
'hub.challenge': challenge,
|
|
317
|
+
'hub.verify_token': token,
|
|
318
|
+
} = c.req.query()
|
|
319
|
+
|
|
320
|
+
if (mode === 'subscribe' && token === verifyToken) {
|
|
321
|
+
return c.text(challenge, 200)
|
|
322
|
+
} else {
|
|
323
|
+
return c.status(403)
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
}),
|
|
327
|
+
registerApiRoute('/whatsapp', {
|
|
328
|
+
method: 'POST',
|
|
329
|
+
handler: async c => {
|
|
330
|
+
const mastra = c.get('mastra')
|
|
331
|
+
const chatWorkflow = mastra.getWorkflow('chatWorkflow')
|
|
332
|
+
|
|
333
|
+
const body = await c.req.json()
|
|
334
|
+
|
|
335
|
+
const workflowRun = await chatWorkflow.createRun()
|
|
336
|
+
const runResult = await workflowRun.start({
|
|
337
|
+
inputData: { userMessage: JSON.stringify(body) },
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
return c.json(runResult)
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Testing the chat bot
|
|
349
|
+
|
|
350
|
+
You can test the chat bot locally by simulating a WhatsApp webhook payload.
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import 'dotenv/config'
|
|
354
|
+
|
|
355
|
+
import { mastra } from './mastra'
|
|
356
|
+
|
|
357
|
+
// Simulate a WhatsApp webhook payload
|
|
358
|
+
const mockWebhookData = {
|
|
359
|
+
entry: [
|
|
360
|
+
{
|
|
361
|
+
changes: [
|
|
362
|
+
{
|
|
363
|
+
value: {
|
|
364
|
+
messages: [
|
|
365
|
+
{
|
|
366
|
+
from: '1234567890', // Test phone number
|
|
367
|
+
text: {
|
|
368
|
+
body: 'Hello! How are you today?',
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const workflow = mastra.getWorkflow('chatWorkflow')
|
|
380
|
+
const workflowRun = await workflow.createRun()
|
|
381
|
+
|
|
382
|
+
const result = await workflowRun.start({
|
|
383
|
+
inputData: { userMessage: JSON.stringify(mockWebhookData) },
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
console.log('Workflow completed:', result)
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Example output
|
|
390
|
+
|
|
391
|
+
When a user sends "Hello! How are you today?" to your WhatsApp bot, it might respond with multiple messages like:
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
Hey there! 👋 I'm doing great, thanks for asking!
|
|
395
|
+
|
|
396
|
+
How's your day going so far?
|
|
397
|
+
|
|
398
|
+
I'm here and ready to chat about whatever's on your mind
|
|
399
|
+
|
|
400
|
+
Whether you need help with something or just want to talk, I'm all ears! 😊
|
|
401
|
+
|
|
402
|
+
What's new with you?
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
The bot maintains conversation context through memory and delivers responses that feel natural for WhatsApp messaging.
|