Route existing harness models through native providers - #2898
Open
miguelg719 wants to merge 13 commits into
Open
Route existing harness models through native providers#2898miguelg719 wants to merge 13 commits into
miguelg719 wants to merge 13 commits into
Conversation
…/consolidation-08-native-routing
…/consolidation-08-native-routing
|
Contributor
There was a problem hiding this comment.
No issues found across 6 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant U as User/Evaluator
participant M as Mastra SDK
participant R as resolveMastraModel()
participant N as Native @ai-sdk Provider
participant G as Vercel AI Gateway
participant D as DeepAgents Runner
participant B as build_eval_model()
participant L as LangChain ChatOpenAI
participant X as xAI API (api.x.ai)
Note over M,N: Mastra Model Resolution Flow
U->>M: runMastraSession({ model, prompt })
M->>R: resolveMastraModel(model)
alt MASTRA_FORCE_GATEWAY=1 or explicit gateway/vercel route
R-->>M: Return gateway string
M->>G: Route via gateway
else Native provider with key present
R->>R: Parse provider/id from model string
alt Provider = openai/anthropic/google
R->>N: Create native provider (createOpenAI, createAnthropic, createGoogleGenerativeAI)
N-->>R: Native model instance
else Provider = xai
R->>N: Create OpenAI-compatible provider (api.x.ai)
N-->>R: Native model instance
end
R-->>M: Return native model instance
M->>N: Stream agent requests
else Missing provider key
R-->>M: Return normalized string (gateway fallback)
M->>G: Route to gateway
end
Note over D,X: DeepAgents Model Resolution Flow
U->>D: run_eval with model config
D->>B: build_eval_model(config)
alt Model starts with "xai/"
B->>B: Check XAI_API_KEY env variable
alt Key missing or blank
B-->>D: Raise ValueError (no fallback to OPENAI_API_KEY)
else Key present
B->>L: Create ChatOpenAI(base_url=api.x.ai, api_key)
L-->>B: LangChain xAI model
B-->>D: Return native xAI model
end
else Other providers (openai, anthropic, google)
B-->>D: Return model string (unchanged)
D->>G: Route via gateway
end
…/consolidation-08-native-routing
…/consolidation-08-native-routing
…/consolidation-08-native-routing
…/consolidation-08-native-routing
…/consolidation-08-native-routing
…/consolidation-08-native-routing
akeimach
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routes direct Mastra and DeepAgents model requests through the intended native provider while respecting explicit gateway routing. Missing provider configuration remains an actionable startup error.
Missing xAI credentials fail before client construction, preventing fallback to another provider’s ambient key.
Validation: 41 Python runner tests including synthetic cross-provider credential regressions; 32 Python tests, 18 Mastra routing/session tests, five build tasks, frozen dependency installation, and Mastra typecheck passed.
Stack position: 8/17. Base:
evals/consolidation-07-deepagents-lifecycle. Each PR contains the change relative to its immediate predecessor.Reviewer entry points:
packages/integrations/mastra-sdk/src/session.tspackages/integrations/mastra-sdk/tests/model-routing.test.tspackages/integrations/deepagents/runner/run_eval.pyReadiness: local validation is described above; GitHub CI and automated review feedback are pending. This PR is open as non-draft so automated reviewers can run.