mastra-signals
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Send input into a Mastra agent thread at any time with signals: sendMessage, queueMessage, sendSignal, queueSignal, state signals with sendStateSignal, durable notifications with sendNotificationSignal and an inbox tool, thread streams with subscribeToThread, signal providers (SignalProvider, WebhookSignalProvider, TaskSignalProvider, RingSignals), and leases for running across processes. Use this skill whenever the user wants to message a running agent, steer or interrupt it mid-run, wake an idle thread from a webhook or CI event, keep browser or editor state in context, deliver prioritized notifications, stream a thread's output across runs, or coordinate threads across replicas. Triggers on signals, sendSignal, sendMessage, queueMessage, subscribeToThread, ifActive, ifIdle, wake, persist, accepted action, transient signal, state lane, cacheKey, notification inbox, deliveryPolicy, dedupeKey, coalesceKey, SignalProvider, poll, handleWebhook, task_write, RedisStreamsPubSub, thread lease.
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 104
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/core/dist/docs/ and the installed Agent signal method types.
- Very specific: line 106
Open a thread subscription: before sending (agent.subscribeToThread in-process, client.getAgent(id).subscribeToThread remotely).
- Very specific: line 108
Set delivery behavior: only when the defaults are wrong.
- Very specific: line 150
Model never sees
payload: Only summary and attributes reach the model.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Signals
Send input to an agent's thread whenever it arrives, receive output through one long-lived thread subscription, and route external events through notifications and providers.
When to use
- A user sends a message while the agent is still working
- A follow-up should wait until the current answer finishes
- A system event (CI result, background job, webhook) should add context or wake an idle thread
- Context that changes over time (browser page, editor state) should stay current without chat noise
- Events need a durable inbox, priorities, summaries, and retries
- A UI should stream a thread's output across many runs, with history on reconnect
- Polling or webhook sources should notify the threads that subscribed to them
- Several Mastra processes may receive input for the same thread
When NOT to use
- A one-off request and response (use
mastra-agentswithgenerateorstream) - Starting work on a cron (use
mastra-schedules, which sends threaded fires as signals) - Durable agents, background tasks, goals, and AgentController sessions (use
mastra-harness) - Chat platform adapters such as Slack or Discord (use
mastra-channels) - Thread storage, history, and working memory setup (use
mastra-memory) - Writing input or output processors in general (use
mastra-processors-guardrails) - Calling a running server from a browser in general (use
mastra-client-sdk)
Required inputs
- The thread target:
resourceIdandthreadId(Memory configured for storage-backed delivery) - What kind of input it is: user message, system context, changing state, or external event
- What should happen when the thread is active or idle (deliver, persist, discard, wake)
- For notifications: source, kind, priority, a stable
dedupeKey, and a storage adapter with the notifications domain - For providers: how external resources map to threads (
externalResourceId) - Deployment: single process, several processes on one host, or several hosts
The framework: choose the input type
| Input | API | Model sees | Stored |
| User message now | agent.sendMessage(msg, target) | user input, or <user ...attrs> | With Memory |
| User follow-up after current answer | agent.queueMessage() | user input | With Memory |
| System context | agent.sendSignal({ type: 'reactive', tagName, contents }) | <system-reminder> or custom tag | Unless transient: true |
| Queued system context | agent.queueSignal() | as above | |
| Changing named state | agent.sendStateSignal({ id, mode, cacheKey, contents }) | <state> snapshot or delta | Always (never transient) |
| External event with inbox | agent.sendNotificationSignal({ source, kind, summary, priority }) | <notification> or <notification-summary> | Durable record |
Subscribe first, then send:
import { Agent } from '@mastra/core/agent'
import { Memory } from '@mastra/memory'
import { LibSQLStore } from '@mastra/libsql'
const agent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'Help the user compare options.',
model: 'openai/gpt-6.1-sol',
memory: new Memory({ storage: new LibSQLStore({ id: 'signals-storage', url: 'file:./signals.db' }) }),
})
const thread = { resourceId: 'user_123', threadId: 'thread_456' }
const subscription = await agent.subscribeToThread({ ...thread, withRunStatus: true })
const result = agent.sendMessage('Compare that with the previous option.', thread)
const { action } = await result.accepted // 'wake' | 'deliver' | 'persist' | 'discard' | 'blocked'
for await (const chunk of subscription.stream) {
console.log(chunk) // stays open across later runs; call subscription.unsubscribe() when done
}Delivery defaults
| Thread state | Default | Alternatives |
| Active | ifActive: { behavior: 'deliver' } | persist, discard |
| Idle | ifIdle: { behavior: 'wake' } | persist, discard |
accepted resolves at routing time, not when the run ends. wake carries output. persist exposes persisted to await the write. A paused run (pending approval) returns blocked.
Input arriving during a model request can cancel and retry that request while the model has only produced reasoning or nothing yet. Once text or a tool call streams, input waits for the next loop boundary.
Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/and the installedAgentsignal method types. Otherwise fetchhttps://mastra.ai/docs/signals/overview.md,https://mastra.ai/docs/signals/sending-signals.md, andhttps://mastra.ai/reference/agents/agent.md. Signals need@mastra/core@1.39.0or later, providers 1.42.0. Trust these over memory. - Configure Memory on the agent with storage so signals persist and threads exist.
sendStateSignalcannot create a missing thread. - Open a thread subscription before sending (
agent.subscribeToThreadin-process,client.getAgent(id).subscribeToThreadremotely). AddwithInitialHistoryandwithRunStatusas needed. - Pick the input type from the table. Use
sendSignalwithtype: 'reactive'and an XML-safetagNamefor system context. - Set delivery behavior only when the defaults are wrong. Await
acceptedto catch routing failures. - For changing context, send a
snapshotfirst, thendeltaupdates, each with a newcacheKey. Or compute it in a processor withcomputeStateSignal(). - For external events, use
sendNotificationSignalwithdedupeKeyorcoalesceKey, configurenotifications.deliveryPolicyon the agent, and addcreateNotificationInboxTool(). - For sources you watch, register a
SignalProvidersubclass orWebhookSignalProviderin the agent'ssignalsarray. Persist subscriptions yourself if they must survive restarts. - For several processes, share storage and a PubSub backend with leases (
RedisStreamsPubSubacross hosts,UnixSocketPubSubon one host). On serverless, keep awakealive withwaitUntil. - Test active and idle paths, a reconnect, and a duplicate event.
Deep dive: notifications and providers
const { record, decision } = await agent.sendNotificationSignal(
{
source: 'github',
kind: 'ci-status',
priority: 'high',
summary: 'CI failed on main: 3 tests failed in the API suite.',
payload: { repository: 'acme/app', branch: 'main', runId: '123456' },
dedupeKey: 'github:acme/app:main:ci',
},
thread,
)Built-in policy: urgent always delivers. high delivers when idle, summarizes then delivers later when active. medium delivers when idle, batches when active. low always batches. Override with notifications.deliveryPolicy on the agent (decide, then sources, then priorities, then default). Summaries and deferrals run through a dispatcher scheduled every minute by default (new Mastra({ notifications: { dispatch } })). Records fail after five delivery attempts.
Providers wrap this: subclass SignalProvider from @mastra/core/signals, set id and pollInterval, implement poll(subscriptions) or handleWebhook(request), and call this.notify(notification, { resourceId, threadId }). TaskSignalProvider adds task_write, task_update, task_complete, and task_check with a tasks state lane.
Failure patterns
- Output missed at the start of a run. You sent before subscribing. Subscribe first.
- Treating
acceptedas completion. It resolves on routing. Read the stream oroutputfor results. - Two runs on one thread across replicas. The default
EventEmitterPubSubis in-process. Use a shared PubSub with leases and shared storage. GoogleCloudPubSubduplicate runs. It has no leases. Guarantee one process per thread elsewhere.- Signals lost after a crash. Runtime queues are in memory. Use
persist, state signals, or notifications for input that must survive. - State updates skipped. Same
cacheKeyand mode returns{ skipped: true, reason: 'unchanged' }. Change the key when state changes. - State signal fails on a new thread.
sendStateSignalcannot create threads. Send a message first or create the thread. transientwith a state signal orpersist. State signals cannot be transient.transientplus persist discards the signal.sendNotificationSignalthrows. Storage lacks the notifications domain. Use libSQL, Postgres, or MongoDB.- Model never sees
payload. Onlysummaryand attributes reach the model. Put what matters insummary. - Duplicate notifications from polling. Set a stable
dedupeKey. Providers do not deduplicate beforenotify(). - Provider subscriptions vanish on restart. The registry is in memory. Rehydrate in
start(). - Public provider route without verification.
requiresAuth: falseroutes must check the webhook signature on the raw body. - Expecting
hideSignalsto secure data. It only filters one subscriber's view. - Serverless function freezes mid-run. Wrap
accepted.output.consumeStream()inwaitUntilonwake.
Output format
A finished signals delivery contains:
- An agent with Memory and storage, registered on
Mastra - A thread subscription in the UI or server code, opened before input is sent
- Send calls using the right input type, with explicit
ifActive/ifIdleonly where needed - For notifications: storage with the notifications domain, a delivery policy, dedupe keys, and the inbox tool
- For providers: the provider class, registration in
signals, subscription persistence if needed, and shutdown viastop() - For multiple processes: shared storage and
pubsubonMastra, consistent lease env vars
Reference files
references/api.md- Agent signal methods, accepted actions, subscription options, state signal fields, notification records and policies, inbox tool, provider API, thread events, PubSub topologies.references/examples.md- Chat with mid-run steering, CI notifications with policy and inbox, browser state lane, polling provider, multi-process setup.references/checklist.md- Signals production checklist.
Live docs
- https://mastra.ai/docs/signals/overview
- https://mastra.ai/docs/signals/sending-signals
- https://mastra.ai/docs/signals/state-signals
- https://mastra.ai/docs/signals/notifications
- https://mastra.ai/docs/signals/thread-streams
- https://mastra.ai/docs/signals/signal-providers
- https://mastra.ai/docs/signals/running-across-processes
- https://mastra.ai/reference/signals/notifications
- https://mastra.ai/reference/signals/signal-provider
- https://mastra.ai/reference/signals/task-signal-provider
- https://mastra.ai/reference/signals/webhook-signal-provider
- https://mastra.ai/reference/signals/create-notification-inbox-tool
- https://mastra.ai/reference/signals/thread-events
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

