Skip to content

Route existing harness models through native providers - #2898

Open
miguelg719 wants to merge 13 commits into
evals/consolidation-07-deepagents-lifecyclefrom
evals/consolidation-08-native-routing
Open

Route existing harness models through native providers#2898
miguelg719 wants to merge 13 commits into
evals/consolidation-07-deepagents-lifecyclefrom
evals/consolidation-08-native-routing

Conversation

@miguelg719

@miguelg719 miguelg719 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

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:

Readiness: 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.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dcce7bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants