Conversation
🦋 Changeset detectedLatest commit: 83f5bb9 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 Key changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Agent
participant Validator
participant Handler
participant AI_SDK
participant Provider as LLM Provider
User->>Agent: execute({ thinking: { enableThinking: true, ... } })
Agent->>Validator: validateExperimentalFeatures()
alt CUA mode enabled
Validator-->>Agent: throw StagehandInvalidArgumentError
else experimental: false
Validator-->>Agent: throw ExperimentalNotConfiguredError
else valid config
Validator-->>Agent: validation passed
end
Agent->>Handler: buildProviderOptions(modelId, thinkingConfig)
alt Google (gemini)
Handler->>Handler: build google.thinkingConfig
Handler-->>Agent: { google: { thinkingConfig: {...} }, suppressWarnings: true }
else Anthropic (claude)
alt budgetTokens missing
Handler-->>Agent: throw StagehandInvalidArgumentError
else budgetTokens provided
Handler->>Handler: build anthropic.thinking
Handler-->>Agent: { anthropic: { thinking: {...} }, suppressWarnings: true }
end
else OpenAI (o1/o3/o4/gpt)
Handler->>Handler: build openai.reasoningSummary/reasoningEffort
Handler-->>Agent: { openai: {...}, suppressWarnings: false }
end
Agent->>Handler: suppressAiSdkWarnings() if needed
Handler->>Handler: set AI_SDK_LOG_WARNINGS = false
Agent->>AI_SDK: generateText/streamText(providerOptions)
AI_SDK->>Provider: API call with thinking config
Provider-->>AI_SDK: response with reasoning
AI_SDK-->>Agent: StepResult with reasoningText
Agent->>Handler: extractReasoningFromStep()
Handler->>Handler: check reasoningText, fallback to text
Handler-->>Agent: reasoning string
Agent->>Handler: restoreWarnings()
Handler->>Handler: restore AI_SDK_LOG_WARNINGS
Agent-->>User: AgentResult with reasoning
|
There was a problem hiding this comment.
3 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="packages/core/lib/v3/handlers/v3AgentHandler.ts">
<violation number="1" location="packages/core/lib/v3/handlers/v3AgentHandler.ts:149">
P2: Missing range validation for Anthropic `budgetTokens`. The PR description and types document that Anthropic requires `budgetTokens` between 1024-64000, but only existence is validated. Add bounds checking to provide a helpful error message.</violation>
</file>
<file name="packages/core/lib/v3/types/public/agent.ts">
<violation number="1" location="packages/core/lib/v3/types/public/agent.ts:360">
P3: Missing comma in JSDoc example. Developers copying this example will get a syntax error.</violation>
</file>
<file name="packages/core/tests/public-api/public-types.test.ts">
<violation number="1" location="packages/core/tests/public-api/public-types.test.ts:199">
P2: Missing `ThinkingConfig` entry in `ExpectedExportedTypes` manifest. Since this type is now used in the test cases and is publicly exported, it should be added to the type manifest at the top of the file for consistency (e.g., `ThinkingConfig: Stagehand.ThinkingConfig;`).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Resolve conflict in v3AgentHandler.ts: - Use 'done' tool name (renamed from 'close') - Keep thinkingConfig provider options from branch
pirate
left a comment
There was a problem hiding this comment.
I would recommend just passing through the config params to the LLM providers without trying to normalize the names/levels. as there are more LLM providers over time with more drift between them, we dont want to create a neverending stream of normalization work for ourselves. better to just document the recommended configs, but pass through 100% of the provider config options without trying to interpret them.
pirate
left a comment
There was a problem hiding this comment.
really really want this to be generic without special handling for individual providers as much as possible, if you can figure that out then LGTM
it's fine to patch known stuff like mediaResolution: "MEDIA_RESOLUTION_HIGH", but for everything else it should just pass-through what the user provides
|
|
||
| // Pass through OpenAI reasoning options directly | ||
| if (userOptions?.openai) { | ||
| return { openai: userOptions.openai }; |
There was a problem hiding this comment.
is there any way we can do these generically based on provider name without having to hardcode specific providers here?
e.g. just return userOptions?
| const stepReasoning = this.extractReasoningFromStep(event); | ||
| if (stepReasoning) { | ||
| state.collectedReasoning.push(stepReasoning); | ||
| this.logger({ |
There was a problem hiding this comment.
can you check if flowLogger is capturing reasoning correctly as well?
Provider Options for Agent Thinking/Reasoning
Addresses #1524
Added
providerOptionsconfiguration foragent.execute()that allows users to pass provider-specific thinking/reasoning options directly.Usage
Pass provider-specific options directly to enable thinking capabilities:
Google Gemini:
Anthropic Claude:
OpenAI:
Available Options Per Provider
thinkingConfig: { includeThoughts?, thinkingBudget? }thinking: { type: "enabled", budgetTokens } | { type: "disabled" }reasoningSummary?,reasoningEffort?Type Safety
The
providerOptionsfield uses TypeScriptPicktypes to only allow thinking-related options:GoogleThinkingOptions- onlythinkingConfigAnthropicThinkingOptions- onlythinkingOpenAIThinkingOptions- onlyreasoningSummaryandreasoningEffortAttempting to pass other provider options (e.g.,
temperature,mediaResolution) will result in a compile-time error.Notes
experimental: trueon Stagehand initStagehandInvalidArgumentErrorif used withmode: "cua"budgetTokensis required whentype: "enabled"(min 1024, max 64000)