Skip to content

Add executionModel serialization to api client#1636

Merged
miguelg719 merged 6 commits intomainfrom
miguelgonzalez/stg-1229-execution-model-not-reaching-api
Jan 29, 2026
Merged

Add executionModel serialization to api client#1636
miguelg719 merged 6 commits intomainfrom
miguelgonzalez/stg-1229-execution-model-not-reaching-api

Conversation

@miguelg719
Copy link
Collaborator

@miguelg719 miguelg719 commented Jan 29, 2026

why

executionModel is not properly propagated to api

what changed

Serialize and send AgentConfig.executionModel to the API

test plan


Summary by cubic

Serialize and send AgentConfig.executionModel to the API, and document it in schemas so tool execution uses the intended model. Addresses Linear STG-1229 (execution model not reaching the API).

  • Bug Fixes
    • Serialize executionModel in StagehandAPIClient requests using prepareModelConfig when provided.
    • Add executionModel to AgentConfigSchema (Zod) and OpenAPI (input/output) as ModelConfig or string with clear description.

Written for commit 0372c38. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: 0372c38

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

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand-server Patch
@browserbasehq/stagehand Patch
@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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

✱ Stainless preview builds

This PR will update the stagehand SDKs with the following commit message.

feat: Add executionModel serialization to api client
⚠️ stagehand-csharp studio · code

There was a regression in your SDK.
generate ⚠️lint ❗test ✅

stagehand-go studio · conflict

There was a conflict between your custom code and your generated changes.
You don't need to resolve this conflict right now, but you will need to resolve it for your changes to be released to your users. Read more about why this happened here.

stagehand-python studio · conflict

There was a conflict between your custom code and your generated changes.
You don't need to resolve this conflict right now, but you will need to resolve it for your changes to be released to your users. Read more about why this happened here.

stagehand-openapi studio · code

Your SDK built successfully.
generate ✅lint ⏳test ⏳

⚠️ stagehand-typescript studio · code

There was a regression in your SDK.
generate ✅build ✅lint ✅test ❗

npm install https://pkg.stainless.com/s/stagehand-typescript/9377a1f343f50174ca2c7941989e3cb9fb2fc320/dist.tar.gz
stagehand-kotlin studio · conflict

There was a conflict between your custom code and your generated changes.
You don't need to resolve this conflict right now, but you will need to resolve it for your changes to be released to your users. Read more about why this happened here.

stagehand-java studio · conflict

There was a conflict between your custom code and your generated changes.
You don't need to resolve this conflict right now, but you will need to resolve it for your changes to be released to your users. Read more about why this happened here.

stagehand-php studio · code

Your SDK built successfully.
generate ✅lint ✅test ✅

stagehand-ruby studio · code

Your SDK built successfully.
generate ✅lint ✅test ✅


This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
If you push custom code to the preview branch, re-run this workflow to update the comment.
Last updated: 2026-01-29 21:32:48 UTC

@miguelg719 miguelg719 marked this pull request as ready for review January 29, 2026 01:54
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Serializes and sends AgentConfig.executionModel to the API, fixing STG-1229 where the execution model was not reaching the API layer.

Changes made:

  • Serialized executionModel in StagehandAPIClient.agentExecute() using prepareModelConfig() for consistent wire-format conversion
  • Added executionModel to AgentConfigSchema (Zod) as optional union type accepting ModelConfig object or string
  • Updated OpenAPI specification with executionModel in both AgentConfig (input) and AgentConfigOutput schemas
  • Added changeset documenting the patch

The implementation correctly mirrors the existing model field handling and properly integrates with the existing execution model flow used by agent tools (act, extract, fillForm).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows established patterns (mirrors existing model field handling), is consistent across all layers (API client, Zod schema, OpenAPI spec), and addresses a clear bug where executionModel was not being serialized to the API
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/lib/v3/api.ts Added executionModel serialization using prepareModelConfig, consistent with existing model field handling
packages/core/lib/v3/types/public/api.ts Added executionModel to AgentConfigSchema with union type accepting ModelConfig or string, with clear documentation
packages/server/openapi.v3.yaml Added executionModel to both AgentConfig input and AgentConfigOutput schemas with proper anyOf type definitions

Sequence Diagram

