-
Notifications
You must be signed in to change notification settings - Fork 1.3k
customize thinking in agent [STG-1161] #1545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 44f3735 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 SummaryAdded standardized
Issues Found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
packages/core/lib/v3/handlers/v3AgentHandler.ts, line 566-571 (link)logic:
restoreWarningsnot called inonError, leavingAI_SDK_LOG_WARNINGSpotentially corrupted if error occurs during streaming.
5 files reviewed, 2 comments
| "Anthropic models require 'budgetTokens' when thinking is enabled. " + | ||
| "Add 'budgetTokens' to your thinking config" + | ||
| "Example: thinking: { enableThinking: true, budgetTokens: 10000 }", |
There was a problem hiding this comment.
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.
| "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.There was a problem hiding this 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" + |
There was a problem hiding this comment.
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>
| "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 |
There was a problem hiding this comment.
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>
| Add support for customizing a models thinking configuration when using agent | |
| Add support for customizing a model's thinking configuration when using agent |
Thinking Configuration for Agent
addresses #1524
Added standardized
thinkingconfiguration foragent.execute()that maps to provider-specific options.Usage
Provider Mappings
enableThinkingincludeThoughts: truethinking: { type: 'enabled' }reasoningSummary: 'auto'thinkingLevelthinkingLevelreasoningEffort+reasoningSummarybudgetTokensthinkingBudgetbudgetTokens(required)Notes
experimental: trueon Stagehand initbudgetTokensis required (min 1024, max 64000) - throws helpful error if missingthinkingLevel: "high"maps toreasoningSummary: "detailed", others to"auto"includeThoughtsis Vertex-only, but it works fine with non-Vertex Google AISummary 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
Migration
Written for commit 44f3735. Summary will update on new commits.