@mastra/memory 1.41.0 → 1.41.1-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.
Files changed (31) hide show
  1. package/dist/docs/SKILL.md +3 -4
  2. package/dist/docs/assets/SOURCE_MAP.json +225 -191
  3. package/dist/docs/references/docs-harness-background-tasks.md +2 -1
  4. package/dist/docs/references/docs-harness-goals.md +1 -1
  5. package/dist/docs/references/docs-knowledge-overview.md +106 -0
  6. package/dist/docs/references/docs-memory-observational-memory.md +23 -23
  7. package/dist/docs/references/docs-memory-overview.md +19 -7
  8. package/dist/docs/references/docs-memory-semantic-recall.md +24 -1
  9. package/dist/docs/references/integrations-channels-github.md +63 -24
  10. package/dist/docs/references/integrations-databases-postgresql.md +46 -0
  11. package/dist/docs/references/reference-core-getMemory.md +2 -2
  12. package/dist/docs/references/reference-core-listMemory.md +3 -3
  13. package/dist/docs/references/reference-memory-memory-class.md +1 -1
  14. package/dist/docs/references/reference-memory-observational-memory.md +9 -7
  15. package/dist/docs/references/reference-processors-token-limiter-processor.md +1 -1
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.ts +26 -8
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/processors/index.cjs +1 -1
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  23. package/dist/{src-BncFunCW.js → src-BL6KZcyR.js} +309 -399
  24. package/dist/src-BL6KZcyR.js.map +1 -0
  25. package/dist/{src-gNoNdZv8.cjs → src-Bo9Kpfk_.cjs} +308 -398
  26. package/dist/src-Bo9Kpfk_.cjs.map +1 -0
  27. package/package.json +4 -4
  28. package/dist/docs/references/reference-migrations-agentnetwork.md +0 -102
  29. package/dist/docs/references/reference-migrations-upgrade-to-v1-memory.md +0 -290
  30. package/dist/src-BncFunCW.js.map +0 -1
  31. package/dist/src-gNoNdZv8.cjs.map +0 -1
@@ -108,7 +108,7 @@ The agent now has humanlike long-term memory that persists across conversations.
108
108
  const memory = new Memory({
109
109
  options: {
110
110
  observationalMemory: {
111
- model: 'deepseek/deepseek-reasoner',
111
+ model: 'deepseek/deepseek-flash',
112
112
  },
113
113
  },
114
114
  })