sequenceDiagram
    participant Client as Client Code
    participant V3 as V3 Instance
    participant AgentHandler as V3AgentHandler
    participant APIClient as StagehandAPIClient
    participant AgentTools as Agent Tools
    participant API as Stagehand API

    Note over Client,API: Agent Execution with executionModel

    Client->>V3: agent({ executionModel: "openai/gpt-4o-mini" })
    V3->>V3: resolveLlmClient(executionModel)
    V3->>AgentHandler: new V3AgentHandler(v3, llmClient, executionModel, ...)
    AgentHandler->>AgentTools: createAgentTools(v3, { executionModel })
    Note over AgentTools: Tools (act, extract, fillForm)<br/>now use executionModel

    Client->>V3: execute(instruction, agentConfig)
    V3->>APIClient: agentExecute(executeOptions, agentConfig)
    
    Note over APIClient: NEW: Serialize executionModel
    APIClient->>APIClient: prepareModelConfig(agentConfig.executionModel)
    Note over APIClient: Converts to wire format:<br/>{ modelName, apiKey }
    
    APIClient->>API: POST /sessions/{id}/agentExecute
    Note over API: agentConfig: {<br/>  model: {...},<br/>  executionModel: {...}<br/>}
    
    API->>API: Execute agent with tool execution model
    Note over API: Tools use executionModel<br/>for observe/act calls
    
    API-->>APIClient: AgentResult
    APIClient-->>V3: AgentResult
    V3-->>Client: AgentResult
Loading

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 3/5

  • Moderate risk: a breaking-change area in the Stagehand REST API client/server is touched without the required integration test, which could allow regressions to slip in.
  • Missing integration coverage for executionModel serialization means potential client/server mismatch could go unnoticed.
  • Pay close attention to packages/core/lib/v3/api.ts - missing integration test for executionModel serialization.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/core/lib/v3/api.ts">

<violation number="1" location="packages/core/lib/v3/api.ts:370">
P2: Rule violated: **Any breaking changes to Stagehand REST API client / server implementation must be covered by an integration test under packages/server/test**

Missing integration test for `executionModel` serialization. Rule requires that breaking changes to the REST API client must be covered by integration tests under `packages/server/test`. The existing `agentExecute.test.ts` tests other `agentConfig` fields but does not test `executionModel`. Please add a test case that verifies `executionModel` is correctly serialized and handled by the server.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant App as Application Logic
    participant Client as StagehandAPIClient
    participant Utils as prepareModelConfig
    participant API as Backend API
    participant Tools as Agent Tooling

    Note over App,Tools: Flow: Initializing and Propagating Agent Configuration

    App->>Client: createAgent(agentConfig)
    
    rect rgb(240, 240, 240)
        Note right of Client: Request Preparation
        Client->>Utils: prepareModelConfig(agentConfig.model)
        Utils-->>Client: ModelConfig (wire format)

        opt NEW: executionModel is present
            Client->>Utils: NEW: prepareModelConfig(agentConfig.executionModel)
            Utils-->>Client: ModelConfig (wire format)
        end
    end

    Client->>API: POST /v3/agent/sessions (with serialized AgentConfig)
    
    Note over API: CHANGED: Validates body via AgentConfigSchema<br/>(Includes new executionModel field)

    alt Success
        API-->>Client: 201 Created
        Client-->>App: Agent Instance
    else Validation Error
        API-->>Client: 400 Bad Request
    end

    Note over API,Tools: Runtime Execution
    API->>Tools: Initialize tools with AgentConfig
    
    opt Tools Perform Actions (Observe/Act)
        alt executionModel provided
            Tools->>Tools: Use executionModel for LLM calls
        else executionModel missing
            Tools->>Tools: Fallback: Use main model config
        end
    end
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@miguelg719
Copy link
Collaborator Author

@cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Jan 29, 2026

@cubic-dev-ai

@miguelg719 I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant SDK as SDK / User
    participant Client as StagehandAPIClient
    participant Server as API Server (v1/sessions)
    participant Agent as Agent Executor

    Note over SDK, Agent: Agent Execution Flow with Model Specialization

    SDK->>Client: agentExecute(options)
    
    Client->>Client: prepareModelConfig(agentConfig.model)
    
    alt NEW: executionModel provided
        Client->>Client: NEW: prepareModelConfig(agentConfig.executionModel)
    else executionModel missing
        Note over Client: Defaults to main model configuration
    end

    Client->>Server: POST /agentExecute (JSON body)
    Note right of Client: Includes serialized executionModel
    
    Server->>Server: Validate against AgentConfigSchema
    
    alt Validation Success
        Server->>Agent: Initialize Execution
        
        loop Tool Execution (Observe/Act)
            Agent->>Agent: NEW: Use executionModel for tool logic
            Note over Agent: Uses specific model for sub-tasks if defined
        end
        
        Agent-->>Server: Execution Result
        Server-->>SDK: 200 OK (Result)
    else Validation Error
        Server-->>SDK: 400 Bad Request
    end
Loading

@miguelg719 miguelg719 merged commit ea33052 into main Jan 29, 2026
42 of 43 checks passed
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.

3 participants