Commit 5573693
authored
fix(core): respect default memory options in tool discovery (#17175)
## Summary
This fixes a user-visible logging issue where supervisor runs could emit
`Skipping memory tools (no thread or resource context)` while preparing
sub-agent tools. The sub-agent could be correctly configured with memory
through dynamic `defaultOptions`, but the supervisor background
eligibility probe calls `Agent.getToolsForExecution()` directly,
bypassing the normal `stream()` / `generate()` default option merge.
This PR updates `getToolsForExecution()` to resolve and merge the
agent's `defaultOptions` before converting tools. That makes
memory-backed tools discoverable when an agent derives its memory
thread/resource from `requestContext`, matching the path used by normal
agent execution.
## Alternative considered
Another option was to skip or suppress memory tool discovery
specifically during the background eligibility probe. That would reduce
the log noise, but it would also make the probe less representative of
the sub-agent's actual tool surface. Merging the relevant defaults keeps
tool discovery aligned with real execution behavior while preserving
explicit per-call thread/resource overrides and reserved request-context
keys.
## Validation
- `pnpm test
packages/core/src/agent/__tests__/working-memory-context.test.ts`
- `pnpm --filter ./packages/core check`
CodeRabbit CLI is installed locally, but `coderabbit doctor` reports it
is not signed in, so I could not run a local CodeRabbit review without
an auth step.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
When the supervisor peeked at what tools a sub-agent could use, it
sometimes missed memory tools that should have been available. This
change makes the probe use the same defaults-merging logic as normal
runs, so it sees memory tools correctly.
## Summary
Fixes incorrect debug logs ("Skipping memory tools (no thread or
resource context)") emitted during supervisor background eligibility
probes by making tool discovery respect an agent's dynamic
defaultOptions.
### Root Cause
The supervisor probe called Agent.getToolsForExecution() directly,
bypassing the normal stream()/generate() merge of dynamic
defaultOptions. Sub-agents can derive memory thread/resource from
defaultOptions (e.g., via requestContext), so the probe could
incorrectly consider memory tools unavailable.
### Solution
Agent.getToolsForExecution() now:
- Resolves the agent's dynamic defaultOptions for the provided
requestContext.
- Deep-merges those defaults with call-site options.
- Resolves threadId and resourceId using merged defaults while
preserving explicit per-call overrides and reserved request-context
keys.
- Forwards merged runId, memoryConfig, and autoResumeSuspendedTools into
convertTools() so memory-backed tools are discoverable during probe
discovery.
### Changes
- .changeset/dull-comics-tease.md — bump/notes for `@mastra/core` patch
release
- packages/core/src/agent/__tests__/working-memory-context.test.ts —
adds test asserting defaultOptions can supply working-memory context
when assembling tools
- packages/core/src/agent/agent.ts — update getToolsForExecution() to
resolve & merge defaultOptions before converting tools
### Validation
- Ran tests: pnpm test
packages/core/src/agent/__tests__/working-memory-context.test.ts
- Ran type/check: pnpm --filter ./packages/core check
- Note: CodeRabbit review not run locally due to auth state
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/mastra-ai/mastra/pull/17175?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent dd6a66e commit 5573693
3 files changed
Lines changed: 61 additions & 1 deletion
File tree
- .changeset
- packages/core/src/agent
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
330 | 360 | | |
331 | 361 | | |
332 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5277 | 5277 | | |
5278 | 5278 | | |
5279 | 5279 | | |
| 5280 | + | |
| 5281 | + | |
| 5282 | + | |
| 5283 | + | |
| 5284 | + | |
| 5285 | + | |
| 5286 | + | |
| 5287 | + | |
| 5288 | + | |
| 5289 | + | |
| 5290 | + | |
| 5291 | + | |
| 5292 | + | |
| 5293 | + | |
| 5294 | + | |
| 5295 | + | |
| 5296 | + | |
| 5297 | + | |
| 5298 | + | |
5280 | 5299 | | |
5281 | | - | |
| 5300 | + | |
| 5301 | + | |
| 5302 | + | |
| 5303 | + | |
| 5304 | + | |
5282 | 5305 | | |
| 5306 | + | |
| 5307 | + | |
5283 | 5308 | | |
5284 | 5309 | | |
5285 | 5310 | | |
| |||
0 commit comments