@mastra/mcp-docs-server 1.2.17-alpha.9 → 1.2.18-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/course/02-agent-tools-mcp/32-conclusion.md +1 -1
- package/.docs/docs/agents/code-mode.md +3 -3
- package/.docs/docs/agents/guardrails.md +1 -1
- package/.docs/docs/agents/{agent-approval.md → human-in-the-loop.md} +5 -5
- package/.docs/docs/agents/networks.md +3 -3
- package/.docs/docs/agents/overview.md +7 -7
- package/.docs/docs/agents/processors.md +3 -3
- package/.docs/docs/agents/{using-tools.md → tools.md} +7 -7
- package/.docs/docs/{server/auth → auth}/custom-auth-provider.md +1 -1
- package/.docs/docs/{server/auth → auth}/fga.md +27 -1
- package/.docs/docs/{server/auth.md → auth/overview.md} +4 -4
- package/.docs/docs/{server/auth → auth}/simple-auth.md +1 -1
- package/.docs/docs/{server/auth → auth}/workers.md +2 -2
- package/.docs/docs/{capabilities/channels.md → channels.md} +2 -2
- package/.docs/docs/{agents → connections}/a2a.md +2 -2
- package/.docs/docs/{agents → connections}/acp.md +18 -6
- package/.docs/docs/{mcp/overview.md → connections/mcp.md} +1 -1
- package/.docs/docs/connections/overview.md +5 -5
- package/.docs/docs/{agents → connections}/sdk-agents.md +3 -1
- package/.docs/docs/deployment/cloud-providers.md +1 -0
- package/.docs/docs/deployment/mastra-server.md +2 -2
- package/.docs/docs/deployment/overview.md +2 -1
- package/.docs/docs/deployment/sandbox.md +3 -3
- package/.docs/docs/deployment/workers.md +4 -4
- package/.docs/docs/guides/context-engineering.md +297 -0
- package/.docs/docs/guides/multi-agent-systems.md +7 -7
- package/.docs/docs/guides/streaming.md +1 -1
- package/.docs/docs/harness/agent-controller.md +5 -3
- package/.docs/docs/{long-running-agents → harness}/background-tasks.md +5 -5
- package/.docs/docs/{long-running-agents → harness}/durable-agents.md +18 -2
- package/.docs/docs/{long-running-agents → harness}/goals.md +6 -6
- package/.docs/docs/harness/overview.md +11 -10
- package/.docs/docs/{long-running-agents → harness}/schedules.md +5 -5
- package/.docs/docs/{long-running-agents → harness}/signal-providers.md +4 -4
- package/.docs/docs/mastra-platform/deploy.md +1 -1
- package/.docs/docs/mastra-platform/overview.md +1 -1
- package/.docs/docs/mastra-platform/server.md +1 -1
- package/.docs/docs/memory/message-history.md +1 -1
- package/.docs/docs/memory/overview.md +4 -4
- package/.docs/docs/memory/working-memory.md +1 -1
- package/.docs/docs/observability/integrations/exporters/mastra-storage.md +1 -1
- package/.docs/docs/{workspace → sandbox}/filesystem.md +2 -2
- package/.docs/docs/{workspace → sandbox}/lsp.md +3 -3
- package/.docs/docs/{workspace/sandbox.md → sandbox/overview.md} +4 -3
- package/.docs/docs/{workspace → sandbox}/search.md +2 -2
- package/.docs/docs/{workspace → sandbox}/skills.md +5 -5
- package/.docs/docs/server/custom-api-routes.md +2 -2
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/{mastra-server.md → overview.md} +3 -3
- package/.docs/docs/server/pubsub.md +2 -2
- package/.docs/docs/server/server-adapters.md +4 -4
- package/.docs/docs/{agents/skills.md → skills.md} +4 -4
- package/.docs/docs/{storage/overview.md → storage.md} +2 -1
- package/.docs/docs/studio/auth.md +4 -4
- package/.docs/docs/studio/overview.md +2 -2
- package/.docs/docs/{capabilities/subagents.md → subagents.md} +35 -5
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/control-flow.md +0 -4
- package/.docs/docs/workflows/human-in-the-loop.md +0 -4
- package/.docs/docs/workflows/overview.md +1 -1
- package/.docs/docs/workflows/scheduled-workflows.md +2 -2
- package/.docs/docs/workflows/snapshots.md +1 -1
- package/.docs/docs/workflows/suspend-and-resume.md +0 -4
- package/.docs/integrations/agentic-ui/ai-sdk-ui.md +1 -1
- package/.docs/integrations/agentic-ui/copilotkit.md +1 -1
- package/.docs/integrations/auth/google.md +2 -2
- package/.docs/integrations/auth/workos.md +1 -1
- package/.docs/integrations/browsers/agent-browser.md +2 -2
- package/.docs/integrations/browsers/browser-viewer.md +6 -6
- package/.docs/integrations/browsers/firecrawl.md +1 -1
- package/.docs/integrations/browsers/stagehand.md +2 -2
- package/.docs/integrations/channels/discord.md +2 -2
- package/.docs/integrations/channels/github.md +1 -1
- package/.docs/integrations/channels/imessage.md +4 -4
- package/.docs/integrations/channels/slack.md +5 -5
- package/.docs/integrations/channels/teams.md +2 -2
- package/.docs/integrations/channels/telegram.md +2 -2
- package/.docs/integrations/channels/whatsapp.md +2 -2
- package/.docs/integrations/databases/postgresql.md +1 -0
- package/.docs/integrations/deploy/amazon-ec2.md +2 -2
- package/.docs/integrations/deploy/aws-lambda.md +3 -3
- package/.docs/integrations/deploy/azure-app-services.md +2 -2
- package/.docs/integrations/deploy/cloudflare.md +2 -2
- package/.docs/integrations/deploy/digital-ocean.md +3 -3
- package/.docs/integrations/deploy/kubernetes.md +11 -11
- package/.docs/integrations/deploy/netlify.md +3 -3
- package/.docs/integrations/deploy/render.md +389 -0
- package/.docs/integrations/deploy/vercel.md +2 -2
- package/.docs/integrations/file-storage/amazon-s3.md +1 -1
- package/.docs/integrations/file-storage/azure-blob.md +1 -1
- package/.docs/integrations/file-storage/google-cloud-storage.md +1 -1
- package/.docs/integrations/file-storage/mesa.md +2 -2
- package/.docs/integrations/file-storage/vercel-files.md +1 -1
- package/.docs/integrations/frameworks/astro.md +6 -2
- package/.docs/integrations/frameworks/electron.md +1 -1
- package/.docs/integrations/frameworks/express.md +1 -1
- package/.docs/integrations/frameworks/hono.md +1 -1
- package/.docs/integrations/frameworks/nestjs.md +1 -1
- package/.docs/integrations/frameworks/next-js.md +6 -2
- package/.docs/integrations/frameworks/nuxt.md +1 -1
- package/.docs/integrations/frameworks/sveltekit.md +1 -1
- package/.docs/integrations/frameworks/vite-react.md +6 -2
- package/.docs/integrations/sandboxes/agentcore.md +1 -1
- package/.docs/integrations/sandboxes/apple-container.md +1 -1
- package/.docs/integrations/sandboxes/cloudflare-sandbox.md +118 -0
- package/.docs/integrations/sandboxes/daytona.md +1 -1
- package/.docs/integrations/sandboxes/docker.md +4 -3
- package/.docs/integrations/sandboxes/e2b.md +1 -1
- package/.docs/integrations/sandboxes/modal.md +1 -1
- package/.docs/integrations/sandboxes/railway.md +11 -0
- package/.docs/integrations.md +4 -0
- package/.docs/models/environment-variables.md +9 -2
- package/.docs/models/gateways/merge-gateway.md +212 -0
- package/.docs/models/gateways/openrouter.md +3 -1
- package/.docs/models/gateways/vercel.md +22 -1
- package/.docs/models/gateways.md +1 -0
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/alibaba-token-plan-cn.md +2 -1
- package/.docs/models/providers/alibaba-token-plan.md +2 -1
- package/.docs/models/providers/ambient.md +2 -2
- package/.docs/models/providers/amd.md +73 -0
- package/.docs/models/providers/arcee.md +79 -0
- package/.docs/models/providers/baseten.md +1 -1
- package/.docs/models/providers/cerebras.md +2 -3
- package/.docs/models/providers/chutes.md +2 -1
- package/.docs/models/providers/cloudflare-workers-ai.md +3 -2
- package/.docs/models/providers/cortecs.md +2 -1
- package/.docs/models/providers/crof.md +1 -1
- package/.docs/models/providers/crossmodel.md +3 -2
- package/.docs/models/providers/deepinfra.md +5 -1
- package/.docs/models/providers/digitalocean.md +3 -2
- package/.docs/models/providers/echo.md +73 -0
- package/.docs/models/providers/edenai.md +26 -11
- package/.docs/models/providers/empiriolabs.md +11 -1
- package/.docs/models/providers/hetzner.md +6 -8
- package/.docs/models/providers/huggingface.md +4 -1
- package/.docs/models/providers/hyper.md +8 -7
- package/.docs/models/providers/inferx.md +19 -13
- package/.docs/models/providers/jalapeno.md +89 -0
- package/.docs/models/providers/kilo.md +12 -11
- package/.docs/models/providers/kosmik.md +73 -0
- package/.docs/models/providers/llmgateway.md +3 -3
- package/.docs/models/providers/llmtr.md +35 -10
- package/.docs/models/providers/nano-gpt.md +13 -17
- package/.docs/models/providers/ofox.md +8 -4
- package/.docs/models/providers/opencode-go.md +23 -22
- package/.docs/models/providers/requesty.md +143 -53
- package/.docs/models/providers/runinfra.md +76 -0
- package/.docs/models/providers/sakana.md +3 -2
- package/.docs/models/providers/scnet-token-plan.md +85 -0
- package/.docs/models/providers/scx-ai.md +76 -0
- package/.docs/models/providers/togetherai.md +2 -1
- package/.docs/models/providers/umans-ai-coding-plan.md +2 -1
- package/.docs/models/providers/umans-ai.md +2 -1
- package/.docs/models/providers/vivgrid.md +2 -1
- package/.docs/models/providers/wandb.md +2 -1
- package/.docs/models/providers/xai.md +2 -1
- package/.docs/models/providers.md +8 -2
- package/.docs/reference/acp/acp-agent.md +2 -2
- package/.docs/reference/acp/create-acp-tool.md +1 -1
- package/.docs/reference/agent-controller/agent-controller-class.md +2 -2
- package/.docs/reference/agents/agent.md +2 -2
- package/.docs/reference/agents/channels.md +2 -2
- package/.docs/reference/agents/createSkill.md +2 -2
- package/.docs/reference/agents/durable-agent.md +1 -1
- package/.docs/reference/agents/generate.md +3 -1
- package/.docs/reference/agents/getSkill.md +1 -1
- package/.docs/reference/agents/listSkills.md +1 -1
- package/.docs/reference/agents/listSuspendedRuns.md +6 -6
- package/.docs/reference/agents/listTools.md +2 -2
- package/.docs/reference/agents/network.md +3 -1
- package/.docs/reference/ai-sdk/chat-route.md +1 -1
- package/.docs/reference/ai-sdk/handle-chat-stream.md +1 -1
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -2
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +1 -1
- package/.docs/reference/ai-sdk/network-route.md +2 -2
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +1 -1
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +1 -1
- package/.docs/reference/ai-sdk/workflow-route.md +1 -1
- package/.docs/reference/auth/fga.md +7 -5
- package/.docs/reference/auth/jwt.md +1 -1
- package/.docs/reference/browser/agent-browser.md +2 -2
- package/.docs/reference/browser/browser-viewer.md +2 -2
- package/.docs/reference/browser/firecrawl-browser.md +1 -1
- package/.docs/reference/browser/mastra-browser.md +1 -1
- package/.docs/reference/browser/stagehand-browser.md +2 -2
- package/.docs/reference/build-with-ai.md +2 -2
- package/.docs/reference/channels/channel-provider.md +1 -1
- package/.docs/reference/channels/slack-provider.md +1 -1
- package/.docs/reference/cli/mastra.md +2 -0
- package/.docs/reference/client-js/agents.md +24 -4
- package/.docs/reference/coding-agent/create-coding-agent.md +142 -13
- package/.docs/reference/configuration.md +6 -6
- package/.docs/reference/core/getEditor.md +1 -1
- package/.docs/reference/core/getMCPServer.md +1 -1
- package/.docs/reference/core/getMCPServerById.md +1 -1
- package/.docs/reference/core/getTool.md +1 -1
- package/.docs/reference/core/getToolById.md +1 -1
- package/.docs/reference/core/listMCPServers.md +1 -1
- package/.docs/reference/core/listTools.md +1 -1
- package/.docs/reference/core/removeWorkspace.md +1 -1
- package/.docs/reference/editor/mastra-editor.md +2 -2
- package/.docs/reference/editor/prompt-blocks.md +2 -2
- package/.docs/reference/editor/tool-provider.md +108 -1
- package/.docs/reference/editor/tools.md +1 -1
- package/.docs/reference/editor/versioning.md +3 -3
- package/.docs/reference/evals/prompt-alignment.md +18 -0
- package/.docs/reference/evals/rubric.md +1 -1
- package/.docs/reference/file-based-agents/memory.md +2 -2
- package/.docs/reference/file-based-agents/server.md +3 -3
- package/.docs/reference/file-based-agents/skills.md +1 -1
- package/.docs/reference/file-based-agents/storage.md +3 -3
- package/.docs/reference/file-based-agents/subagents.md +1 -1
- package/.docs/reference/file-based-agents/workspace.md +3 -3
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/manual-install.md +3 -3
- package/.docs/reference/memory/memory-class.md +1 -0
- package/.docs/reference/memory/settled.md +57 -0
- package/.docs/reference/migrations/network-to-supervisor.md +2 -2
- package/.docs/reference/processors/provider-history-compat.md +6 -5
- package/.docs/reference/processors/skill-search-processor.md +3 -1
- package/.docs/reference/processors/token-limiter-processor.md +4 -0
- package/.docs/reference/processors/tool-call-filter.md +7 -7
- package/.docs/reference/processors/tool-search-processor.md +1 -1
- package/.docs/reference/project-structure.md +1 -1
- package/.docs/reference/pubsub/lease-provider.md +3 -3
- package/.docs/reference/pubsub/redis-streams.md +1 -1
- package/.docs/reference/rag/graph-rag.md +71 -8
- package/.docs/reference/rag/retrieval.md +26 -18
- package/.docs/reference/schedules/overview.md +1 -1
- package/.docs/reference/streaming/ChunkType.md +2 -2
- package/.docs/reference/streaming/agents/stream.md +29 -4
- package/.docs/reference/streaming/agents/streamUntilIdle.md +1 -1
- package/.docs/reference/tools/ask-user-tool.md +1 -1
- package/.docs/reference/tools/create-code-mode.md +1 -1
- package/.docs/reference/tools/create-tool.md +4 -4
- package/.docs/reference/tools/mcp-client.md +2 -0
- package/.docs/reference/tools/mcp-server.md +97 -4
- package/.docs/reference/tools/submit-plan-tool.md +1 -1
- package/.docs/reference/tools/task-tools.md +2 -2
- package/.docs/reference/vectors/vectorize.md +12 -2
- package/.docs/reference/workers/overview.md +2 -2
- package/.docs/reference/workflows/run-methods/resume.md +21 -0
- package/.docs/reference/workspace/local-filesystem.md +1 -1
- package/.docs/reference/workspace/local-sandbox.md +4 -3
- package/.docs/reference/workspace/platform-sandbox.md +11 -0
- package/.docs/reference/workspace/process-manager.md +20 -4
- package/.docs/reference/workspace/sandbox.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +5 -5
- package/CHANGELOG.md +81 -0
- package/package.json +6 -6
- package/.docs/models/providers/merge-gateway.md +0 -265
- /package/.docs/docs/{server/auth → auth}/composite-auth.md +0 -0
- /package/.docs/docs/{server/auth → auth}/jwt.md +0 -0
- /package/.docs/docs/{browser/overview.md → browser.md} +0 -0
- /package/.docs/docs/{getting-started/develop.md → develop.md} +0 -0
- /package/.docs/docs/{long-running-agents → harness}/signals.md +0 -0
- /package/.docs/docs/{editor/overview.md → studio/editor.md} +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Context engineering
|
|
4
|
+
|
|
5
|
+
A model can only work with the information available in its context window. That might include the current conversation, remembered details, application data, tool results, or relevant passages from a knowledge base.
|
|
6
|
+
|
|
7
|
+
Context engineering is the practice of deciding what information the model should see and when. The goal isn't to provide as much as possible, but to keep the context relevant and current. Too little context leaves the model without information it needs; too much can make important details harder to find, increase cost, and reduce the quality of the response long before the model reaches its context limit.
|
|
8
|
+
|
|
9
|
+
Mastra provides different ways to bring information into context, keep it available over time, retrieve it when needed, and reduce or isolate it as a task grows. This guide explains when to use each mechanism and how they fit together.
|
|
10
|
+
|
|
11
|
+
| Need | Start with | What the model sees |
|
|
12
|
+
| ----------------------------------------- | --------------------------------------------- | -------------------------------------------------------- |
|
|
13
|
+
| Stable identity, rules, or constraints | [Instructions](#instructions) | System context on each model call |
|
|
14
|
+
| Data from a database or API | [Tools](#tools) | Tool definitions followed by selected results |
|
|
15
|
+
| Current customer or application data | [Inline context](#inline-context) | Data interpolated into the user message |
|
|
16
|
+
| A large, stable knowledge base | [RAG](#rag) | Semantically relevant chunks from an index |
|
|
17
|
+
| User- or organization-managed documents | [Filesystems](#filesystems) | Files selected through read or search tools |
|
|
18
|
+
| Recent conversation or durable facts | [Memory](#memory) | History, observations, or retrieved memories |
|
|
19
|
+
| A long-running conversation | [Observational Memory](#observational-memory) | Dense observations plus recent unobserved messages |
|
|
20
|
+
| New events or changing state during a run | [Signals](#signals) | User, reactive, notification, or state messages |
|
|
21
|
+
| Instructions needed only for some tasks | [Dynamic skills](#dynamic-skills) | Skill metadata followed by instructions loaded on demand |
|
|
22
|
+
|
|
23
|
+
## Instructions
|
|
24
|
+
|
|
25
|
+
An agent's [`instructions`](https://mastra.ai/reference/agents/agent) define its stable identity, behavior, and constraints. They're system messages and appear before conversation messages in the model request.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Agent } from '@mastra/core/agent'
|
|
29
|
+
|
|
30
|
+
export const supportAgent = new Agent({
|
|
31
|
+
id: 'support-agent',
|
|
32
|
+
name: 'Support Agent',
|
|
33
|
+
instructions: `You help customers understand their account.
|
|
34
|
+
Today is ${new Date().toDateString()}.
|
|
35
|
+
Use plain language and don't invent account details.`,
|
|
36
|
+
model: 'openai/gpt-5.6-sol',
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Keep instructions focused on behavior that applies to most calls. Adding current account data, retrieved documents, or task-specific details makes the base prompt larger and harder to reuse.
|
|
41
|
+
|
|
42
|
+
Instructions can also be resolved at runtime from [`RequestContext`](https://mastra.ai/docs/server/request-context):
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
instructions: ({ requestContext }) => {
|
|
46
|
+
const name = requestContext.get('name')
|
|
47
|
+
|
|
48
|
+
return `You help ${name} understand their account.`
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `RequestContext` when instructions depend on data that changes with each request, such as the current user, tenant, locale, role, or feature flags. Values that don't come from the request, such as the current date, can be interpolated directly as shown in the first example.
|
|
53
|
+
|
|
54
|
+
> **Tip:** If the resolved instructions change often, the model provider may not be able to reuse the same prompt cache prefix. Keep the stable part first, and pass frequently changing background through messages or signals instead.
|
|
55
|
+
>
|
|
56
|
+
> Watch [this short video on prompt caching](https://youtu.be/eBB0dBqfvuQ) to learn how cacheable prompt prefixes reduce latency and cost.
|
|
57
|
+
|
|
58
|
+
## Inline context
|
|
59
|
+
|
|
60
|
+
Most applications pass runtime context by interpolating relevant values into the current message. This works well when your code has already loaded customer or application data:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const customer = await db.customer.findById(customerId)
|
|
64
|
+
|
|
65
|
+
await supportAgent.generate(`
|
|
66
|
+
Customer: ${customer.name}
|
|
67
|
+
Plan: ${customer.plan}
|
|
68
|
+
Question: ${question}
|
|
69
|
+
`)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Select and label the fields the model needs instead of serializing an entire database record. This keeps the prompt smaller and makes the meaning of each value clear.
|
|
73
|
+
|
|
74
|
+
When memory is enabled, Mastra saves the current user message. Don't interpolate sensitive or temporary data that shouldn't appear in conversation history.
|
|
75
|
+
|
|
76
|
+
For the less common case where background should affect one response without being saved as conversation history, pass a [`context`](https://mastra.ai/reference/agents/generate) message:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
await supportAgent.generate('Recommend the next action.', {
|
|
80
|
+
context: [{ role: 'user', content: 'The customer has an unresolved billing dispute.' }],
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The model sees this background for the current execution, but Mastra doesn't save it to memory. Use `context` when persisting the background would pollute the conversation or expose temporary application state on later turns.
|
|
85
|
+
|
|
86
|
+
## Tools
|
|
87
|
+
|
|
88
|
+
[Tools](https://mastra.ai/docs/agents/tools) are the recommended way to fetch current data from a database, API, or service. The model decides when it needs the data and supplies the tool arguments, while your application controls the query and returned fields.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createTool } from '@mastra/core/tools'
|
|
92
|
+
import { z } from 'zod'
|
|
93
|
+
|
|
94
|
+
export const getCustomer = createTool({
|
|
95
|
+
id: 'get-customer',
|
|
96
|
+
description: 'Gets the current profile and plan for a customer',
|
|
97
|
+
inputSchema: z.object({ customerId: z.string() }),
|
|
98
|
+
execute: async ({ customerId }) => {
|
|
99
|
+
const customer = await db.customer.findById(customerId)
|
|
100
|
+
return { name: customer.name, plan: customer.plan, status: customer.status }
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Use [`toModelOutput`](https://mastra.ai/docs/agents/tools) when application code needs the full result but the model needs a smaller representation.
|
|
106
|
+
|
|
107
|
+
## RAG
|
|
108
|
+
|
|
109
|
+
[Retrieval-Augmented Generation (RAG)](https://mastra.ai/reference/rag/overview) retrieves semantically relevant chunks from an indexed corpus. It still fits large, stable knowledge bases where users ask open-ended questions that don't map cleanly to structured database queries.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
113
|
+
import { createVectorQueryTool } from '@mastra/rag'
|
|
114
|
+
|
|
115
|
+
const knowledgeBase = createVectorQueryTool({
|
|
116
|
+
vectorStoreName: 'knowledgeBase',
|
|
117
|
+
indexName: 'support-docs',
|
|
118
|
+
model: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Register the vector store referenced by `vectorStoreName` on the same Mastra instance as the agent. Mastra supports [multiple vector databases](https://mastra.ai/reference/rag/vector-databases). RAG is often exposed through a tool, as in this example. The design choice is whether the agent needs semantic retrieval or can query the source directly.
|
|
123
|
+
|
|
124
|
+
Many applications now start with direct, source-specific tools. Models have become better at selecting them, and a direct query is often simpler and cheaper because it doesn't require a chunking, embedding, and vector-index pipeline. Choose RAG when semantic search over unstructured content is the actual requirement, then constrain the returned context with metadata filters, reranking, and a conservative `topK`.
|
|
125
|
+
|
|
126
|
+
## Filesystems
|
|
127
|
+
|
|
128
|
+
A [filesystem](https://mastra.ai/docs/sandbox/filesystem) gives an agent persistent access to documents and other files. Files can live in a local directory or in providers such as Amazon S3, AgentFS, or Google Drive. The agent receives built-in tools to list, read, and search them.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { LocalFilesystem, Workspace } from '@mastra/core/workspace'
|
|
132
|
+
|
|
133
|
+
export const workspace = new Workspace({
|
|
134
|
+
filesystem: new LocalFilesystem({ basePath: './knowledge-base' }),
|
|
135
|
+
bm25: true,
|
|
136
|
+
autoIndexPaths: ['**/*.md'],
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
// Agents receive tools including read_file, list_files, grep,
|
|
140
|
+
// mastra_workspace_search, and mastra_workspace_index.
|
|
141
|
+
await workspace.init()
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
[Workspace search](https://mastra.ai/docs/sandbox/search) supports BM25 keyword search, vector semantic search, or a hybrid of both. Use a filesystem for a personal assistant that works with a user's files or an organization knowledge base that teammates update in a service such as Google Drive. Search runs against the workspace index, so changed files must be indexed before the agent can retrieve their latest contents.
|
|
145
|
+
|
|
146
|
+
> **Tip:** Filesystem search can also use vectors, so it overlaps with RAG. Choose a filesystem when the source of truth is a set of files that the agent may need to list, read, or update. Choose a standalone RAG pipeline when retrieval is the main requirement and the source content doesn't need to behave like files.
|
|
147
|
+
|
|
148
|
+
## Memory
|
|
149
|
+
|
|
150
|
+
[Memory](https://mastra.ai/docs/memory/overview) gives an agent conversational coherence across turns. It brings recent messages and remembered details into context without requiring the application to resend the full transcript on every turn.
|
|
151
|
+
|
|
152
|
+
Memory requires a storage provider. Each call also identifies a `resource` that owns the memory and a `thread` that identifies the conversation. Reuse both values to continue the same conversation:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { Agent } from '@mastra/core/agent'
|
|
156
|
+
import { Memory } from '@mastra/memory'
|
|
157
|
+
|
|
158
|
+
export const assistant = new Agent({
|
|
159
|
+
id: 'assistant',
|
|
160
|
+
name: 'Assistant',
|
|
161
|
+
model: 'openai/gpt-5.6-sol',
|
|
162
|
+
memory: new Memory({
|
|
163
|
+
options: {
|
|
164
|
+
lastMessages: 20,
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
await assistant.generate('Help me plan the next project milestone.', {
|
|
170
|
+
memory: {
|
|
171
|
+
resource: 'user-123',
|
|
172
|
+
thread: 'project-456',
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The example assumes storage is configured on the registered Mastra instance or directly on `Memory`. `lastMessages` controls how many recent messages Mastra loads from the thread. The default is 10.
|
|
178
|
+
|
|
179
|
+
Message history works well for shorter conversations where recent turns contain the context the agent needs. For long-running conversations, Mastra recommends [Observational Memory](https://mastra.ai/docs/memory/observational-memory), which keeps recent conversation available and turns older history into a dense observation log.
|
|
180
|
+
|
|
181
|
+
## Observational Memory
|
|
182
|
+
|
|
183
|
+
Conversation history grows with every user message, response, and tool call. Even before it reaches the model's hard context limit, a long transcript can increase cost and make relevant details harder for the model to find. Compression replaces old, verbose history with a smaller representation.
|
|
184
|
+
|
|
185
|
+
[Observational Memory](https://mastra.ai/docs/memory/observational-memory) handles this continuously. An Observer turns older messages and tool interactions into dense observations, while periodic reflection reorganizes and compresses those observations.
|
|
186
|
+
|
|
187
|
+
You don't need to configure `lastMessages` when Observational Memory is enabled. Observational Memory manages history itself, keeping recent unobserved messages in context and replacing older messages with observations.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { Agent } from '@mastra/core/agent'
|
|
191
|
+
import { Memory } from '@mastra/memory'
|
|
192
|
+
|
|
193
|
+
export const assistant = new Agent({
|
|
194
|
+
id: 'assistant',
|
|
195
|
+
name: 'Assistant',
|
|
196
|
+
model: 'openai/gpt-5.6-sol',
|
|
197
|
+
memory: new Memory({
|
|
198
|
+
options: {
|
|
199
|
+
observationalMemory: true,
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
After messages are observed, the model receives the observation log, recent messages that haven't been observed, and a continuation reminder. The raw messages remain stored but no longer occupy the active model context.
|
|
206
|
+
|
|
207
|
+
Observations are added in stable chunks, which helps providers reuse the existing prompt prefix. Observational Memory can also activate buffered observations after a prompt cache is likely to expire or before the agent changes providers.
|
|
208
|
+
|
|
209
|
+
## Signals
|
|
210
|
+
|
|
211
|
+
> **Beta:** Signals may change without a major version bump until the API is stable.
|
|
212
|
+
|
|
213
|
+
[Signals](https://mastra.ai/docs/harness/signals) add messages or system-generated context to a memory-backed thread. Delivery depends on the thread's state: a signal can wake an idle agent or enter an active loop. It can also wait for the next turn or persist without waking the agent.
|
|
214
|
+
|
|
215
|
+
State signals require memory and an existing thread. Notification inbox signals require a storage adapter with notification support.
|
|
216
|
+
|
|
217
|
+
| API | Use | Context behavior |
|
|
218
|
+
| ------------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------- |
|
|
219
|
+
| `sendMessage()` | User input that the active agent should see now | Enters the active loop or wakes an idle thread |
|
|
220
|
+
| `queueMessage()` | User input that should wait for the next turn | Starts after the current run finishes |
|
|
221
|
+
| `sendSignal()` | Background results, policy reminders, or external events | Adds reactive or notification context according to its delivery options |
|
|
222
|
+
| `sendStateSignal()` | Browser state, editor state, task state, or another changing value | Maintains a thread-scoped state lane with snapshots and deltas |
|
|
223
|
+
|
|
224
|
+
Use `sendSignal()` for context produced by the system rather than the user:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const result = agent.sendSignal(
|
|
228
|
+
{
|
|
229
|
+
type: 'notification',
|
|
230
|
+
contents: 'CI failed on pull request 123: three tests failed.',
|
|
231
|
+
attributes: { source: 'github', pullRequest: 123 },
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
resourceId: 'user-123',
|
|
235
|
+
threadId: 'project-456',
|
|
236
|
+
},
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
await result.accepted
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
A processor can send a reactive signal during `processInputStep()`. This is useful for guidance that depends on the current step or a recent tool result. Set `transient: true` when the signal should reach only the current model call. Re-send it when needed instead of storing repeated reminders in conversation history.
|
|
243
|
+
|
|
244
|
+
State signals represent context that changes over time. Mastra tracks snapshots and deltas for each state lane and can reinsert a fresh snapshot after the previous one leaves the active context window. Use `computeStateSignal()` when a processor owns the state. Working memory, browser context, and task lists can use this lane to stay available even after history or Observational Memory removes older messages.
|
|
245
|
+
|
|
246
|
+
Signals append changing context near the current turn instead of rewriting the agent's base instructions. Transient and state signals can therefore preserve a more stable prompt prefix while keeping current guidance and state visible to the model.
|
|
247
|
+
|
|
248
|
+
## Dynamic skills
|
|
249
|
+
|
|
250
|
+
[Agent skills](https://mastra.ai/docs/skills) let an agent load task-specific instructions only when needed instead of carrying every procedure in its base instructions. Use them for specialized guidance that applies to some requests and keep the default context smaller.
|
|
251
|
+
|
|
252
|
+
## Context control
|
|
253
|
+
|
|
254
|
+
Context control limits what the model sees as a task grows. Compaction and processors reduce context within one agent, while subagent boundaries control what moves between agents.
|
|
255
|
+
|
|
256
|
+
### Compaction
|
|
257
|
+
|
|
258
|
+
If you've used Claude Code, you may have seen compaction happen during a long session. The Mastra team likes to joke, "Friends don't let friends do compaction."
|
|
259
|
+
|
|
260
|
+
Compaction waits until a conversation reaches a token threshold. It then summarizes the transcript and replaces earlier messages. It's a blunt fallback. The compaction turn adds latency, and a single summary has to represent everything that came before. Repeated summaries can flatten chronology or lose details that later become important.
|
|
261
|
+
|
|
262
|
+
Prefer [Observational Memory](#observational-memory) for long-running conversations. It can process history asynchronously in the background while preserving temporal context. Reflection revisits accumulated memories and naturally prunes details that no longer matter. Mastra doesn't provide compaction out of the box, though you could implement it with a custom [processor](https://mastra.ai/docs/agents/processors).
|
|
263
|
+
|
|
264
|
+
### Processors
|
|
265
|
+
|
|
266
|
+
[Processors](https://mastra.ai/docs/agents/processors) control what enters model context and can rewrite content before a model call. Use them when information should remain in stored history or application output but doesn't need to be sent back to the model on every step.
|
|
267
|
+
|
|
268
|
+
For example, `ToolCallFilter` removes old tool arguments and results from the next model request without deleting those messages from storage. The model gets a smaller prompt, while your application can still display or inspect the complete interaction.
|
|
269
|
+
|
|
270
|
+
Use `processInput()` or `processInputStep()` to change the active message list. Those changes may later be saved to memory. Use `processLLMRequest()` when a rewrite should apply only to the current provider call and leave memory untouched.
|
|
271
|
+
|
|
272
|
+
Mastra includes several controls for common sources of context bloat:
|
|
273
|
+
|
|
274
|
+
- [`toModelOutput`](https://mastra.ai/docs/agents/tools): Replace a verbose tool result with a smaller model-facing representation.
|
|
275
|
+
- [`ToolCallFilter`](https://mastra.ai/reference/processors/tool-call-filter): Remove old tool calls and results from model input while retaining them in memory and the UI.
|
|
276
|
+
- [`ToolSearchProcessor`](https://mastra.ai/reference/processors/tool-search-processor): Replace a large tool catalog with search and load tools.
|
|
277
|
+
- [`TokenLimiter`](https://mastra.ai/reference/processors/token-limiter-processor): Prune non-system messages until the prompt fits a token budget.
|
|
278
|
+
|
|
279
|
+
Start with [`toModelOutput`](https://mastra.ai/docs/agents/tools) for verbose tool results and `ToolCallFilter` for old tool interactions. Add `TokenLimiter` as a final budget guard rather than relying on the model's maximum context window.
|
|
280
|
+
|
|
281
|
+
### Subagents
|
|
282
|
+
|
|
283
|
+
A common source of context bloat is passing too much information to and from [subagents](https://mastra.ai/docs/subagents). A subagent gets a separate model context for its delegated task, but the boundary still needs deliberate controls.
|
|
284
|
+
|
|
285
|
+
By default, Mastra forwards the parent's conversation to the subagent. Use `messageFilter` to pass only the messages that specialist needs:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
await supervisor.generate('Investigate the failed deployment.', {
|
|
289
|
+
delegation: {
|
|
290
|
+
messageFilter: ({ messages }) => messages.slice(-10),
|
|
291
|
+
},
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
In the other direction, Mastra returns the subagent's text to the parent model by default while keeping nested tool calls and metadata available to application code. Leave `includeSubAgentToolResultsInModelContext` disabled unless the parent must reason over those details. Use `onDelegationStart` to refine the child prompt and `onDelegationComplete` to reduce or replace the text returned to the parent.
|
|
296
|
+
|
|
297
|
+
See [Subagents](https://mastra.ai/docs/subagents) for delegation hooks, memory isolation, iteration monitoring, and result controls.
|
|
@@ -44,7 +44,7 @@ A supervisor pattern keeps one lead agent in control for the full task. The supe
|
|
|
44
44
|
|
|
45
45
|
Use this pattern when the task is open-ended and the full sequence isn't known in advance. For example, a research task may require different lines of inquiry based on what earlier steps uncover. A supervisor can adapt as the task unfolds. The tradeoff is that the supervisor becomes the main coordination point. That makes the pattern flexible, but it also means the result depends heavily on good delegation behavior and clear subagent boundaries.
|
|
46
46
|
|
|
47
|
-
In Mastra, this pattern maps directly to [supervisor agents](https://mastra.ai/docs/
|
|
47
|
+
In Mastra, this pattern maps directly to [supervisor agents](https://mastra.ai/docs/subagents). A supervisor agent defines subagents on the `agents` property and uses `stream()` or `generate()` to coordinate them. Mastra also provides delegation hooks, message filtering, and memory isolation to help control this pattern.
|
|
48
48
|
|
|
49
49
|
> **Tip:** Follow the [supervisor agents tutorial](https://mastra.ai/blog/build-a-research-coordinator-with-supervisor-agents) for a step-by-step guide.
|
|
50
50
|
|
|
@@ -60,12 +60,12 @@ Mastra doesn't provide a dedicated council primitive. In Mastra, implement this
|
|
|
60
60
|
|
|
61
61
|
These patterns differ mainly in how they distribute control:
|
|
62
62
|
|
|
63
|
-
| Pattern | Who stays in control | Use when | Tradeoff | Mastra implementation
|
|
64
|
-
| ----------------- | -------------------- | ------------------------------------------------ | -------------------------------------------------------- |
|
|
65
|
-
| Handoffs | Current specialist | Ownership should move between specialists | Context transfer becomes more important | Agents with workflows and memory
|
|
66
|
-
| Workflows | Execution graph | The path is known in advance | Less adaptive when the task changes | [Workflows](https://mastra.ai/docs/workflows/overview)
|
|
67
|
-
| Supervisor agents | One lead agent | Delegation must adapt during execution | Results depend on good coordination and clear boundaries | [Supervisor agents](https://mastra.ai/docs/
|
|
68
|
-
| Council | Final synthesis step | The task needs multiple independent perspectives | Higher cost and latency | Agents with workflow parallelism
|
|
63
|
+
| Pattern | Who stays in control | Use when | Tradeoff | Mastra implementation |
|
|
64
|
+
| ----------------- | -------------------- | ------------------------------------------------ | -------------------------------------------------------- | ------------------------------------------------------ |
|
|
65
|
+
| Handoffs | Current specialist | Ownership should move between specialists | Context transfer becomes more important | Agents with workflows and memory |
|
|
66
|
+
| Workflows | Execution graph | The path is known in advance | Less adaptive when the task changes | [Workflows](https://mastra.ai/docs/workflows/overview) |
|
|
67
|
+
| Supervisor agents | One lead agent | Delegation must adapt during execution | Results depend on good coordination and clear boundaries | [Supervisor agents](https://mastra.ai/docs/subagents) |
|
|
68
|
+
| Council | Final synthesis step | The task needs multiple independent perspectives | Higher cost and latency | Agents with workflow parallelism |
|
|
69
69
|
|
|
70
70
|
In practice, these patterns are often combined:
|
|
71
71
|
|
|
@@ -31,7 +31,7 @@ for await (const chunk of stream.textStream) {
|
|
|
31
31
|
|
|
32
32
|
Visit [Agent.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
33
33
|
|
|
34
|
-
> **Tip:** For agents that dispatch [background tasks](https://mastra.ai/docs/
|
|
34
|
+
> **Tip:** For agents that dispatch [background tasks](https://mastra.ai/docs/harness/background-tasks), use [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) to keep the stream open until those tasks complete and the agent has had a chance to respond to their results.
|
|
35
35
|
|
|
36
36
|
### Output from `Agent.stream()`
|
|
37
37
|
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
[Mastra Code](https://code.mastra.ai) and [Mastra Factory](https://factory.mastra.ai) are the flagship AgentController implementations. They're coding agents with multi-model support, persistent conversations, and plan-then-execute workflows. Read [Building a coding agent](https://mastra.ai/blog/building-a-coding-agent) for a step-by-step TUI guide.
|
|
10
10
|
|
|
11
|
+
When the agent you host works in a codebase, build it with [`createCodingAgent()`](https://mastra.ai/reference/coding-agent/create-coding-agent) instead of `new Agent()`. It returns a standard `Agent` that already has a workspace, task tracking, and retries for transient model errors, which are the defaults Mastra Code runs on.
|
|
12
|
+
|
|
11
13
|
## When to use the Agent Controller
|
|
12
14
|
|
|
13
15
|
Use the Agent Controller when your application needs:
|
|
@@ -388,7 +390,7 @@ channels: {
|
|
|
388
390
|
|
|
389
391
|
Controller channel sessions and auto-approval state are held in memory, so use a long-lived server. Pending approvals and live Session state don't survive process restarts. Adapters that can't render approval controls automatically run tools without an approval prompt so the run doesn't remain suspended.
|
|
390
392
|
|
|
391
|
-
See [Channels](https://mastra.ai/docs/
|
|
393
|
+
See [Channels](https://mastra.ai/docs/channels) for adapter setup and platform-specific webhook configuration.
|
|
392
394
|
|
|
393
395
|
## Connect a UI
|
|
394
396
|
|
|
@@ -412,6 +414,6 @@ Subscriptions are isolated by Session. Events from another Session on the same c
|
|
|
412
414
|
## Related
|
|
413
415
|
|
|
414
416
|
- [Agents](https://mastra.ai/docs/agents/overview)
|
|
415
|
-
- [Workspace](https://mastra.ai/docs/
|
|
417
|
+
- [Workspace](https://mastra.ai/docs/sandbox/overview)
|
|
416
418
|
- [Observational memory](https://mastra.ai/docs/memory/observational-memory)
|
|
417
|
-
- [Channels](https://mastra.ai/docs/
|
|
419
|
+
- [Channels](https://mastra.ai/docs/channels)
|
|
@@ -16,7 +16,7 @@ Use background tasks when a tool call may take long enough that the user shouldn
|
|
|
16
16
|
|
|
17
17
|
For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
|
|
18
18
|
|
|
19
|
-
> **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/storage
|
|
19
|
+
> **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
|
|
20
20
|
|
|
21
21
|
## Quickstart
|
|
22
22
|
|
|
@@ -121,7 +121,7 @@ If the agent has `backgroundTasks.disabled: true`, every tool call runs synchron
|
|
|
121
121
|
|
|
122
122
|
## Background tasks related stream chunks
|
|
123
123
|
|
|
124
|
-
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/
|
|
124
|
+
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/harness/background-tasks) SSE stream. Each stream covers a different set of chunk types:
|
|
125
125
|
|
|
126
126
|
| Chunk type | When it fires | Emitted by |
|
|
127
127
|
| --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
|
|
@@ -376,7 +376,7 @@ These read from storage rather than the pubsub stream, so they're suitable for p
|
|
|
376
376
|
|
|
377
377
|
- [`Agent.stream()` reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
378
378
|
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
379
|
-
- [Durable agents](https://mastra.ai/docs/
|
|
380
|
-
- [Supervisor agents](https://mastra.ai/docs/
|
|
379
|
+
- [Durable agents](https://mastra.ai/docs/harness/durable-agents)
|
|
380
|
+
- [Supervisor agents](https://mastra.ai/docs/subagents)
|
|
381
381
|
- [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
|
|
382
|
-
- [Storage](https://mastra.ai/docs/storage
|
|
382
|
+
- [Storage](https://mastra.ai/docs/storage)
|
|
@@ -118,6 +118,22 @@ const agent = new Agent({
|
|
|
118
118
|
export const eventedWriter = createEventedAgent({ agent })
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
+
### Stored agents created through the API
|
|
122
|
+
|
|
123
|
+
Agents created with [`createStoredAgent()`](https://mastra.ai/reference/client-js/agents) opt in with a `durable` field on the agent config. The server wraps the agent with `createDurableAgent()` when it hydrates it, so no code deployment is needed:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
await mastraClient.createStoredAgent({
|
|
127
|
+
id: 'helper',
|
|
128
|
+
name: 'Helper',
|
|
129
|
+
instructions: 'You are a helpful assistant.',
|
|
130
|
+
model: { provider: 'openai', name: 'gpt-5' },
|
|
131
|
+
durable: true,
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`durable` also accepts `{ maxSteps, cleanupTimeoutMs }`. Cache and pubsub are inherited from the server's `Mastra` instance, so configure distributed backends there if you need durability across replicas. Automatic recovery is still configured in code through `recovery.durableAgents`.
|
|
136
|
+
|
|
121
137
|
### Inngest-powered with `createInngestAgent()`
|
|
122
138
|
|
|
123
139
|
Run the workflow on the [Inngest](https://www.inngest.com/docs) platform. Each tool call becomes a memoized step that Inngest can retry independently, and you get a dashboard for monitoring runs:
|
|
@@ -198,7 +214,7 @@ await durableAgent.stream('Research topic', {
|
|
|
198
214
|
})
|
|
199
215
|
```
|
|
200
216
|
|
|
201
|
-
Visit [Background tasks](https://mastra.ai/docs/
|
|
217
|
+
Visit [Background tasks](https://mastra.ai/docs/harness/background-tasks) for the full background task guide, including configuration, subagents, and suspend/resume.
|
|
202
218
|
|
|
203
219
|
## Cleanup
|
|
204
220
|
|
|
@@ -267,7 +283,7 @@ Mastra doesn't provide a distributed lease or lock yet. In multi-replica deploym
|
|
|
267
283
|
|
|
268
284
|
- [DurableAgent reference](https://mastra.ai/reference/agents/durable-agent)
|
|
269
285
|
- [`createInngestAgent()` reference](https://mastra.ai/reference/agents/inngest-agent)
|
|
270
|
-
- [Background tasks](https://mastra.ai/docs/
|
|
286
|
+
- [Background tasks](https://mastra.ai/docs/harness/background-tasks)
|
|
271
287
|
- [Inngest deployment guide](https://mastra.ai/integrations/deploy/inngest)
|
|
272
288
|
- [Agent overview](https://mastra.ai/docs/agents/overview)
|
|
273
289
|
- [Worker overview](https://mastra.ai/docs/deployment/workers)
|
|
@@ -10,7 +10,7 @@ A goal is a durable, thread-scoped objective: a standing instruction the agent k
|
|
|
10
10
|
|
|
11
11
|
The objective is persisted in thread state, so it survives reloads and is evaluated in-loop, even when a new message arrives in the middle of an already-running turn.
|
|
12
12
|
|
|
13
|
-
Goals build on the same machinery as [`isTaskComplete`](https://mastra.ai/docs/
|
|
13
|
+
Goals build on the same machinery as [`isTaskComplete`](https://mastra.ai/docs/subagents): an LLM-as-judge scores the agent's output each iteration and gates the loop. The difference is that a goal is **durable** (stored in thread state, not passed per call) and is set and updated through `Agent` methods rather than per-`stream()` options.
|
|
14
14
|
|
|
15
15
|
## When to use goals
|
|
16
16
|
|
|
@@ -20,11 +20,11 @@ Use a goal when you want an agent to keep working toward a single objective acro
|
|
|
20
20
|
- Work that should continue across mid-run messages (a message delivered into a live run is still judged against the goal).
|
|
21
21
|
- An objective that must persist across thread reloads or process restarts.
|
|
22
22
|
|
|
23
|
-
For a one-off completion check within a single `stream()` call, use [`isTaskComplete`](https://mastra.ai/docs/
|
|
23
|
+
For a one-off completion check within a single `stream()` call, use [`isTaskComplete`](https://mastra.ai/docs/subagents) instead.
|
|
24
24
|
|
|
25
25
|
## Quickstart
|
|
26
26
|
|
|
27
|
-
Goals require a configured [storage](https://mastra.ai/docs/storage
|
|
27
|
+
Goals require a configured [storage](https://mastra.ai/docs/storage) backend and a memory-backed thread. Add a `goal` config to the agent, a judge model is required for the goal to do anything, then set an objective for a thread:
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
import { Agent } from '@mastra/core/agent'
|
|
@@ -113,7 +113,7 @@ Per-objective values written by `setObjective` / `updateObjectiveOptions` take p
|
|
|
113
113
|
|
|
114
114
|
## Related
|
|
115
115
|
|
|
116
|
-
- [Supervisor agents](https://mastra.ai/docs/
|
|
117
|
-
- [Signal providers](https://mastra.ai/docs/
|
|
118
|
-
- [Memory storage](https://mastra.ai/docs/storage
|
|
116
|
+
- [Supervisor agents](https://mastra.ai/docs/subagents): `isTaskComplete` and the rubric scorer
|
|
117
|
+
- [Signal providers](https://mastra.ai/docs/harness/signal-providers): How the objective is projected into context
|
|
118
|
+
- [Memory storage](https://mastra.ai/docs/storage): The storage backend goals require
|
|
119
119
|
- [Mastra Factory](https://factory.mastra.ai) and [Mastra Code](https://code.mastra.ai): Examples of goal-driven coding agents
|
|
@@ -12,13 +12,14 @@ In Mastra, harness refers to a set of capabilities for managing an agent beyond
|
|
|
12
12
|
|
|
13
13
|
Choose a starting point based on what the agent needs. You may use one capability or several.
|
|
14
14
|
|
|
15
|
-
| If you want to | Start here
|
|
16
|
-
| ------------------------------------------------------------------------------------- |
|
|
17
|
-
| Keep a run available through client disconnects or server restarts | [Durable Agents](https://mastra.ai/docs/
|
|
18
|
-
| Run slow tools, workflows, or subagents without blocking | [Background Tasks](https://mastra.ai/docs/
|
|
19
|
-
| Keep an agent working until it reaches an objective | [Goals](https://mastra.ai/docs/
|
|
20
|
-
| Start work automatically at recurring times | [Schedules](https://mastra.ai/docs/
|
|
21
|
-
| Add context, redirect active work, or wake an idle thread | [Signals](https://mastra.ai/docs/
|
|
22
|
-
| React to changes in GitHub, Slack, continuous integration, or another external system | [Signal Providers](https://mastra.ai/docs/
|
|
23
|
-
| Build an interactive product with sessions, modes, state, approvals, and events | [AgentController](https://mastra.ai/docs/harness/agent-controller)
|
|
24
|
-
| Let users steer, queue follow-up work, or stop an interactive run | [AgentController](https://mastra.ai/docs/harness/agent-controller)
|
|
15
|
+
| If you want to | Start here | Why |
|
|
16
|
+
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
17
|
+
| Keep a run available through client disconnects or server restarts | [Durable Agents](https://mastra.ai/docs/harness/durable-agents) | Persist run state and let clients reconnect to its stream. |
|
|
18
|
+
| Run slow tools, workflows, or subagents without blocking | [Background Tasks](https://mastra.ai/docs/harness/background-tasks) | Finish work asynchronously and return its result to the agent. |
|
|
19
|
+
| Keep an agent working until it reaches an objective | [Goals](https://mastra.ai/docs/harness/goals) | Evaluate a thread-scoped objective until it's complete or reaches its run budget. |
|
|
20
|
+
| Start work automatically at recurring times | [Schedules](https://mastra.ai/docs/harness/schedules) | Start isolated runs or send prompts into an existing thread on a cron schedule. |
|
|
21
|
+
| Add context, redirect active work, or wake an idle thread | [Signals](https://mastra.ai/docs/harness/signals) | Deliver input now or hold it for the next turn. |
|
|
22
|
+
| React to changes in GitHub, Slack, continuous integration, or another external system | [Signal Providers](https://mastra.ai/docs/harness/signal-providers) | Track subscriptions and forward matching events to agent threads. |
|
|
23
|
+
| Build an interactive product with sessions, modes, state, approvals, and events | [AgentController](https://mastra.ai/docs/harness/agent-controller) | Host isolated sessions around a shared agent runtime. |
|
|
24
|
+
| Let users steer, queue follow-up work, or stop an interactive run | [AgentController](https://mastra.ai/docs/harness/agent-controller) | Expose run controls through each session. |
|
|
25
|
+
| Give an agent files, a shell, and the defaults a coding agent needs | [`createCodingAgent()`](https://mastra.ai/reference/coding-agent/create-coding-agent) | Build a standard agent with a workspace, task tracking, and retries already configured. |
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
|
-
A schedule runs an agent on a cron cadence. On each fire, Mastra sends a prompt to the agent, either as a [signal](https://mastra.ai/docs/
|
|
9
|
+
A schedule runs an agent on a cron cadence. On each fire, Mastra sends a prompt to the agent, either as a [signal](https://mastra.ai/docs/harness/signals) into a thread or as a threadless [`agent.generate()`](https://mastra.ai/reference/agents/generate) run. Use schedules for recurring agent work such as daily summaries, periodic checks, or scheduled nudges into a conversation.
|
|
10
10
|
|
|
11
11
|
Schedules are persisted, so they survive restarts and redeploys. Manage them at runtime through [`mastra.schedules`](https://mastra.ai/reference/schedules/overview), the canonical create, read, update, and delete (CRUD) surface. The same surface also manages [workflow schedules](https://mastra.ai/docs/workflows/scheduled-workflows) (pass `workflowId` instead of `agentId` to schedule a workflow).
|
|
12
12
|
|
|
13
|
-
> **Note:** Schedules require a [storage](https://mastra.ai/docs/storage
|
|
13
|
+
> **Note:** Schedules require a [storage](https://mastra.ai/docs/storage) adapter that implements the schedules domain. See the [`mastra.schedules` reference](https://mastra.ai/reference/schedules/overview) for supported adapters and API behavior.
|
|
14
14
|
|
|
15
15
|
## Quickstart
|
|
16
16
|
|
|
@@ -71,7 +71,7 @@ Without a `threadId`, each fire is an isolated `agent.generate()` run. Nothing i
|
|
|
71
71
|
|
|
72
72
|
### Threaded
|
|
73
73
|
|
|
74
|
-
With a `threadId`, the schedule sends a [signal](https://mastra.ai/docs/
|
|
74
|
+
With a `threadId`, the schedule sends a [signal](https://mastra.ai/docs/harness/signals) into that thread, so the prompt joins the agent's conversation. Threaded schedules require a `resourceId` alongside the `threadId`.
|
|
75
75
|
|
|
76
76
|
```typescript
|
|
77
77
|
await mastra.schedules.create({
|
|
@@ -83,7 +83,7 @@ await mastra.schedules.create({
|
|
|
83
83
|
})
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
Threaded schedules accept extra fields that control how the signal behaves, including the signal type, XML tag, tag attributes, and active-or-idle delivery behavior. They mirror the options [`agent.sendSignal()`](https://mastra.ai/docs/
|
|
86
|
+
Threaded schedules accept extra fields that control how the signal behaves, including the signal type, XML tag, tag attributes, and active-or-idle delivery behavior. They mirror the options [`agent.sendSignal()`](https://mastra.ai/docs/harness/signals) accepts and stay JSON-serializable so they persist with the schedule.
|
|
87
87
|
|
|
88
88
|
These fields require a `threadId`. For the full threaded input shape, see the [agent schedule input reference](https://mastra.ai/reference/schedules/overview).
|
|
89
89
|
|
|
@@ -197,5 +197,5 @@ Hook exceptions are caught and logged. They never re-route the worker or trigger
|
|
|
197
197
|
## Related
|
|
198
198
|
|
|
199
199
|
- [`mastra.schedules`](https://mastra.ai/reference/schedules/overview): API reference for creating and managing schedules.
|
|
200
|
-
- [Signals](https://mastra.ai/docs/
|
|
200
|
+
- [Signals](https://mastra.ai/docs/harness/signals): the delivery mechanism behind threaded schedules.
|
|
201
201
|
- [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows): declare a cron schedule on a workflow definition.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
|
-
A signal provider monitors an external source, such as GitHub, Slack, continuous integration (CI), or your own API, and pushes [notification signals](https://mastra.ai/docs/
|
|
9
|
+
A signal provider monitors an external source, such as GitHub, Slack, continuous integration (CI), or your own API, and pushes [notification signals](https://mastra.ai/docs/harness/signals) into subscribed agent threads.
|
|
10
10
|
|
|
11
11
|
## When to use a signal provider
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ If you only need to push a one-off event into a thread, call [`agent.sendNotific
|
|
|
20
20
|
|
|
21
21
|
## How signal providers work
|
|
22
22
|
|
|
23
|
-
A signal provider is the producing side of the [signals](https://mastra.ai/docs/
|
|
23
|
+
A signal provider is the producing side of the [signals](https://mastra.ai/docs/harness/signals) system. It brings external events into a thread, while the signal APIs control how the thread consumes them.
|
|
24
24
|
|
|
25
25
|
A signal provider combines three capabilities:
|
|
26
26
|
|
|
@@ -205,7 +205,7 @@ For a production provider that watches GitHub pull requests, see the [GitHub Cha
|
|
|
205
205
|
## Related
|
|
206
206
|
|
|
207
207
|
- [Guide: Building a signal provider](https://mastra.ai/blog/building-a-signal-provider)
|
|
208
|
-
- [Signals](https://mastra.ai/docs/
|
|
209
|
-
- [Notification signals](https://mastra.ai/docs/
|
|
208
|
+
- [Signals](https://mastra.ai/docs/harness/signals)
|
|
209
|
+
- [Notification signals](https://mastra.ai/docs/harness/signals)
|
|
210
210
|
- [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider)
|
|
211
211
|
- [`WebhookSignalProvider` reference](https://mastra.ai/reference/signals/webhook-signal-provider)
|
|
@@ -63,7 +63,7 @@ A local `.env` file is optional. Environment variables stored on the platform ar
|
|
|
63
63
|
|
|
64
64
|
4. Verify your deployment at the URL printed by the CLI. Append `/api/agents` to confirm it returns a JSON list of your agents.
|
|
65
65
|
|
|
66
|
-
> **Warning:** Set up [authentication](https://mastra.ai/docs/
|
|
66
|
+
> **Warning:** Set up [authentication](https://mastra.ai/docs/auth/overview) before exposing your endpoints publicly.
|
|
67
67
|
|
|
68
68
|
The first deploy writes a `.mastra-project.json` file linking your directory to the platform project. Commit it so later deploys, CI runs, and [`mastra env`](https://mastra.ai/docs/mastra-platform/environments) commands target the same project without extra flags.
|
|
69
69
|
|
|
@@ -29,7 +29,7 @@ Choose the path that matches what you want to do:
|
|
|
29
29
|
Your Mastra application is built from three building blocks:
|
|
30
30
|
|
|
31
31
|
- [Agents](https://mastra.ai/docs/agents/overview): AI agents that can use tools and follow instructions while maintaining context
|
|
32
|
-
- [Tools](https://mastra.ai/docs/agents/
|
|
32
|
+
- [Tools](https://mastra.ai/docs/agents/tools): Callable functions and integrations available to your agents
|
|
33
33
|
- [Workflows](https://mastra.ai/docs/workflows/overview): Multi-step orchestration pipelines that coordinate agents and tools
|
|
34
34
|
|
|
35
35
|
## Going to production
|
|
@@ -56,7 +56,7 @@ You get a stable API endpoint with environment variable management and custom do
|
|
|
56
56
|
|
|
57
57
|
4. Verify your deployment at the URL printed by the CLI. Append `/api/agents` to confirm it returns a JSON list of your agents.
|
|
58
58
|
|
|
59
|
-
> **Warning:** Set up [authentication](https://mastra.ai/docs/
|
|
59
|
+
> **Warning:** Set up [authentication](https://mastra.ai/docs/auth/overview) before exposing your endpoints publicly.
|
|
60
60
|
|
|
61
61
|
## Deploy lifecycle
|
|
62
62
|
|
|
@@ -25,7 +25,7 @@ Studio automatically generates a thread and resource ID for you. When calling `s
|
|
|
25
25
|
|
|
26
26
|
## Getting started
|
|
27
27
|
|
|
28
|
-
Install the Mastra memory module along with a [storage adapter](https://mastra.ai/docs/storage
|
|
28
|
+
Install the Mastra memory module along with a [storage adapter](https://mastra.ai/docs/storage) for your database. The examples below use `@mastra/libsql`, which stores data locally in a `mastra.db` file.
|
|
29
29
|
|
|
30
30
|
**npm**:
|
|
31
31
|
|