Skip to content

Conversation

@tkattkat
Copy link
Collaborator

@tkattkat tkattkat commented Jan 14, 2026

Thinking Configuration for Agent

addresses #1524

Added standardized thinking configuration for agent.execute() that maps to provider-specific options.

Usage

const result = await agent.execute({
  instruction: "Solve this complex problem",
  thinking: {
    enableThinking: true,
    thinkingLevel: "high",    // optional: "low" | "medium" | "high"
    budgetTokens: 10000       // required for Anthropic
  }
});

Provider Mappings

Config Google Anthropic OpenAI
enableThinking includeThoughts: true thinking: { type: 'enabled' } reasoningSummary: 'auto'
thinkingLevel thinkingLevel N/A reasoningEffort + reasoningSummary
budgetTokens thinkingBudget budgetTokens (required) N/A

Notes

  • Experimental: Requires experimental: true on Stagehand init
  • Not supported in CUA mode
  • Anthropic: budgetTokens is required (min 1024, max 64000) - throws helpful error if missing
  • OpenAI: thinkingLevel: "high" maps to reasoningSummary: "detailed", others to "auto"
  • AI SDK Warnings: We suppress certain warnings when thinking is enabled:
    • Google: AI SDK incorrectly warns that includeThoughts is Vertex-only, but it works fine with non-Vertex Google AI
    • Anthropic: AI SDK warns about temperature not being supported with thinking enabled, but this is handled automatically by the AI SDK so we suppress the warning.

Summary by cubic

Adds a standardized thinking configuration to agent.execute so you can enable and tune model reasoning across Google, Anthropic, and OpenAI. Implements STG-1161 and addresses #1524.

  • New Features

    • New thinking option: enableThinking, thinkingLevel, budgetTokens.
    • Provider mappings:
      • Google: includeThoughts, thinkingLevel, thinkingBudget.
      • Anthropic: thinking enabled + budgetTokens (required).
      • OpenAI: reasoningSummary/reasoningEffort (high → detailed).
    • Captures reasoning text from steps and logs it.
    • Suppresses noisy SDK warnings (Google Vertex-only notice, Anthropic temperature).
  • Migration

    • Requires experimental: true in Stagehand init.
    • Not supported in CUA mode; throws a clear error.
    • Anthropic: set budgetTokens (min 1024).

Written for commit 44f3735. Summary will update on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

🦋 Changeset detected

Latest commit: 44f3735

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 Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server 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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

Added standardized thinking configuration for agent.execute() that maps to provider-specific thinking/reasoning options (Google thinkingConfig, Anthropic thinking, OpenAI reasoningSummary/reasoningEffort). Includes validation for Anthropic's required budgetTokens, CUA mode restrictions, and experimental feature flagging. Implementation extracts reasoning text from AI SDK responses and suppresses incorrect provider warnings.

  • Added ThinkingConfig and AgentProviderOptions types with clear provider mappings
  • Implemented buildProviderOptions() to translate standardized config to provider-specific formats
  • Added AI SDK warning suppression for Google (Vertex-only warning) and Anthropic (temperature warning)
  • Enhanced reasoning extraction to capture reasoningText from thinking-enabled models
  • Added validation preventing thinking config usage with CUA mode
  • Included comprehensive test coverage for experimental validation

Issues Found:

  • Missing restoreWarnings() call in streaming onError handler, which can leave global AI_SDK_LOG_WARNINGS corrupted if error occurs
  • Minor punctuation issue in Anthropic error message (missing period)

Confidence Score: 3/5

  • Safe to merge with one critical fix needed for error handling
  • Implementation is well-structured with good type safety and validation, but has a critical bug in streaming error handling that can corrupt global state. The missing restoreWarnings() call in onError means that if an error occurs during streaming with thinking enabled, the AI_SDK_LOG_WARNINGS global will remain false, affecting all subsequent operations. This is a reliability issue that should be fixed before merge.
  • packages/core/lib/v3/handlers/v3AgentHandler.ts needs the onError handler fixed

Important Files Changed

Filename Overview
packages/core/lib/v3/handlers/v3AgentHandler.ts Added thinking config support with provider-specific mappings, warning suppression, and reasoning extraction; missing cleanup in onError handler
packages/core/lib/v3/types/public/agent.ts Added well-documented ThinkingConfig and AgentProviderOptions types with clear provider mappings
packages/core/lib/v3/agent/utils/validateExperimentalFeatures.ts Added thinking configuration validation for CUA mode and experimental feature checks

Sequence Diagram

sequenceDiagram
    participant User
    participant Agent
    participant V3AgentHandler
    participant buildProviderOptions
    participant LLMClient
    participant AISDKWarnings

    User->>Agent: execute({ thinking: { enableThinking: true, ... } })
    Agent->>V3AgentHandler: prepareAgent()
    V3AgentHandler->>buildProviderOptions: buildProviderOptions(modelId, thinkingConfig)
    
    alt Google Model
        buildProviderOptions->>buildProviderOptions: Map to thinkingConfig
        buildProviderOptions-->>V3AgentHandler: { google: { thinkingConfig, ... }, suppressWarnings: true }
    else Anthropic Model
        buildProviderOptions->>buildProviderOptions: Validate budgetTokens required
        alt budgetTokens missing
            buildProviderOptions-->>V3AgentHandler: throw StagehandInvalidArgumentError
        else budgetTokens present
            buildProviderOptions-->>V3AgentHandler: { anthropic: { thinking: { type: 'enabled', budgetTokens } }, suppressWarnings: true }
        end
    else OpenAI Model
        buildProviderOptions->>buildProviderOptions: Map to reasoningSummary/reasoningEffort
        buildProviderOptions-->>V3AgentHandler: { openai: { reasoningSummary, reasoningEffort }, suppressWarnings: false }
    end

    alt suppressWarnings
        V3AgentHandler->>AISDKWarnings: suppressAiSdkWarnings()
        AISDKWarnings-->>V3AgentHandler: restoreWarnings()
    end

    V3AgentHandler->>LLMClient: generateText/streamText(providerOptions)
    
    loop Each Step
        LLMClient->>V3AgentHandler: onStepFinish(event)
        V3AgentHandler->>V3AgentHandler: extractReasoningFromStep(event)
        alt reasoningText exists
            V3AgentHandler->>V3AgentHandler: collectedReasoning.push(reasoningText)
        else text exists
            V3AgentHandler->>V3AgentHandler: collectedReasoning.push(text)
        end
    end

    alt Stream completes
        LLMClient->>V3AgentHandler: onFinish/onAbort
        V3AgentHandler->>AISDKWarnings: restoreWarnings()
    else Stream errors
        LLMClient->>V3AgentHandler: onError
        Note over V3AgentHandler: ⚠️ restoreWarnings NOT called
    end

    V3AgentHandler-->>User: result with reasoning
Loading

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.

Additional Comments (1)

  1. packages/core/lib/v3/handlers/v3AgentHandler.ts, line 566-571 (link)

    logic: restoreWarnings not called in onError, leaving AI_SDK_LOG_WARNINGS potentially corrupted if error occurs during streaming.

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +151 to +153
"Anthropic models require 'budgetTokens' when thinking is enabled. " +
"Add 'budgetTokens' to your thinking config" +
"Example: thinking: { enableThinking: true, budgetTokens: 10000 }",
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Missing period after "thinking config" causes run-on sentence.

Suggested change
"Anthropic models require 'budgetTokens' when thinking is enabled. " +
"Add 'budgetTokens' to your thinking config" +
"Example: thinking: { enableThinking: true, budgetTokens: 10000 }",
"Anthropic models require 'budgetTokens' when thinking is enabled. " +
"Add 'budgetTokens' to your thinking config. " +
"Example: thinking: { enableThinking: true, budgetTokens: 10000 }",

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/handlers/v3AgentHandler.ts
Line: 151:153

Comment:
**syntax:** Missing period after "thinking config" causes run-on sentence.

```suggestion
          "Anthropic models require 'budgetTokens' when thinking is enabled. " +
            "Add 'budgetTokens' to your thinking config. " +
            "Example: thinking: { enableThinking: true, budgetTokens: 10000 }",
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

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.

2 issues found across 6 files

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=".changeset/slick-colts-tickle.md">

<violation number="1" location=".changeset/slick-colts-tickle.md:5">
P3: Minor grammatical issue: "a models" should be "a model's" (possessive). This text will appear in the public changelog.</violation>
</file>

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

<violation number="1" location="packages/core/lib/v3/handlers/v3AgentHandler.ts:152">
P2: Missing period and space in error message. The concatenation produces "...your thinking configExample:..." instead of proper sentence separation.</violation>
</file>

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

if (!thinkingConfig.budgetTokens) {
throw new StagehandInvalidArgumentError(
"Anthropic models require 'budgetTokens' when thinking is enabled. " +
"Add 'budgetTokens' to your thinking config" +
Copy link
Contributor

Choose a reason for hiding this comment

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

P2: Missing period and space in error message. The concatenation produces "...your thinking configExample:..." instead of proper sentence separation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/lib/v3/handlers/v3AgentHandler.ts, line 152:

<comment>Missing period and space in error message. The concatenation produces "...your thinking configExample:..." instead of proper sentence separation.</comment>

<file context>
@@ -69,6 +76,115 @@ export class V3AgentHandler {
+      if (!thinkingConfig.budgetTokens) {
+        throw new StagehandInvalidArgumentError(
+          "Anthropic models require 'budgetTokens' when thinking is enabled. " +
+            "Add 'budgetTokens' to your thinking config" +
+            "Example: thinking: { enableThinking: true, budgetTokens: 10000 }",
+        );
</file context>
Suggested change
"Add 'budgetTokens' to your thinking config" +
"Add 'budgetTokens' to your thinking config. " +

"@browserbasehq/stagehand": patch
---

Add support for customizing a models thinking configuration when using agent
Copy link
Contributor

Choose a reason for hiding this comment

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

P3: Minor grammatical issue: "a models" should be "a model's" (possessive). This text will appear in the public changelog.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .changeset/slick-colts-tickle.md, line 5:

<comment>Minor grammatical issue: "a models" should be "a model's" (possessive). This text will appear in the public changelog.</comment>

<file context>
@@ -0,0 +1,5 @@
+"@browserbasehq/stagehand": patch
+---
+
+Add support for customizing a models thinking configuration when using agent
</file context>
Suggested change
Add support for customizing a models thinking configuration when using agent
Add support for customizing a model's thinking configuration when using agent

@tkattkat tkattkat closed this Jan 14, 2026
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