0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00

Let Factory agents discover usable models before switching sessions (#28055)

## Summary
- Allow `factory_switch_session_model` to return models usable by the
target session when no model ID is given, without changing the session.
- Tell agents to interpret requests by family, purpose, or preference
against this credential-scoped catalog before choosing an exact ID.
- Cover discovery, no-op behavior, and user credential boundaries in
session-tool tests.

## Test plan
- `npx vitest run src/tools/session-tools.test.ts` (54 passed)
- `npx oxlint --type-aware src/tools/session-tools.ts
src/tools/session-tools.test.ts` (passed)
- `npm run check` (blocked by unrelated `src/rules/dispatcher.ts:1132`
TS2345)

## Proof
- New discovery tests failed before the tool change and pass afterward;
exact-ID switching and credential isolation still pass in the complete
suite.

## Unverified
- Full Factory type-check remains blocked by the unrelated
`src/rules/dispatcher.ts:1132` error.

## Risk
Low — switching still validates the exact selection against the existing
session-scoped catalog.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## ELI5

The tool can now show which models a session can use before it changes
anything. Agents can match a user’s model preference to this list, while
credentials keep model access isolated.

## Changes

- Updated `factory_switch_session_model` to return credential-scoped
usable models when `modelId` is omitted.
- Preserved exact-ID switching behavior when `modelId` is provided.
- Added guidance for matching model requests by family, purpose, or
preference.
- Added tests for discovery, no-op behavior, server-scoped models, user
credentials, credential isolation, and exact-ID switching.

## Validation

- `npx vitest run src/tools/session-tools.test.ts` — 54 passed.
- `npx oxlint --type-aware src/tools/session-tools.ts
src/tools/session-tools.test.ts` — passed.
- `npm run check` — blocked by unrelated `src/rules/dispatcher.ts:1132`
`TS2345`.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com>
This commit is contained in:
mastra-platform[bot] 2026-10-21 13:27:30 -07:00 • committed by GitHub
commit e88b34defe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 9 deletions