@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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Prompt blocks are reusable instruction templates managed by Editor. An agent's instructions can combine inline text with embedded prompt blocks and references to independently versioned prompt blocks.
|
|
6
6
|
|
|
7
|
-
See [Prompt blocks](https://mastra.ai/docs/editor
|
|
7
|
+
See [Prompt blocks](https://mastra.ai/docs/studio/editor) for the Studio workflow and common uses.
|
|
8
8
|
|
|
9
9
|
## Block types
|
|
10
10
|
|
|
@@ -134,4 +134,4 @@ The default Mastra server prefix is `/api`. A custom server prefix changes the p
|
|
|
134
134
|
|
|
135
135
|
## Version resolution
|
|
136
136
|
|
|
137
|
-
Runtime references resolve the active published block. Editor previews resolve the latest draft. See [Editor versioning](https://mastra.ai/docs/editor
|
|
137
|
+
Runtime references resolve the active published block. Editor previews resolve the latest draft. See [Editor versioning](https://mastra.ai/docs/studio/editor) for the shared draft, publish, and restore lifecycle.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The `ToolProvider` interface defines how the editor discovers and resolves integration tools from external platforms. Mastra includes two built-in implementations: `ComposioToolProvider` and `ArcadeToolProvider`.
|
|
6
6
|
|
|
7
|
-
See [Editor tools](https://mastra.ai/docs/editor
|
|
7
|
+
See [Editor tools](https://mastra.ai/docs/studio/editor) for provider setup and the Studio workflow. See [tool configuration](https://mastra.ai/reference/editor/tools) for stored selections and resolution behavior.
|
|
8
8
|
|
|
9
9
|
## ToolProvider interface
|
|
10
10
|
|
|
@@ -77,6 +77,8 @@ const editor = new MastraEditor({
|
|
|
77
77
|
|
|
78
78
|
**defaultScope** (`'per-author' | 'caller-supplied'`): Connection identity scope. Defaults to per-author. (Default: `'per-author'`)
|
|
79
79
|
|
|
80
|
+
**userIdResolver** (`ComposioUserIdResolver`): Server-side resolver that derives the effective Composio userId from authenticated context fields. Used for invoker and caller-supplied execution. The exact connected account always comes from the stored connection pin.
|
|
81
|
+
|
|
80
82
|
### Tool slugs
|
|
81
83
|
|
|
82
84
|
Composio tools use uppercase slug format: `GITHUB_CREATE_ISSUE`, `SLACK_SEND_MESSAGE`.
|
|
@@ -85,6 +87,111 @@ Composio tools use uppercase slug format: `GITHUB_CREATE_ISSUE`, `SLACK_SEND_MES
|
|
|
85
87
|
|
|
86
88
|
Connections use per-author scope by default. Set `defaultScope: 'caller-supplied'` to bucket authorization by the caller identity resolved from `MASTRA_RESOURCE_ID_KEY` in request context. Ensure each authenticated request provides a stable, unique resource ID. When using `MastraAuthWorkos`, configure `mapUserToResourceId` to set this value from the authenticated user.
|
|
87
89
|
|
|
90
|
+
How the provider resolves the Composio user for a tool call depends on the connection:
|
|
91
|
+
|
|
92
|
+
- **Author-bound connections** (`kind: 'author'`) execute as the agent author's user against the pinned connected account.
|
|
93
|
+
- **Invoker-bound connections** (`kind: 'invoker'`) execute as the authenticated invoker against the exact pinned account, which may be an account another user shared with the invoker through Composio's access control list (ACL). The user ID comes from `userIdResolver` when configured, then the authenticated user, and never from the Memory `resourceId`. Invoker resolution fails when no authenticated user or resolver result exists.
|
|
94
|
+
- **Caller-supplied scope** (`scope: 'caller-supplied'`) uses `userIdResolver` when configured. Otherwise, it falls back to the legacy `resourceId` from request context for backward compatibility. When a specific connected account is pinned, execution routes to that exact account. Otherwise, Composio auto-resolves within the user's bucket.
|
|
95
|
+
|
|
96
|
+
### Execute with a shared account
|
|
97
|
+
|
|
98
|
+
Bob needs to run a Salesforce tool with an account that Alice shared through Composio. Keep each identity separate:
|
|
99
|
+
|
|
100
|
+
| Identity | Value |
|
|
101
|
+
| ----------------- | --------------------- |
|
|
102
|
+
| Memory resource | `project_123` |
|
|
103
|
+
| Composio user ID | `bob` |
|
|
104
|
+
| Connected account | `ca_alice_salesforce` |
|
|
105
|
+
|
|
106
|
+
Register the provider normally. Mastra server authentication writes the authenticated user to request context, so most applications don't need a `userIdResolver`:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
110
|
+
import { MastraEditor } from '@mastra/editor'
|
|
111
|
+
import { ComposioToolProvider } from '@mastra/editor/composio'
|
|
112
|
+
|
|
113
|
+
const editor = new MastraEditor({
|
|
114
|
+
toolProviders: {
|
|
115
|
+
composio: new ComposioToolProvider({
|
|
116
|
+
apiKey: process.env.COMPOSIO_API_KEY!,
|
|
117
|
+
}),
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
export const mastra = new Mastra({ editor })
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Configure the agent with an invoker connection pinned to `ca_alice_salesforce`. When Bob invokes the agent, Mastra sends `bob` as the Composio user and the pinned account ID as the exact connected account. The Memory resource stays `project_123`. Composio then checks whether the account's ACL permits Bob to execute it.
|
|
125
|
+
|
|
126
|
+
### Map application users to Composio users
|
|
127
|
+
|
|
128
|
+
Use `userIdResolver` when your Composio user IDs differ from the IDs returned by Mastra authentication, or when your application must authorize the stored account pin before execution.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
type ComposioUserIdResolver = (
|
|
132
|
+
input: ComposioUserIdResolverInput,
|
|
133
|
+
) => Promise<string | undefined> | string | undefined
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**requestContext** (`RequestContext`): Live per-request context. Client-provided non-reserved entries are untrusted. Derive identity and authorize connectedAccountId only from validated, server-populated fields such as MASTRA\_USER\_KEY, read with getRaw().
|
|
137
|
+
|
|
138
|
+
**toolkit** (`string`): Toolkit slug the identity is being resolved for, when known.
|
|
139
|
+
|
|
140
|
+
**connectedAccountId** (`string`): Stored connection pin being resolved, when one exists. Use it to validate that the invoker may use this exact account.
|
|
141
|
+
|
|
142
|
+
The resolver returns the Composio user ID, or `undefined` to use the provider's default resolution. Returning an empty string throws instead of silently falling back. The resolver can't replace the connected account.
|
|
143
|
+
|
|
144
|
+
This example namespaces the Composio user by organization and asks the application's authorization layer to approve the exact account pin:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { MASTRA_USER_KEY } from '@mastra/server/auth'
|
|
148
|
+
import { ComposioToolProvider } from '@mastra/editor/composio'
|
|
149
|
+
import { canUseConnectedAccount } from './integration-authorization'
|
|
150
|
+
|
|
151
|
+
type AuthenticatedUser = {
|
|
152
|
+
id: string
|
|
153
|
+
organizationId: string
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isAuthenticatedUser(value: unknown): value is AuthenticatedUser {
|
|
157
|
+
return (
|
|
158
|
+
typeof value === 'object' &&
|
|
159
|
+
value !== null &&
|
|
160
|
+
'id' in value &&
|
|
161
|
+
typeof value.id === 'string' &&
|
|
162
|
+
'organizationId' in value &&
|
|
163
|
+
typeof value.organizationId === 'string'
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const composio = new ComposioToolProvider({
|
|
168
|
+
apiKey: process.env.COMPOSIO_API_KEY!,
|
|
169
|
+
userIdResolver: async ({ requestContext, toolkit, connectedAccountId }) => {
|
|
170
|
+
const user = requestContext?.getRaw(MASTRA_USER_KEY)
|
|
171
|
+
if (!isAuthenticatedUser(user)) return undefined
|
|
172
|
+
|
|
173
|
+
if (connectedAccountId) {
|
|
174
|
+
const allowed = await canUseConnectedAccount({
|
|
175
|
+
actorId: user.id,
|
|
176
|
+
organizationId: user.organizationId,
|
|
177
|
+
provider: 'composio',
|
|
178
|
+
toolkit,
|
|
179
|
+
connectedAccountId,
|
|
180
|
+
})
|
|
181
|
+
if (!allowed) {
|
|
182
|
+
throw new Error('User cannot access this connected account')
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return `${user.organizationId}:${user.id}`
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Use the same namespaced ID when creating Composio connections and shared-account ACL entries. For example, Bob's Composio user ID in this setup is `acme:bob`.
|
|
192
|
+
|
|
193
|
+
Throw from `userIdResolver` to deny the request. During stored-agent resolution, Mastra logs the failure and omits tools associated with that connection, so no tool call reaches Composio. Other connections continue to resolve. When calling `resolveToolsVNext()` directly, the error is returned to the caller instead.
|
|
194
|
+
|
|
88
195
|
### Connection management tools
|
|
89
196
|
|
|
90
197
|
Composio provides tools for starting and monitoring authorization from an agent chat. When `allowedToolkits` is set, include `composio` to make these tools available:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Editor stores tool selections as part of an agent version. A stored configuration can add registered tools and tools from integration providers, as well as tools from Model Context Protocol (MCP) clients.
|
|
6
6
|
|
|
7
|
-
See [Editor tools](https://mastra.ai/docs/editor
|
|
7
|
+
See [Editor tools](https://mastra.ai/docs/studio/editor) for the Studio workflow and common uses.
|
|
8
8
|
|
|
9
9
|
## Tool sources
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Editor versions stored agents and prompt blocks. Database-backed resources use draft and publish operations. Code-backed agent overrides use deterministic files and Git history.
|
|
6
6
|
|
|
7
|
-
See [Editor versioning](https://mastra.ai/docs/editor
|
|
7
|
+
See [Editor versioning](https://mastra.ai/docs/studio/editor) for release and experimentation patterns.
|
|
8
8
|
|
|
9
9
|
## Database lifecycle
|
|
10
10
|
|
|
@@ -35,7 +35,7 @@ See [`MastraEditor`](https://mastra.ai/reference/editor/mastra-editor) for sourc
|
|
|
35
35
|
|
|
36
36
|
## Select an agent version
|
|
37
37
|
|
|
38
|
-
Calling [`mastra.getAgentById()`](https://mastra.ai/reference/core/getAgentById) without a selector returns the registered code-defined agent. Pass `status` or `versionId` to apply a stored override. See [Select a version](https://mastra.ai/docs/editor
|
|
38
|
+
Calling [`mastra.getAgentById()`](https://mastra.ai/reference/core/getAgentById) without a selector returns the registered code-defined agent. Pass `status` or `versionId` to apply a stored override. See [Select a version](https://mastra.ai/docs/studio/editor) for a TypeScript example.
|
|
39
39
|
|
|
40
40
|
With the default server prefix, pass selectors as query parameters under `/api`:
|
|
41
41
|
|
|
@@ -54,7 +54,7 @@ See the [Client SDK agents reference](https://mastra.ai/reference/client-js/agen
|
|
|
54
54
|
|
|
55
55
|
## Sub-agent versioning
|
|
56
56
|
|
|
57
|
-
Version overrides propagate through [supervisor-agent delegation](https://mastra.ai/docs/
|
|
57
|
+
Version overrides propagate through [supervisor-agent delegation](https://mastra.ai/docs/subagents) in request context. Define selectors at three levels:
|
|
58
58
|
|
|
59
59
|
1. `Mastra` instance `versions`: Defaults for every invocation
|
|
60
60
|
2. Server request-body `versions`: Per-request values added to request context
|
|
@@ -70,6 +70,24 @@ const scorer = createPromptAlignmentScorerLLM({
|
|
|
70
70
|
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
### Multi-turn conversations
|
|
74
|
+
|
|
75
|
+
By default the scorer only sees the current turn. In a conversation, a reply like `"A"` is meaningless on its own, so the judge can't tell what the user asked for and scores the response as misaligned.
|
|
76
|
+
|
|
77
|
+
Set `includeConversationHistory` to give the judge the prior turns from the agent's memory. The judge uses them to interpret the current prompt, but still scores only the current response.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const scorer = createPromptAlignmentScorerLLM({
|
|
81
|
+
model: 'openai/gpt-5.6-sol',
|
|
82
|
+
options: {
|
|
83
|
+
evaluationMode: 'user',
|
|
84
|
+
includeConversationHistory: { maxMessages: 6 }, // or `true` for the last 10 messages
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This only affects agent runs, where the scorer receives the remembered messages. Runs scored from a plain prompt string are unchanged.
|
|
90
|
+
|
|
73
91
|
### Multi-Dimensional Analysis
|
|
74
92
|
|
|
75
93
|
Prompt Alignment evaluates responses across four key dimensions with weighted scoring that adapts based on the evaluation mode:
|
|
@@ -111,5 +111,5 @@ The `reason` summarizes the result and lists each criterion with its verdict, so
|
|
|
111
111
|
## Related
|
|
112
112
|
|
|
113
113
|
- [isTaskComplete on stream()](https://mastra.ai/reference/streaming/agents/stream)
|
|
114
|
-
- [Supervisor agents](https://mastra.ai/docs/
|
|
114
|
+
- [Supervisor agents](https://mastra.ai/docs/subagents)
|
|
115
115
|
- [createScorer](https://mastra.ai/reference/evals/create-scorer)
|
|
@@ -18,7 +18,7 @@ import { Memory } from '@mastra/memory'
|
|
|
18
18
|
export default new Memory()
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
The exported instance becomes the agent's `memory`. If your app configures a storage provider on the main Mastra instance, memory data is stored there. See [storage](https://mastra.ai/docs/storage
|
|
21
|
+
The exported instance becomes the agent's `memory`. If your app configures a storage provider on the main Mastra instance, memory data is stored there. See [storage](https://mastra.ai/docs/storage) for more information.
|
|
22
22
|
|
|
23
23
|
Use the same `resource` and `thread` values when calling the agent to continue a conversation:
|
|
24
24
|
|
|
@@ -51,7 +51,7 @@ export default new Memory({
|
|
|
51
51
|
|
|
52
52
|
Visit the [`Memory` reference](https://mastra.ai/reference/memory/memory-class) for constructor options. Use these pages for related memory features:
|
|
53
53
|
|
|
54
|
-
- [Storage](https://mastra.ai/docs/storage
|
|
54
|
+
- [Storage](https://mastra.ai/docs/storage): configure persistence for memory data.
|
|
55
55
|
- [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): retrieve relevant past messages by semantic meaning.
|
|
56
56
|
- [Memory processors](https://mastra.ai/docs/memory/memory-processors): filter, trim, or transform messages before memory adds them to model context.
|
|
57
57
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
|
-
Mastra configures its HTTP [server](https://mastra.ai/docs/server/
|
|
7
|
+
Mastra configures its HTTP [server](https://mastra.ai/docs/server/overview) from a `server.ts` file directly under `src/mastra/`. The server exposes agents, workflows, and other registered primitives as REST endpoints, and the file default-exports the same `ServerConfig` shape you'd pass to [`new Mastra()`](https://mastra.ai/reference/core/mastra-class).
|
|
8
8
|
|
|
9
|
-
Use this page for the file-based convention. For server features, middleware, custom routes, generated API docs, and deployment behavior, see [Server overview](https://mastra.ai/docs/server/
|
|
9
|
+
Use this page for the file-based convention. For server features, middleware, custom routes, generated API docs, and deployment behavior, see [Server overview](https://mastra.ai/docs/server/overview).
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ export default {
|
|
|
32
32
|
| Add webhooks or health checks | `apiRoutes` |
|
|
33
33
|
| Enable generated API docs | `build.openAPIDocs` and `build.swaggerUI` |
|
|
34
34
|
|
|
35
|
-
See [Mastra server](https://mastra.ai/docs/server/
|
|
35
|
+
See [Mastra server](https://mastra.ai/docs/server/overview), [middleware](https://mastra.ai/docs/server/middleware), and [custom API routes](https://mastra.ai/docs/server/custom-api-routes) for examples.
|
|
36
36
|
|
|
37
37
|
## Precedence with code
|
|
38
38
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
A file-based agent discovers skills from its `skills/` directory and bundles them at build time. Skills are reusable procedures or reference material that the agent can load when relevant, instead of putting every detail into the always-on prompt.
|
|
8
8
|
|
|
9
|
-
Use this page for the file-based convention. For code-defined skills, see [Agent skills](https://mastra.ai/docs/
|
|
9
|
+
Use this page for the file-based convention. For code-defined skills, see [Agent skills](https://mastra.ai/docs/skills). For the `SKILL.md` package format, see [Workspace skills](https://mastra.ai/docs/sandbox/skills).
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
|
-
Mastra sets the project's default [storage](https://mastra.ai/docs/storage
|
|
7
|
+
Mastra sets the project's default [storage](https://mastra.ai/docs/storage) from a `storage.ts` file directly under `src/mastra/`. The file default-exports a store, which replaces the built-in in-memory store used for memory, workflows, observability, and other storage domains.
|
|
8
8
|
|
|
9
|
-
Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see [storage overview](https://mastra.ai/docs/storage
|
|
9
|
+
Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see [storage overview](https://mastra.ai/docs/storage).
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
@@ -25,7 +25,7 @@ Mastra registers the store before file-based agents and workflows, so storage-de
|
|
|
25
25
|
|
|
26
26
|
## Production backends
|
|
27
27
|
|
|
28
|
-
`storage.ts` can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see [storage overview](https://mastra.ai/docs/storage
|
|
28
|
+
`storage.ts` can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see [storage overview](https://mastra.ai/docs/storage), [observability signal support](https://mastra.ai/docs/observability/overview), and the [storage reference](https://mastra.ai/reference/storage/overview).
|
|
29
29
|
|
|
30
30
|
## Precedence with code
|
|
31
31
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
A file-based agent can declare **subagents**, specialist child agents it delegates to. The parent model sees each subagent as a delegation tool named after the subagent directory and calls that tool to hand off a task. The subagent's result returns to the parent conversation.
|
|
8
8
|
|
|
9
|
-
Use this page for the file-based convention. For broader delegation patterns, hooks, memory isolation, tool approval propagation, and scoring, see [Supervisor agents](https://mastra.ai/docs/
|
|
9
|
+
Use this page for the file-based convention. For broader delegation patterns, hooks, memory isolation, tool approval propagation, and scoring, see [Supervisor agents](https://mastra.ai/docs/subagents).
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
|
-
A [workspace](https://mastra.ai/docs/
|
|
7
|
+
A [workspace](https://mastra.ai/docs/sandbox/overview) assembles capabilities such as filesystem access and command execution. The configured backends determine which tools are available. File-based agents get a default workspace automatically when discovered through `mastra dev` or `mastra build`. This default includes filesystem access and command execution, so agents can read and write files and run shell commands without extra configuration.
|
|
8
8
|
|
|
9
|
-
Use this page for the file-based convention. For workspace providers, tools, search, lifecycle, and sandbox details, see [Sandbox](https://mastra.ai/docs/
|
|
9
|
+
Use this page for the file-based convention. For workspace providers, tools, search, lifecycle, and sandbox details, see [Sandbox](https://mastra.ai/docs/sandbox/overview).
|
|
10
10
|
|
|
11
11
|
## Default workspace
|
|
12
12
|
|
|
@@ -65,7 +65,7 @@ Customize the workspace when the default local directory isn't enough. Common re
|
|
|
65
65
|
- Add workspace search with BM25 or vector search.
|
|
66
66
|
- Share one workspace across multiple agents.
|
|
67
67
|
|
|
68
|
-
For provider patterns and runtime behavior, see the [sandbox guide](https://mastra.ai/docs/
|
|
68
|
+
For provider patterns and runtime behavior, see the [sandbox guide](https://mastra.ai/docs/sandbox/overview) and [workspace search](https://mastra.ai/docs/sandbox/search).
|
|
69
69
|
|
|
70
70
|
## Runtime boundary
|
|
71
71
|
|
package/.docs/reference/index.md
CHANGED
|
@@ -211,6 +211,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
211
211
|
- [.getThreadById()](https://mastra.ai/reference/memory/getThreadById)
|
|
212
212
|
- [.listThreads()](https://mastra.ai/reference/memory/listThreads)
|
|
213
213
|
- [.recall()](https://mastra.ai/reference/memory/recall)
|
|
214
|
+
- [.settled()](https://mastra.ai/reference/memory/settled)
|
|
214
215
|
- [.summarizeThread()](https://mastra.ai/reference/memory/summarizeThread)
|
|
215
216
|
- [AgentNetwork to .network()](https://mastra.ai/reference/migrations/agentnetwork)
|
|
216
217
|
- [AI SDK v4 to v5](https://mastra.ai/reference/migrations/ai-sdk-v4-to-v5)
|
|
@@ -157,7 +157,7 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
|
|
|
157
157
|
})
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
> **Note:** We've shortened and simplified the `weatherTool` example here. You can see the complete weather tool under [Giving an Agent a Tool](https://mastra.ai/docs/agents/
|
|
160
|
+
> **Note:** We've shortened and simplified the `weatherTool` example here. You can see the complete weather tool under [Giving an Agent a Tool](https://mastra.ai/docs/agents/tools).
|
|
161
161
|
|
|
162
162
|
5. Create a `weather-agent.ts` file:
|
|
163
163
|
|
|
@@ -244,7 +244,7 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
|
|
|
244
244
|
|
|
245
245
|
- [Review the project structure](https://mastra.ai/reference/project-structure): Understand how `src/mastra/` files map to agents, tools, workflows, storage, and configuration.
|
|
246
246
|
- [Test your agent in Studio](https://mastra.ai/docs/studio/overview): Open the local Studio UI and run the weather agent.
|
|
247
|
-
- [Use tools with agents](https://mastra.ai/docs/agents/
|
|
247
|
+
- [Use tools with agents](https://mastra.ai/docs/agents/tools): Replace the example weather tool with a real tool that calls an API or service.
|
|
248
248
|
- [Add memory](https://mastra.ai/docs/memory/overview): Persist conversation history and user-specific context.
|
|
249
|
-
- [Configure storage](https://mastra.ai/docs/storage
|
|
249
|
+
- [Configure storage](https://mastra.ai/docs/storage): Add a persistent storage adapter for memory, workflows, observability, and other runtime state.
|
|
250
250
|
- [Build and deploy](https://mastra.ai/docs/deployment/overview): Build the Mastra server and deploy it to a hosting platform.
|
|
@@ -145,4 +145,5 @@ export const agent = new Agent({
|
|
|
145
145
|
- [listThreads](https://mastra.ai/reference/memory/listThreads)
|
|
146
146
|
- [deleteMessages](https://mastra.ai/reference/memory/deleteMessages)
|
|
147
147
|
- [cloneThread](https://mastra.ai/reference/memory/cloneThread)
|
|
148
|
+
- [settled](https://mastra.ai/reference/memory/settled)
|
|
148
149
|
- [Clone Utility Methods](https://mastra.ai/reference/memory/clone-utilities)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Memory.settled()
|
|
4
|
+
|
|
5
|
+
The `.settled()` method resolves once all background work the `Memory` instance started has finished. Some memory work continues after an agent run returns:
|
|
6
|
+
|
|
7
|
+
- Observational memory cycles (buffered observation and reflection, including the nested agent runs they spawn)
|
|
8
|
+
- Vector cleanup started by `deleteThread()` and `deleteMessages()`
|
|
9
|
+
|
|
10
|
+
Await this method before closing a storage connection you own. Without it, background statements can run against a closed connection.
|
|
11
|
+
|
|
12
|
+
The method is declared on the base memory class, so it's also available on the `MastraMemory` instance returned by `agent.getMemory()`.
|
|
13
|
+
|
|
14
|
+
## Usage example
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
await agent.generate('Hello', {
|
|
18
|
+
memory: { thread: 'thread-123', resource: 'user-456' },
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
await memory.settled()
|
|
22
|
+
await store.close()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
This method takes no parameters.
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
**void** (`Promise<void>`): A promise that resolves when all background memory work has finished. Background work that fails does not reject this promise.
|
|
32
|
+
|
|
33
|
+
## Extended usage example
|
|
34
|
+
|
|
35
|
+
Test suites and short-lived processes are the most common places to need this, since they close the store immediately after a run finishes.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Memory } from '@mastra/memory'
|
|
39
|
+
import { PostgresStore } from '@mastra/pg'
|
|
40
|
+
|
|
41
|
+
const store = new PostgresStore({ connectionString })
|
|
42
|
+
const memory = new Memory({ storage: store })
|
|
43
|
+
|
|
44
|
+
// ... run your agent ...
|
|
45
|
+
|
|
46
|
+
// Wait for observational memory and vector cleanup to finish before closing.
|
|
47
|
+
await memory.settled()
|
|
48
|
+
await store.close()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> **Note:** `settled()` joins the work that had started by the time you called it, plus any work that work enqueues. It does not prevent new work from starting afterwards, so call it once the agent runs you care about have returned.
|
|
52
|
+
|
|
53
|
+
## Related
|
|
54
|
+
|
|
55
|
+
- [Memory Class Reference](https://mastra.ai/reference/memory/memory-class)
|
|
56
|
+
- [Observational Memory](https://mastra.ai/docs/memory/observational-memory)
|
|
57
|
+
- [deleteMessages](https://mastra.ai/reference/memory/deleteMessages)
|
|
@@ -255,9 +255,9 @@ const stream = await supervisorAgent.stream('Research AI in education', {
|
|
|
255
255
|
|
|
256
256
|
## See also
|
|
257
257
|
|
|
258
|
-
- [Supervisor Agents](https://mastra.ai/docs/
|
|
258
|
+
- [Supervisor Agents](https://mastra.ai/docs/subagents)
|
|
259
259
|
- [Agent Networks](https://mastra.ai/docs/agents/networks)
|
|
260
260
|
- [Agent.stream() Reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
261
261
|
- [Agent.generate() Reference](https://mastra.ai/reference/agents/generate)
|
|
262
|
-
- [Agent Approval](https://mastra.ai/docs/agents/
|
|
262
|
+
- [Agent Approval](https://mastra.ai/docs/agents/human-in-the-loop)
|
|
263
263
|
- [Guide: Research Coordinator](https://mastra.ai/blog/build-a-research-coordinator-with-supervisor-agents)
|
|
@@ -45,11 +45,12 @@ Mastra agents don't add this processor automatically. Add it explicitly when you
|
|
|
45
45
|
|
|
46
46
|
`ProviderHistoryCompat` includes these built-in compatibility rules:
|
|
47
47
|
|
|
48
|
-
| Rule | Provider
|
|
49
|
-
| ------------------------------------------- |
|
|
50
|
-
| `anthropic-tool-id-format` | Anthropic
|
|
51
|
-
| `cerebras-strip-reasoning-content` | Cerebras
|
|
52
|
-
| `anthropic-strip-foreign-reasoning-content` | Anthropic
|
|
48
|
+
| Rule | Provider | Timing | Behavior |
|
|
49
|
+
| ------------------------------------------- | ------------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
50
|
+
| `anthropic-tool-id-format` | Anthropic | Reactive API error recovery | Rewrites tool call IDs that contain characters outside `[a-zA-Z0-9_-]` and retries the request. |
|
|
51
|
+
| `cerebras-strip-reasoning-content` | Cerebras | Preemptive prompt rewrite | Removes assistant `reasoning` parts from the outbound prompt so they're not serialized as unsupported `reasoning_content` fields. |
|
|
52
|
+
| `anthropic-strip-foreign-reasoning-content` | Anthropic | Preemptive prompt rewrite | Removes non-Anthropic assistant `reasoning` parts from the outbound prompt. Anthropic-native thinking history is preserved. |
|
|
53
|
+
| `azure-system-reminder-transform` | Azure OpenAI | Preemptive prompt rewrite | Renames `<system-reminder>` wrappers in user text and system instructions to `<memory-context>` for the outbound request. Stored history remains unchanged. |
|
|
53
54
|
|
|
54
55
|
Preemptive rules run through `processLLMRequest` after Mastra converts messages to the model prompt format and before the prompt is sent to the provider. These rewrites affect only the current provider call.
|
|
55
56
|
|
|
@@ -41,6 +41,8 @@ const skillSearch = new SkillSearchProcessor({
|
|
|
41
41
|
|
|
42
42
|
**options.ttl** (`number`): Time-to-live for thread state in milliseconds. After this duration of inactivity, thread state will be cleaned up. Set to 0 to disable cleanup.
|
|
43
43
|
|
|
44
|
+
**options.blockingRefresh** (`boolean`): When true, awaits the skills staleness check before the first step of each request so skill changes appear in the same turn. When false, the cached catalog is served and revalidated in the background, so skill changes can lag by one turn plus the staleness cooldown (up to 30 seconds).
|
|
45
|
+
|
|
44
46
|
## Returns
|
|
45
47
|
|
|
46
48
|
**id** (`string`): Processor identifier set to 'skill-search'
|
|
@@ -112,4 +114,4 @@ Reserve workspace file tools such as `mastra_workspace_read_file` for explicit f
|
|
|
112
114
|
|
|
113
115
|
- [ToolSearchProcessor](https://mastra.ai/reference/processors/tool-search-processor)
|
|
114
116
|
- [Processors](https://mastra.ai/docs/agents/processors)
|
|
115
|
-
- [Workspace Skills](https://mastra.ai/docs/
|
|
117
|
+
- [Workspace Skills](https://mastra.ai/docs/sandbox/skills)
|
|
@@ -64,6 +64,10 @@ for await (const part of stream.fullStream) {
|
|
|
64
64
|
}
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
## Media token counting
|
|
68
|
+
|
|
69
|
+
Images and file attachments are estimated rather than tokenized. This applies to `file` message parts and to tool results shaped like `{ data, mediaType }`. Images use a flat per-image estimate, other media is estimated from its decoded byte size, and remote URLs or provider file ids use a flat fallback because their size isn't known locally. Encoded payloads such as base64 data are never counted as text, which would otherwise inflate the count by an order of magnitude and truncate history unnecessarily.
|
|
70
|
+
|
|
67
71
|
## Error behavior
|
|
68
72
|
|
|
69
73
|
When used as an input processor (both `processInput` and `processInputStep`), `TokenLimiterProcessor` throws a `TripWire` error in the following cases:
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# ToolCallFilter
|
|
4
4
|
|
|
5
|
-
The `ToolCallFilter` is an **input processor** that filters out tool calls and their results from the
|
|
5
|
+
The `ToolCallFilter` is an **input processor** that filters out tool calls and their results from the prompt sent to the model. This is useful when you want to exclude specific tool interactions from context or remove all tool calls entirely.
|
|
6
|
+
|
|
7
|
+
Filtering happens in the `processLLMRequest` hook, which runs after the message list is converted to a model prompt. Changes are transient: they affect only what's sent to the model on that call. Stored messages, memory, and UI history keep their original tool calls and results.
|
|
6
8
|
|
|
7
9
|
## Usage example
|
|
8
10
|
|
|
@@ -44,13 +46,11 @@ const filterWithCompactToolHistory = new ToolCallFilter({
|
|
|
44
46
|
|
|
45
47
|
**name** (`string`): Processor display name set to 'ToolCallFilter'
|
|
46
48
|
|
|
47
|
-
**
|
|
48
|
-
|
|
49
|
-
**processInputStep** (`(args: ProcessInputStepArgs) => Promise<ProcessInputStepResult>`): Processes agent loop step input when filterAfterToolSteps is configured. Returns no changes when step filtering is disabled
|
|
49
|
+
**processLLMRequest** (`(args: ProcessLLMRequestArgs) => Promise<ProcessLLMRequestResult | undefined>`): Filters tool calls and results out of the model prompt before it is sent to the provider. Returns undefined when nothing is filtered. Changes are transient and are not persisted to the message list or memory
|
|
50
50
|
|
|
51
51
|
## Step filtering
|
|
52
52
|
|
|
53
|
-
By default, `ToolCallFilter` filters
|
|
53
|
+
By default, `ToolCallFilter` filters tool calls from history but leaves tool calls made during the current agent loop in place. Set `filterAfterToolSteps` to also filter tool calls produced by the current loop.
|
|
54
54
|
|
|
55
55
|
`filterAfterToolSteps` counts tool-producing steps. For example, `filterAfterToolSteps: 2` keeps tool calls and results from the two most recent tool-producing steps and filters older tool calls and results. Non-tool text remains in context.
|
|
56
56
|
|
|
@@ -64,9 +64,9 @@ const filter = new ToolCallFilter({
|
|
|
64
64
|
|
|
65
65
|
## Preserve compact model output
|
|
66
66
|
|
|
67
|
-
Set `preserveModelOutput: true` to retain compact `toModelOutput` history for
|
|
67
|
+
Set `preserveModelOutput: true` to retain compact `toModelOutput` history for tool results that the filter removes. The removed tool call and result are replaced with a single text part in the prompt, so the model still sees the output while the raw tool arguments are dropped.
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Tool results without model output that can be represented as text are removed entirely.
|
|
70
70
|
|
|
71
71
|
```typescript
|
|
72
72
|
const filter = new ToolCallFilter({
|
|
@@ -44,7 +44,7 @@ Mastra recommends organizing your code into the following folders:
|
|
|
44
44
|
|
|
45
45
|
Mastra has two special folder conventions:
|
|
46
46
|
|
|
47
|
-
- `src/mastra/agents/<name>`: You can define an agent by file convention instead of constructing it in code. Learn more in the [File-based Agents](https://mastra.ai/docs/
|
|
47
|
+
- `src/mastra/agents/<name>`: You can define an agent by file convention instead of constructing it in code. Learn more in the [File-based Agents](https://mastra.ai/docs/develop) docs.
|
|
48
48
|
- `src/mastra/public`: Contents are copied into the `.build/output` directory during the build process, making them available for serving at runtime.
|
|
49
49
|
|
|
50
50
|
### Top-level files
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# LeaseProvider
|
|
4
4
|
|
|
5
|
-
`LeaseProvider` is the distributed leasing contract, separate from event delivery ([`PubSub`](https://mastra.ai/reference/pubsub/base)). Mastra's [signals layer](https://mastra.ai/docs/
|
|
5
|
+
`LeaseProvider` is the distributed leasing contract, separate from event delivery ([`PubSub`](https://mastra.ai/reference/pubsub/base)). Mastra's [signals layer](https://mastra.ai/docs/harness/signals) uses it to elect a single owner across multiple processes (for example, serverless invocations) for a resource, most commonly a thread key. The owner is the process that wakes and runs the agent stream, so other processes route follow-up work to it instead of starting a competing run.
|
|
6
6
|
|
|
7
7
|
Leasing is a distinct concern from pub/sub. A backend implements `LeaseProvider` only when it can actually coordinate a lock, such as Redis via atomic `SET`/Lua, or an in-memory map for single-process. Backends that can't lease omit it; the signals runtime feature-detects the capability and falls back to a no-op provider, preserving single-process behavior.
|
|
8
8
|
|
|
@@ -129,5 +129,5 @@ When the configured pub/sub backend doesn't implement `LeaseProvider`, the runti
|
|
|
129
129
|
|
|
130
130
|
- [PubSub](https://mastra.ai/reference/pubsub/base): The event delivery contract, separate from leasing
|
|
131
131
|
- [RedisStreamsPubSub](https://mastra.ai/reference/pubsub/redis-streams): The built-in backend that implements `LeaseProvider`
|
|
132
|
-
- [Signals](https://mastra.ai/docs/
|
|
133
|
-
- [Channels](https://mastra.ai/docs/
|
|
132
|
+
- [Signals](https://mastra.ai/docs/harness/signals): The runtime that uses leasing to coordinate thread execution across processes
|
|
133
|
+
- [Channels](https://mastra.ai/docs/channels): Uses leasing to coordinate agent runs in serverless and multi-instance deployments
|
|
@@ -131,7 +131,7 @@ When a subscriber calls `nack`, the event is republished with an incremented `de
|
|
|
131
131
|
|
|
132
132
|
## Distributed leasing
|
|
133
133
|
|
|
134
|
-
`RedisStreamsPubSub` implements the [`LeaseProvider`](https://mastra.ai/reference/pubsub/lease-provider) contract on top of the same Redis connection. The [signals runtime](https://mastra.ai/docs/
|
|
134
|
+
`RedisStreamsPubSub` implements the [`LeaseProvider`](https://mastra.ai/reference/pubsub/lease-provider) contract on top of the same Redis connection. The [signals runtime](https://mastra.ai/docs/harness/signals) uses it to elect a single owner (usually per thread key) so that across instances only one process wakes and runs the agent, and others route follow-up work to the holder. This is what makes signals work on serverless and multi-instance deployments; without a shared lease, each instance would start its own competing run.
|
|
135
135
|
|
|
136
136
|
Lease keys are namespaced under the same `keyPrefix` as topics, as `<keyPrefix>:lease:<key>`. All operations are atomic: `acquireLease` uses `SET NX PX` and refreshes its own TTL idempotently, while `releaseLease`, `renewLease`, and `transferLease` use Lua scripts that check ownership before mutating, so a concurrent renewal from another owner is never clobbered.
|
|
137
137
|
|