@@ -154,7 +154,7 @@ export const agent = new Agent({
154
154
  memory: new Memory({
155
155
  options: {
156
156
  observationalMemory: {
157
- model: 'google/gemini-2.5-flash',
157
+ model: 'auto',
158
158
  temporalMarkers: true,
159
159
  },
160
160
  },
@@ -180,7 +180,7 @@ import { Memory } from '@mastra/memory'
180
180
  const memory = new Memory({
181
181
  options: {
182
182
  observationalMemory: {
183
- model: 'google/gemini-2.5-flash',
183
+ model: 'auto',
184
184
  activateAfterIdle: 'auto',
185
185
  activateOnProviderChange: true,
186
186
  },
@@ -196,7 +196,7 @@ import { Memory } from '@mastra/memory'
196
196
  const memory = new Memory({
197
197
  options: {
198
198
  observationalMemory: {
199
- model: 'google/gemini-2.5-flash',
199
+ model: 'auto',
200
200
  activateAfterIdle: '5m',
201
201
  observation: {
202
202
  activateAfterIdle: false,
@@ -455,7 +455,7 @@ new Agent({
455
455
  options: {
456
456
  observationalMemory: {
457
457
  observation: {
458
- model: 'deepseek/deepseek-reasoner',
458
+ model: 'deepseek/deepseek-flash',
459
459
  observeAttachments: false,
460
460
  },
461
461
  },
@@ -522,7 +522,7 @@ Set `retrieval: true` to enable the recall tool for browsing raw messages. No ve
522
522
  const memory = new Memory({
523
523
  options: {
524
524
  observationalMemory: {
525
- model: 'google/gemini-2.5-flash',
525
+ model: 'auto',
526
526
  retrieval: true,
527
527
  },
528
528
  },
@@ -540,7 +540,7 @@ const memory = new Memory({
540
540
  embedder: myEmbedder,
541
541
  options: {
542
542
  observationalMemory: {
543
- model: 'google/gemini-2.5-flash',
543
+ model: 'auto',
544
544
  retrieval: { vector: true },
545
545
  },
546
546
  },
@@ -557,7 +557,7 @@ By default, the recall tool scope is `'resource'`, the agent can list threads an
557
557
  const memory = new Memory({
558
558
  options: {
559
559
  observationalMemory: {
560
- model: 'google/gemini-2.5-flash',
560
+ model: 'auto',
561
561
  retrieval: { vector: true, scope: 'thread' },
562
562
  },
563
563
  },
@@ -572,7 +572,7 @@ Mastra injects scope-aware instructions that teach the agent when to search, lis
572
572
  const memory = new Memory({
573
573
  options: {
574
574
  observationalMemory: {
575
- model: 'google/gemini-2.5-flash',
575
+ model: 'auto',
576
576
  retrieval: {
577
577
  vector: true,
578
578
  instructions: `
@@ -641,13 +641,13 @@ const memory = new Memory({
641
641
 
642
642
  Mastra recommends using a model that has a large context window (128K+ tokens) and is fast enough to run in the background without slowing down your actions.
643
643
 
644
- To pin a model instead, set a concrete model ID. We've also successfully tested `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5`, `deepseek/deepseek-reasoner`, `deepseek/deepseek-v4-pro`, `deepseek/deepseek-v4-flash`, `xai/grok-4-1-fast`, `qwen3`, and `glm-4.7`.
644
+ To pin a model instead, set a concrete model ID. We've also successfully tested `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5`, and `deepseek/deepseek-flash`.
645
645
 
646
646
  ```typescript
647
647
  const memory = new Memory({
648
648
  options: {
649
649
  observationalMemory: {
650
- model: 'deepseek/deepseek-reasoner',
650
+ model: 'deepseek/deepseek-flash',
651
651
  },
652
652
  },
653
653
  })
@@ -655,9 +655,9 @@ const memory = new Memory({
655
655
 
656
656
  See [model configuration](https://mastra.ai/reference/memory/observational-memory) for using different models per agent.
657
657
 
658
- > **Note:** `google/gemini-2.5-flash` is unusually good at preserving detail in long output. As a result, the Reflector can produce reflections that stay above the configured `reflection.observationTokens` threshold even after the maximum compression retry. When this happens, the Reflector returns the smallest non-degenerate candidate produced during retries so the loop terminates instead of running forever.
658
+ > **Note:** Some models preserve detail in long output unusually well. In testing, `google/gemini-2.5-flash` did this. Other models may behave differently. With such a model, the Reflector can produce reflections that stay above the configured `reflection.observationTokens` threshold even after the maximum compression retry. When this happens, the Reflector returns the smallest non-degenerate candidate produced during retries so the loop terminates instead of running forever.
659
659
  >
660
- > If you'd rather have more aggressive compression on the Reflector, swap to a model that condenses more readily, such as `xai/grok-4-1-fast`, `deepseek/deepseek-v4-pro`, or `deepseek/deepseek-v4-flash`. You can keep `google/gemini-2.5-flash` for the Observer and use a different model for the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
660
+ > If you'd rather have more aggressive compression on the Reflector, pick a model that condenses more readily, such as `deepseek/deepseek-flash`. You can use a detail-preserving model for the Observer and a condensing one for the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
661
661
 
662
662
  ### Token-tiered model selection
663
663
 
@@ -678,7 +678,7 @@ const memory = new Memory({
678
678
  5_000: 'openrouter/mistralai/ministral-8b-2512',
679
679
  20_000: 'openrouter/mistralai/mistral-small-2603',
680
680
  40_000: 'openai/gpt-6-luna',
681
- 1_000_000: 'google/gemini-3.1-flash-lite-preview',
681
+ 1_000_000: 'google/gemini-3.8-flash',
682
682
  },
683
683
  }),
684
684
  },
@@ -686,7 +686,7 @@ const memory = new Memory({
686
686
  model: new ModelByInputTokens({
687
687
  upTo: {
688
688
  20_000: 'openai/gpt-6-luna',
689
- 100_000: 'google/gemini-2.5-flash',
689
+ 100_000: 'deepseek/deepseek-flash',
690
690
  },
691
691
  }),
692
692
  },
@@ -709,7 +709,7 @@ Each thread has its own observations. This scope is well tested and works well a
709
709
  const memory = new Memory({
710
710
  options: {
711
711
  observationalMemory: {
712
- model: 'google/gemini-2.5-flash',
712
+ model: 'auto',
713
713
  scope: 'thread',
714
714
  },
715
715
  },
@@ -728,7 +728,7 @@ In resource scope, observations are shared across all threads for a resource (ty
728
728
  - **Agent understanding:** Each thread sees a mix of observations from every thread for the resource. Every new thread starts with context from earlier threads, and the agent may continue work that another thread started but didn't finish.
729
729
  - **Performance:** Unobserved messages across _all_ threads are processed together, which is slow for users with many existing threads.
730
730
 
731
- A new knowledge and subconscious memory primitive for cross-thread memory is coming soon and will replace resource scope. Until then, use the alternatives below.
731
+ [Knowledge](https://mastra.ai/docs/knowledge/overview), now in alpha, gives agents shared information across threads and is planned to replace resource scope. Until it's stable, use the alternatives below.
732
732
 
733
733
  #### Cross-thread continuity without resource scope
734
734
 
@@ -743,7 +743,7 @@ Use thread scope with one or both of these features instead:
743
743
  const memory = new Memory({
744
744
  options: {
745
745
  observationalMemory: {
746
- model: 'google/gemini-2.5-flash',
746
+ model: 'auto',
747
747
  retrieval: true,
748
748
  },
749
749
  workingMemory: {
@@ -762,7 +762,7 @@ OM uses token thresholds to decide when to observe and reflect. See [token budge
762
762
  const memory = new Memory({
763
763
  options: {
764
764
  observationalMemory: {
765
- model: 'google/gemini-2.5-flash',
765
+ model: 'auto',
766
766
  observation: {
767
767
  // when to run the Observer (default: 30,000)
768
768
  messageTokens: 30_000,
@@ -873,7 +873,7 @@ With `"auto"`, Mastra chooses an idle activation TTL from the active model provi
873
873
  const memory = new Memory({
874
874
  options: {
875
875
  observationalMemory: {
876
- model: 'google/gemini-2.5-flash',
876
+ model: 'auto',
877
877
  activateAfterIdle: 'auto',
878
878
  activateOnProviderChange: true,
879
879
  },
@@ -893,7 +893,7 @@ Changing models or providers mid-thread will invalidate the prompt cache. If you
893
893
  const memory = new Memory({
894
894
  options: {
895
895
  observationalMemory: {
896
- model: 'google/gemini-2.5-flash',
896
+ model: 'auto',
897
897
  activateAfterIdle: { default: 'auto', anthropic: '1h' },
898
898
  },
899
899
  },
@@ -917,7 +917,7 @@ To disable async buffering and use synchronous observation/reflection instead:
917
917
  const memory = new Memory({
918
918
  options: {
919
919
  observationalMemory: {
920
- model: 'google/gemini-2.5-flash',
920
+ model: 'auto',
921
921
  observation: {
922
922
  bufferTokens: false,
923
923
  },
@@ -940,7 +940,7 @@ Set `observation.previousObserverTokens` to limit how many tokens of previous ob
940
940
  const memory = new Memory({
941
941
  options: {
942
942
  observationalMemory: {
943
- model: 'google/gemini-2.5-flash',
943
+ model: 'auto',
944
944
  observation: {
945
945
  previousObserverTokens: 10_000, // keep only ~10k tokens of recent observations
946
946
  },
@@ -9,8 +9,7 @@ Memory gives your agent access to earlier messages and tool results. The agent c
9
9
  Mastra agents can be configured to store [message history](https://mastra.ai/docs/memory/message-history). Additionally, you can enable:
10
10
 
11
11
  - [Observational Memory](https://mastra.ai/docs/memory/observational-memory) (Recommended): Uses background agents to maintain a dense observation log that replaces raw message history as it grows. This keeps the context window small while preserving long-term memory.
12
- - [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured user data such as names, preferences, and goals.
13
- - [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): Retrieves relevant past messages based on semantic meaning rather than exact keywords.
12
+ - [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured information about the user, the application, or the task, such as names, preferences, and goals.
14
13
  - [Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads): Share one thread between multiple users.
15
14
 
16
15
  If the combined memory exceeds the model's context limit, [memory processors](https://mastra.ai/docs/memory/memory-processors) can filter, trim, or prioritize content so the most relevant information is preserved.
@@ -161,7 +160,7 @@ const response = await memoryAgent.generate('Remember my favorite color is blue.
161
160
  })
162
161
  ```
163
162
 
164
- Scopes can also come from the agent and from the request context. Mastra combines all three sources:
163
+ Scopes can also come from the request context and from the agent. Scopes from the call and the request context arrive first. The agent's `scopes` option then adds a list to them, or a function receives them and returns the run's final set:
165
164
 
166
165
  ```typescript
167
166
  import { Agent } from '@mastra/core/agent'
@@ -170,10 +169,10 @@ import { Memory } from '@mastra/memory'
170
169
  export const memoryAgent = new Agent({
171
170
  id: 'memory-agent',
172
171
  name: 'Memory Agent',
173
- scopes: ({ requestContext }) => {
172
+ scopes: ({ scopes, requestContext }) => {
174
173
  // Set by your auth middleware. Request bodies can fill unreserved keys.
175
174
  const orgId = requestContext.get('org-id')
176
- return orgId ? [`org:${orgId}`] : []
175
+ return orgId ? [...scopes, `org:${orgId}`] : scopes
177
176
  },
178
177
  memory: new Memory(),
179
178
  })
@@ -181,7 +180,7 @@ export const memoryAgent = new Agent({
181
180
 
182
181
  The resolver's inputs must come from the server, not the client: a request body can set any request context key that isn't reserved. Trusted server middleware can also set scopes directly with the `MASTRA_SCOPES_KEY` request context key. Visit [Request Context](https://mastra.ai/docs/server/request-context) for details. Clients can't send scopes in a request body.
183
182
 
184
- You can mix scopes with `memory.resource`, `memory.thread`, or the resource and thread request context keys, as long as they agree. If a `resource:` or `thread:` scope names a different value than another source, the call throws an error.
183
+ You can mix scopes with `memory.resource`, `memory.thread`, or the resource and thread request context keys, as long as they agree. If a `resource:` or `thread:` scope names a different value than another source, the call throws an error. A `scopes` function must also return every `resource:` and `thread:` scope it receives. Dropping one throws an error.
185
184
 
186
185
  Tools, processors, and subagents receive the run's other scopes, but not its `resource:` and `thread:` scopes. Each nested agent call picks its own resource and thread.
187
186
 
@@ -189,6 +188,8 @@ Tools, processors, and subagents receive the run's other scopes, but not its `re
189
188
 
190
189
  Long conversations can fill the context window with raw message history and reduce agent performance. [Observational Memory](https://mastra.ai/docs/memory/observational-memory) uses background agents to compress older messages into observations. This reduces the context used by message history while retaining information for later turns.
191
190
 
191
+ Compression loses exact wording, so Observational Memory can register a `recall` tool that goes back to the original messages. The tool is off by default: set `retrieval: true` to enable browsing, which lists earlier messages across the resource's threads unless you pass `scope: 'thread'`. With `retrieval: { vector: true }` plus a vector store and embedder on `Memory`, it can also search by meaning. That search matches observation groups rather than raw messages, so a detail the summary dropped may not turn up, and each hit links back to the messages it came from. See [retrieval mode](https://mastra.ai/docs/memory/observational-memory).
192
+
192
193
  **For AI agents:** Using Observational Memory requires a storage provider! You either need to set it on the Mastra instance at `src/mastra/index.ts` or pass it to the Agent constructor.
193
194
 
194
195
  ```typescript
@@ -302,4 +303,15 @@ Visit [Request Context](https://mastra.ai/docs/server/request-context) for more
302
303
  - [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
303
304
  - [Tracing](https://mastra.ai/docs/observability/tracing/overview)
304
305
  - [Request Context](https://mastra.ai/docs/server/request-context)
305
- - [Mastra Code](https://code.mastra.ai/): A coding agent using Mastra's memory system
306
+ - [Mastra Code](https://code.mastra.ai/): A coding agent using Mastra's memory system
307
+
308
+ **For AI agents:** Observational Memory has a few failure modes that cause real problems.
309
+
310
+ - Thread scope requires a `threadId` when you call the agent. Without one, Observational Memory throws.
311
+ - On an existing thread, the first turn loads every stored message until the first observation completes. A large thread pays a one-time context cost.
312
+ - `lastMessages` does nothing under Observational Memory. It replaces raw history itself, so the MessageHistory processor is skipped.
313
+ - Leave `observation.observeOnContextOverflow` at its default `true`. When the main model's context overflows, it can activate buffered observations, observe pending messages, and retry the request. It skips read-only requests and only retries when it observed or activated something. With it off, the overflowing request fails.
314
+ - Some invalid options are validated on first use, not when you construct `Memory`. For example, `shareTokenBudget: true` with async buffering enabled fails on the first memory operation. Read the error instead of retrying.
315
+ - With async buffering, work continues in the background. Call `await memory.settled()` before closing storage or shutting down, or that work is lost.
316
+ - The observation mutex only works inside one process. Across processes, coordination comes from a shared PubSub backend and storage: the agent loop uses a backend with leases to run one loop per thread, and the Observer runs inside that loop. Configure every process with the same backend with leases and the same storage. See [Running across processes](https://mastra.ai/docs/signals/running-across-processes).
317
+ - Debug with `OM_DEBUG=1`, which writes `om-debug.log`, plus `getStatus()` and the `onDebugEvent` callback.
@@ -246,6 +246,29 @@ const options = {
246
246
  }
247
247
  ```
248
248
 
249
+ ### Long messages
250
+
251
+ Embedding models accept a limited number of tokens per input. Memory splits longer messages into chunks and stores each chunk as its own vector row, so every part of the message can be recalled. `maxChunkChars` sets the largest chunk in characters:
252
+
253
+ ```typescript
254
+ const agent = new Agent({
255
+ id: 'agent',
256
+ memory: new Memory({
257
+ options: {
258
+ semanticRecall: { topK: 3, messageRange: 2, maxChunkChars: 6000 },
259
+ },
260
+ }),
261
+ })
262
+ ```
263
+
264
+ The default is 16,384 characters, about 4,096 tokens of English text, which fits `openai/text-embedding-3-small` and its 8,191-token limit. The limit is in characters because each embedding provider uses its own tokenizer. Chinese, Japanese, and Korean text, and code, use more tokens per character than English, so lower `maxChunkChars` when that kind of text makes up most of your messages.
265
+
266
+ When you don't set `maxChunkChars` and the embedder declares its input limit, Memory derives the chunk size from that limit. [FastEmbed](#using-fastembed-local) models declare their 512-token window, so they need no configuration.
267
+
268
+ Each chunk row's ID comes from the message ID, so saving a message again replaces its rows. If you save a message again with shorter text through `memory.saveMessages()`, rows for chunks past the new end stay searchable until the message is updated with `memory.updateMessages()` or deleted.
269
+
270
+ Set `maxChunkChars` on the `Memory` constructor. Memory options passed per request, such as `memory.options` in `agent.stream()`, don't change it, so API callers can't force many small chunks.
271
+
249
272
  ## Server-side embeddings
250
273
 
251
274
  Some vector stores generate the embeddings themselves. With one of those, semantic recall runs without an `embedder`: the database embeds each message on write and the search string on arrival. The embedding provider stays out of your application entirely.
@@ -407,7 +430,7 @@ Memory uses a single embedder for both storing and recalling messages, so pick o
407
430
 
408
431
  Multilingual E5 produces 1024-dimensional vectors. Your vector index must be created with matching dimensions, and E5 vectors can't be mixed with vectors from another embedder in the same index.
409
432
 
410
- FastEmbed models embed at most 512 tokens per input (roughly 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding and can't be found by semantic recall. The AI SDK v3 FastEmbed models return a warning when this happens. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
433
+ FastEmbed models embed at most 512 tokens per input (roughly 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding. Semantic recall sizes its message chunks to fit this window automatically (see [Long messages](#long-messages)). Outside of memory, the AI SDK v3 FastEmbed models return a warning when an input is truncated. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
411
434
 
412
435
  ### Setting the embedding dimension
413
436
 
@@ -4,9 +4,48 @@
4
4
 
5
5
  # GitHub
6
6
 
7
- The `@mastra/github-signals` provider lets an agent follow pull requests (PRs). It polls subscribed PRs and sends [notification signals](https://mastra.ai/docs/signals/notifications) to the agent thread when relevant activity occurs.
7
+ Use GitHub with Mastra in two ways:
8
8
 
9
- ## Installation
9
+ - **Agent tools** let an agent work with repositories, issues, pull requests, releases, and workflow runs through [Mastra Connect](https://mastra.ai/docs/mastra-platform/connect).
10
+ - **[Pull request signals](#pull-request-signals)** let an agent follow pull requests (PRs) and react when they change.
11
+
12
+ ## Connect
13
+
14
+ Before you start, complete the [Connect setup](https://mastra.ai/docs/mastra-platform/connect) to install `@mastra/connect` and configure your platform project. Connect keeps GitHub credentials on the Mastra platform, so your application never stores them.
15
+
16
+ ### Agent tools
17
+
18
+ Give agents tools to search code and repositories, manage issues, pull requests, branches, files, and releases, and inspect and rerun workflow runs in GitHub.
19
+
20
+ Connect an account with the `github` provider ID. Run this command from the directory that contains your `.env` file:
21
+
22
+ ```bash
23
+ mastra connect add github
24
+ ```
25
+
26
+ Then pass [`tools()`](https://mastra.ai/reference/connect/tools) to the agent and select the provider:
27
+
28
+ ```typescript
29
+ import { Agent } from '@mastra/core/agent'
30
+ import { tools } from '@mastra/connect'
31
+
32
+ export const githubAgent = new Agent({
33
+ id: 'github-agent',
34
+ name: 'GitHub agent',
35
+ instructions:
36
+ 'You help people search code and repositories, manage issues, pull requests, branches, files, and releases, and inspect and rerun workflow runs in GitHub.',
37
+ model: '__GATEWAY_OPENAI_MODEL_LUNA__',
38
+ tools: tools({ providers: ['github'] }),
39
+ })
40
+ ```
41
+
42
+ The agent gets 49 GitHub tools, with keys such as `github_add_issue_comment`. See [GitHub tools](https://mastra.ai/reference/connect/providers) for the full list, and the [`tools()` parameters](https://mastra.ai/reference/connect/tools) to restrict tools or require approval before a call runs.
43
+
44
+ ## Pull request signals
45
+
46
+ The `@mastra/github-signals` provider polls subscribed PRs and sends [notification signals](https://mastra.ai/docs/signals/notifications) to the agent thread when relevant activity occurs. It runs on your own infrastructure and uses the GitHub CLI for access instead of a Connect connection.
47
+
48
+ ### Installation
10
49
 
11
50
  Install GitHub Signals and the memory packages used in this example:
12
51
 
@@ -34,7 +73,7 @@ yarn add @mastra/github-signals @mastra/libsql @mastra/memory
34
73
  bun add @mastra/github-signals @mastra/libsql @mastra/memory
35
74
  ```
36
75
 
37
- ## Prerequisites
76
+ ### Prerequisites
38
77
 
39
78
  GitHub Signals requires:
40
79
 
@@ -45,11 +84,11 @@ GitHub Signals requires:
45
84
 
46
85
  By default, comments from users with `admin`, `maintain`, or `write` access can trigger notifications. CodeRabbit and Devin bot comments are explicitly allowed.
47
86
 
48
- Bot authorization checks `ignoredBots` first, using an exact case-insensitive login match. Other bots can trigger notifications when they appear in `authorizedBots`, when the GitHub App is owned by a user whose repository permission appears in `authorizedPermissions`, or when the app is owned by the organization that owns the repository. The default authorized permissions are `admin`, `maintain`, and `write`.
87
+ Bot authorization checks `ignoredBots` first, using an exact case-insensitive login match. Other bots can trigger notifications when they're listed in `authorizedBots`, when the GitHub App is owned by a user whose repository permission is listed in `authorizedPermissions`, or when the app is owned by the organization that owns the repository. The default authorized permissions are `admin`, `maintain`, and `write`.
49
88
 
50
- Failed, inaccessible, malformed, and unsupported app-owner lookups deny the bot comment. Successful app-owner lookups are cached for 24 hours; failed lookups aren't cached.
89
+ Failed, inaccessible, malformed, and unsupported app-owner lookups deny the bot comment. Successful app-owner lookups are cached for 24 hours. Failed lookups aren't cached.
51
90
 
52
- ## Agent and subscription
91
+ ### Agent and subscription
53
92
 
54
93
  Create one `GithubSignals` instance and register it on the agent. Register the agent and a storage adapter on the Mastra instance:
55
94
 
@@ -99,35 +138,35 @@ The provider syncs the PR immediately, stores the subscription, and starts polli
99
138
 
100
139
  A thread has one current GitHub Signals subscription. Subscribing it to another PR replaces the existing subscription.
101
140
 
102
- ## Subscription modes
141
+ ### Subscription modes
103
142
 
104
143
  GitHub Signals supports two subscription modes:
105
144
 
106
145
  - `review`: Follows new head revisions, authorized latest PR comments, and observable review-thread-state changes, including when all review threads become resolved.
107
- - `working`: Follows all actionable PR activity detected by the provider. Comment-bearing notifications remain subject to existing authorization gates. This is the default when `mode` is omitted and for stored subscriptions without a valid mode.
146
+ - `working`: Follows all PR activity that can trigger a notification detected by the provider. Comment-bearing notifications remain subject to existing authorization gates. This is the default when `mode` is omitted and for stored subscriptions without a valid mode.
108
147
 
109
148
  The following table shows the observable behavior of each mode:
110
149
 
111
- | Pull request activity | `working` | `review` |
112
- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
113
- | First observation | Sends a baseline notification | Saves all cursors without notifying unless the PR is closed or merged; then notifies and removes the subscription |
114
- | New commit or force-push | Notifies when the latest comment author is authorized | Notifies without requiring a comment author |
115
- | New authorized latest PR comment | Notifies | Notifies |
116
- | Observable review-thread-state change | Notifies while unresolved threads remain | Notifies, including when all review threads become resolved |
117
- | Continuous integration checks start, fail, or recover | Notifies | Saves the new state without notifying |
118
- | Merge conflicts appear or resolve | Notifies | Saves the new state without notifying |
119
- | Other actionable aggregate PR activity | Notifies when applicable authorization checks pass | Saves the new state without notifying |
120
- | PR closes without merging | Notifies and keeps the subscription | Notifies and removes the subscription |
121
- | PR reopens | Notifies | Doesn't notify because the earlier close removed the subscription |
122
- | PR merges | Notifies and removes the subscription | Notifies and removes the subscription |
123
-
124
- Review mode uses the latest generic PR comment exposed by `gitcrawl`. The snapshot doesn't distinguish general PR conversation from inline review comments. Comment notifications require an authorized author because they include comment content. Review-state notifications contain only provider-generated state summaries and aren't author-gated.
150
+ | Pull request activity | `working` | `review` |
151
+ | ----------------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
152
+ | First observation | Sends a baseline notification | Saves all cursors without notifying unless the PR is closed or merged; then notifies and removes the subscription |
153
+ | New commit or force-push | Notifies when the latest comment author is authorized | Notifies without requiring a comment author |
154
+ | New authorized latest PR comment | Notifies | Notifies |
155
+ | Observable review-thread-state change | Notifies while unresolved threads remain | Notifies, including when all review threads become resolved |
156
+ | Continuous integration checks start, fail, or recover | Notifies | Saves the new state without notifying |
157
+ | Merge conflicts appear or resolve | Notifies | Saves the new state without notifying |
158
+ | Other aggregate PR activity that can trigger a notification | Notifies when applicable authorization checks pass | Saves the new state without notifying |
159
+ | PR closes without merging | Notifies and keeps the subscription | Notifies and removes the subscription |
160
+ | PR reopens | Notifies | Doesn't notify because the earlier close removed the subscription |
161
+ | PR merges | Notifies and removes the subscription | Notifies and removes the subscription |
162
+
163
+ Review mode uses the latest generic PR comment exposed by `gitcrawl`, and the snapshot doesn't distinguish general PR conversation from inline review comments. Comment notifications require an authorized author because they include comment content. Review-state notifications contain only provider-generated state summaries and aren't author-gated.
125
164
 
126
165
  The review-state cursor includes the unresolved thread count and the latest unresolved thread timestamp. It reports when the count reaches zero, but it can't report replies on threads that are already resolved.
127
166
 
128
167
  During subscription, a PR already known to be closed or merged isn't stored and doesn't send an activity notification. Otherwise, review mode silently saves its first available non-terminal snapshot, including when the subscribe-time snapshot fails and a later poll supplies the first observation. If the first available poll snapshot or a later snapshot is closed or merged, the provider sends a terminal notification and removes the subscription. It doesn't follow a later reopen unless you subscribe again.
129
168
 
130
- ## Subscription tools
169
+ ### Subscription tools
131
170
 
132
171
  The provider adds `github_subscribe_pr` and `github_unsubscribe_pr` tools to the agent. Pass `mode` when subscribing:
133
172
 
@@ -142,7 +181,7 @@ The provider adds `github_subscribe_pr` and `github_unsubscribe_pr` tools to the
142
181
 
143
182
  Omitting `mode` selects `working`. Don't subscribe for a one-off PR inspection.
144
183
 
145
- ## MastraCode commands
184
+ ### MastraCode commands
146
185
 
147
186
  In MastraCode, use the spaced `--mode` flag with a PR number, `owner/repo#number`, or full GitHub PR URL:
148
187
 
@@ -243,6 +243,52 @@ const thread = await memoryStore?.getThreadById({ threadId: '...' })
243
243
 
244
244
  > **Warning:** If `init()` isn't called, tables won't be created and storage operations will fail silently or throw errors.
245
245
 
246
+ ### Managed PostgreSQL and connection poolers
247
+
248
+ `PostgresStore` connects to managed PostgreSQL providers with the connection string they give you. No provider-specific package is required.
249
+
250
+ `init()` runs all schema changes on a single connection, so it works through transaction-mode connection poolers such as PgBouncer. You can use the provider's pooled connection string and let Mastra create the schema on startup.
251
+
252
+ #### Separate schema initialization
253
+
254
+ If the runtime database role can't create tables or indexes, run `init()` once during deployment with a role that can:
255
+
256
+ ```typescript
257
+ import { PostgresStore } from '@mastra/pg'
258
+
259
+ const storage = new PostgresStore({
260
+ id: 'pg-storage-init',
261
+ connectionString: process.env.DATABASE_ADMIN_URL,
262
+ })
263
+
264
+ try {
265
+ await storage.init()
266
+ // Only needed if the application uses Knowledge
267
+ await storage.initKnowledge()
268
+ } finally {
269
+ await storage.close()
270
+ }
271
+ ```
272
+
273
+ The runtime role needs read and write access to the tables this script creates. See [PostgreSQL privileges](https://www.postgresql.org/docs/current/ddl-priv.html).
274
+
275
+ Then set `disableInit: true` on the runtime store so it skips schema creation:
276
+
277
+ ```typescript
278
+ import { Mastra } from '@mastra/core'
279
+ import { PostgresStore } from '@mastra/pg'
280
+
281
+ export const mastra = new Mastra({
282
+ storage: new PostgresStore({
283
+ id: 'pg-storage',
284
+ connectionString: process.env.DATABASE_URL,
285
+ disableInit: true,
286
+ }),
287
+ })
288
+ ```
289
+
290
+ `disableInit: true` also makes explicit `init()` calls a no-op, so leave it off the store in the deployment script.
291
+
246
292
  ### Using an Existing Pool
247
293
 
248
294
  If you already have a `pg.Pool` in your application (e.g., shared with an ORM or for Row Level Security), you can pass it directly to `PostgresStore`:
@@ -20,11 +20,11 @@ const thread = await memory.createThread({
20
20
 
21
21
  ## Parameters
22
22
 
23
- **key** (`TMemoryKey extends keyof TMemory`): The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.
23
+ **name** (`TMemoryName extends keyof TMemory`): The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.
24
24
 
25
25
  ## Returns
26
26
 
27
- **memory** (`TMemory[TMemoryKey]`): The memory instance with the specified key. Throws an error if the memory is not found.
27
+ **memory** (`TMemory[TMemoryName]`): The memory instance with the specified key. Throws an error if the memory is not found.
28
28
 
29
29
  ## Example: Registering and retrieving memory
30
30
 
@@ -9,7 +9,7 @@ The `.listMemory()` method returns all memory instances registered with the Mast
9
9
  ## Usage example
10
10
 
11
11
  ```typescript
12
- const memoryInstances = mastra.listMemory()
12
+ const memoryInstances = mastra.listMemory() ?? {}
13
13
 
14
14
  for (const [key, memory] of Object.entries(memoryInstances)) {
15
15
  console.log(`Memory "${key}": ${memory.id}`)
@@ -22,7 +22,7 @@ This method takes no parameters.
22
22
 
23
23
  ## Returns
24
24
 
25
- **memory** (`Record<string, MastraMemory>`): An object containing all registered memory instances, keyed by their registry keys.
25
+ **memory** (`Record<string, MastraMemory> | undefined`): An object containing all registered memory instances, keyed by their registry keys.
26
26
 
27
27
  ## Example: Checking registered memory
28
28
 
@@ -49,7 +49,7 @@ const mastra = new Mastra({
49
49
  })
50
50
 
51
51
  // List all registered memory instances
52
- const allMemory = mastra.listMemory()
52
+ const allMemory = mastra.listMemory() ?? {}
53
53
  console.log(Object.keys(allMemory)) // ["conversationMemory", "analyticsMemory"]
54
54
  ```
55
55
 
@@ -49,7 +49,7 @@ export const agent = new Agent({
49
49
 
50
50
  **options.retainFullInput** (`boolean`): When true, the request input is processed exactly as supplied instead of being filtered against stored history. Use this when you assemble the input yourself and need the message sequence preserved. Stored history is still loaded underneath, and every input message that isn't already stored is saved to the thread, including few-shot examples. Can be set per call on memory.options or agent-wide in the memory constructor options.
51
51
 
52
- **options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires a vector store, and an embedder unless the vector store embeds text itself (isSelfEmbedding). Default topK is 4, default messageRange is {before: 1, after: 1}.
52
+ **options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource'; maxChunkChars?: number }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires a vector store, and an embedder unless the vector store embeds text itself (isSelfEmbedding). Default topK is 4, default messageRange is {before: 1, after: 1}. maxChunkChars caps the characters of message text per embedded chunk; see Long messages.
53
53
 
54
54
  **options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be { enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' } or { enabled: boolean } to disable.
55
55
 
@@ -43,6 +43,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
43
43
 
44
44
  **resolveModel** (`(modelId: string, context: { requestContext?: RequestContext }) => MastraModelConfig | Promise<MastraModelConfig>`): Creates the model automatic selection picked, so it can use your credentials and routing. Receives only concrete model IDs, never "auto". When omitted, the picked ID goes through Mastra model routing.
45
45
 
46
+ **canUseProvider** (`(providerId: string, context: { requestContext?: RequestContext }) => boolean`): Decides whether "auto" treats a provider as usable. Replaces the built-in GOOGLE_GENERATIVE_AI_API_KEY check that decides whether automatic selection prefers Gemini. Return false for any provider the current request cannot authenticate, for example a provider whose key is not available in the request context. The context.requestContext is the request context of the run making the OM model call, so credentials can be resolved per request instead of from the server environment. See the model row for the selection order.
47
+
46
48
  **scope** (`'resource' | 'thread'`): Memory scope for observations. 'thread' keeps observations per-thread. 'resource' is deprecated and will be removed in a future release. It shares observations across all threads for a resource and works much worse than thread scope for prompt caching and agent understanding. For cross-thread continuity, use thread scope with retrieval or resource-scoped working memory. See resource scope (deprecated). (Default: `'thread'`)
47
49
 
48
50
  **activateAfterIdle** (`number | string | false | "auto" | Record<string, number | string | false | "auto">`): Time before buffered observations are forced to activate after inactivity, even before observation.messageTokens is reached. Accepts a numeric millisecond value such as 300_000, duration strings like "5m" or "1hr", "auto" for a provider-aware prompt cache TTL, false to disable inherited observation idle activation, or an object of per-provider TTLs such as { default: "auto", anthropic: "1h" }. Object keys match the actor model provider before the first ., case-insensitively, so anthropic covers the direct Anthropic provider but not Claude through another provider such as amazon-bedrock; default covers every other provider. Reflections do not inherit this setting. Use reflection.activateAfterIdle to opt reflections into idle activation.
@@ -71,7 +73,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
71
73
 
72
74
  **observation.manageWorkingMemory** (`boolean`): Let the Observer manage working memory through OM extraction. Adds WorkingMemoryExtractor, defaults workingMemory.agentManaged to false, and defaults workingMemory.useStateSignals to true. See Working memory updates.
73
75
 
74
- **observation.observeAttachments** (`'auto' | boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines. true (default) forwards all attachments. false drops all attachments while keeping placeholders visible. 'auto' uses the provider capabilities registry to decide: attachments are forwarded when the Observer model supports multimodal input, dropped otherwise, and forwarded when no capability data is available for the model. An array is a case-insensitive mimeType allowlist supporting exact matches ('application/pdf'), wildcard subtypes ('image/\*'), and bare '\*' for everything. Useful when the Observer model is text-only (e.g. some DeepSeek endpoints) while the main agent uses a multimodal model. Tool-result attachments are filtered using the same rule.
76
+ **observation.observeAttachments** (`'auto' | boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines. By default only images and PDFs are forwarded. true forwards all attachments. false drops all attachments while keeping placeholders visible. 'auto' uses the provider capabilities registry to decide: attachments are forwarded when the Observer model supports multimodal input, dropped otherwise, and forwarded when no capability data is available for the model. An array is a case-insensitive mimeType allowlist supporting exact matches ('application/pdf'), wildcard subtypes ('image/\*'), and bare '\*' for everything. Useful when the Observer model is text-only (e.g. some DeepSeek endpoints) while the main agent uses a multimodal model, or when you only want specific file types forwarded. Tool-result attachments are filtered using the same rule.
75
77
 
76
78
  **observation.maxRetries** (`number`): Retries after the initial Observer model call on transient provider errors. Governs OM's own retry ladder; the Observer model call itself is configured with no provider-level retries.
77
79
 
@@ -244,7 +246,7 @@ export const agent = new Agent({
244
246
  memory: new Memory({
245
247
  options: {
246
248
  observationalMemory: {
247
- model: 'google/gemini-2.5-flash',
249
+ model: 'auto',
248
250
  observation: {
249
251
  messageTokens: 20_000,
250
252
  },
@@ -325,7 +327,7 @@ export const agent = new Agent({
325
327
  options: {
326
328
  observationalMemory: {
327
329
  observation: {
328
- model: 'google/gemini-2.5-flash',
330
+ model: 'auto',
329
331
  },
330
332
  reflection: {
331
333
  model: 'openai/gpt-6-luna',
@@ -352,7 +354,7 @@ export const agent = new Agent({
352
354
  memory: new Memory({
353
355
  options: {
354
356
  observationalMemory: {
355
- model: 'google/gemini-2.5-flash',
357
+ model: 'auto',
356
358
  observation: {
357
359
  // Focus observations on health-related preferences and goals
358
360
  instruction:
@@ -397,7 +399,7 @@ export const agent = new Agent({
397
399
  memory: new Memory({
398
400
  options: {
399
401
  observationalMemory: {
400
- model: 'google/gemini-2.5-flash',
402
+ model: 'auto',
401
403
  observation: {
402
404
  messageTokens: 30_000,
403
405
  // Buffer every 5k tokens (runs in background)
@@ -424,7 +426,7 @@ To disable async buffering entirely:
424
426
 
425
427
  ```typescript
426
428
  observationalMemory: {
427
- model: "google/gemini-2.5-flash",
429
+ model: "auto",
428
430
  observation: {
429
431
  bufferTokens: false,
430
432
  },
@@ -910,7 +912,7 @@ Group IDs in search results include the record that holds them (`groupId@recordI
910
912
  new ModelByInputTokens(config)
911
913
  ```
912
914
 
913
- Where `config` is an object with `upTo` keys that map token thresholds (numbers) to model targets.
915
+ Where `config` is an object with `upTo` keys that map token thresholds (numbers) to model targets. Each tier needs a concrete model. The example below names specific models instead of `"auto"`.
914
916
 
915
917
  #### Example
916
918