Skip to content

Conversation

@bennycortese
Copy link

So when I ran stagehand.agent out of the box, I kept getting the model set to gpt-4.1-mini by default. This seems to be because the Vercel AI SDK is used as the default for logging, and the model isn't ever getting set to openai/gpt-4.1-mini. This should fix both issues and hopefully fix default model configs for all providers

…l set to gpt-4.1-mini by default. This seems to be because the Vercel AI SDK is used as the default for logging, and the model isn't ever getting set to openai/gpt-4.1-mini. This should fix both issues and hopefully fix default model configs for all provides
@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

🦋 Changeset detected

Latest commit: e6f6d86

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Minor
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Fixed model configuration defaults for stagehand.agent() to ensure the correct model name is used in both logging and API calls. Previously, the model was incorrectly logged and sent to the API as gpt-4.1-mini instead of openai/gpt-4.1-mini.

Key Changes

  • Logging fix (v3.ts:1374): Changed from this.llmClient.modelName to this.modelName to ensure correct model name appears in logs
  • API call fix (v3.ts:1477-1485, 1585-1593): Explicitly set the model in AgentConfig before calling apiClient.agentExecute() to ensure the default model is properly passed when options.model is not specified

The fix ensures that when users run stagehand.agent() without specifying a model, it correctly defaults to the fully qualified model name (e.g., openai/gpt-4.1-mini) instead of an incomplete identifier.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward bug fixes that correct model name references in two specific contexts (logging and API calls). The fix uses existing instance properties (this.modelName) which are already properly initialized during V3 construction, and ensures the model configuration is properly propagated to the API client. No new logic or edge cases are introduced.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/lib/v3/v3.ts 5/5 Fixed model configuration defaults for stagehand.agent() - changed logging to use this.modelName instead of this.llmClient.modelName, and ensured model is properly set when calling API client

Sequence Diagram

sequenceDiagram
    participant User
    participant V3
    participant agent()
    participant APIClient
    participant Handler
    
    User->>V3: new V3(opts)
    V3->>V3: resolveModelConfiguration(opts.model)
    V3->>V3: this.modelName = resolvedModelName
    
    User->>V3: v3.agent(options?)
    agent()->>agent(): Log "Creating v3 agent" with this.modelName
    Note over agent(): Fixed: Use this.modelName instead of this.llmClient.modelName
    
    alt options.cua === true
        agent()->>agent(): resolveModel(options?.model || this.modelName)
        agent()->>agent(): Create agentConfigWithModel with resolved model
        User->>agent(): execute(instruction)
        agent()->>APIClient: agentExecute(agentConfigWithModel, ...)
        Note over agent(),APIClient: Fixed: Ensure model is set in config
    else default AISDK path
        agent()->>agent(): Use options?.model or this.modelName
        User->>agent(): execute(instruction)
        agent()->>APIClient: agentExecute(agentConfigWithModel, ...)
        Note over agent(),APIClient: Fixed: Ensure model is set in config
    end
    
    APIClient-->>User: AgentResult
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

1 participant