Skip to content

[STG-2463] fix: silence AI SDK "system message in messages" warning on agent.execute() - #2305

Merged
seanmcguire12 merged 2 commits into
mainfrom
shrey/stg-fix-aisdk-system-in-messages
Jul 6, 2026
Merged

[STG-2463] fix: silence AI SDK "system message in messages" warning on agent.execute()#2305
seanmcguire12 merged 2 commits into
mainfrom
shrey/stg-fix-aisdk-system-in-messages

Conversation

@shrey150

@shrey150 shrey150 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What & why

Every hybrid/DOM agent.execute() call prints this AI SDK v5 warning to the console:

AI SDK Warning: System messages in the prompt or messages fields can be a security risk because they may enable prompt injection attacks. Use the system option instead when possible. Set allowSystemInMessages to true to suppress this warning, or false to throw an error.

It's cosmetic (a warning, not an error), but it fires on essentially every agent run, and the "prompt injection" wording reads alarmingly enough to generate support tickets — it did (a customer reported it).

Root cause

The agent loop builds its system prompt as a system-role message inside the messages array (prependSystemMessage() in v3AgentHandler.ts) rather than the top-level system param. This is deliberate: it lets the system prompt carry Anthropic ephemeral cache-control via providerOptions (see the function's own comment). AI SDK v5 warns whenever it sees a system message in messages, since it can't distinguish a trusted, library-authored system prompt from untrusted input.

The committed lockfile pinned ai@5.0.133, which predates this warning — so the repo build never saw it, but the ^5.0.133 range means real installs resolve to newer 5.0.x (e.g. 5.0.209) that do warn. That's why users hit it and CI didn't.

Fix

  • Pass allowSystemInMessages: true to the generateText / streamText calls in the agent loop. This is the AI-SDK-sanctioned opt-out for an intentional system-in-messages structure, and it keeps prompt caching intact (vs. moving to top-level system:, which cannot carry per-message providerOptions and would regress Anthropic cache-control).
  • Bump the ai floor ^5.0.133 → ^5.0.185, where allowSystemInMessages is a typed option.
  • Add an explicit return type (LanguageModelV2) to getAISDKLanguageModel. The ai bump pulls a newer @ai-sdk/provider, and without the annotation tsc emits TS2742 ("inferred type … not portable").

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
BEFORE — published @browserbasehq/stagehand@3.6.0 (resolves ai@5.0.209), hybrid agent.execute() on a real Browserbase session, console captured AI SDK system-in-messages warning emitted: YES (1) — full "…security risk…prompt injection…" text Reproduces the customer's exact symptom on the version they run.
AFTER — local patched build (this branch, same ai@5.0.209), identical hybrid agent.execute() flow, same model, real Browserbase session AI SDK system-in-messages warning emitted: NO (0); run exits cleanly Proves the fix removes the warning without breaking the agent run. Same harness as BEFORE → clean A/B.
pnpm turbo run build --filter @browserbasehq/stagehand Tasks: 3 successful, 3 total (fails with TS2742 before the LLMProvider annotation) Typecheck + emit green; confirms the ai bump + annotation compile.
prettier --check + eslint on changed files All matched files use Prettier code style!, eslint clean Style/lint gates pass.

A/B model: anthropic/claude-haiku-4-5-20251001. Both runs used identical mode: "hybrid" + systemPrompt config (the customer's shape).

Closes STG-2463.

🤖 Generated with Claude Code


Summary by cubic

Silences the AI SDK v5 “system message in messages” warning during hybrid/DOM agent.execute() runs while preserving Anthropic cache-control. Addresses STG-2463.

  • Bug Fixes

    • Pass allowSystemInMessages: true to generateText/streamText so the agent’s system prompt in messages does not warn and caching stays intact.
  • Dependencies

    • Bump ai to ^5.0.185 (lock resolves to 5.0.209).
    • Add explicit LanguageModelV2 return type in getAISDKLanguageModel to avoid TS2742 with newer @ai-sdk/provider.

Written for commit bfc10af. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bfc10af

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-v3 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

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

Copy link
Copy Markdown
Contributor

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 Client as Agent Caller
    participant Handler as V3AgentHandler
    participant LLMClient as LLM Client
    participant AI_SDK as AI SDK
    participant Cache as Anthropic Cache

    Note over Handler: System prompt built as system-role message<br/>(carries providerOptions for<br/>ephemeral cache‑control)

    Client->>Handler: agent.execute(systemPrompt, messages)

    Handler->>Handler: prependSystemMessage(systemPrompt, messages)<br/>→ messages array with system role + providerOptions

    Handler->>LLMClient: generateText({<br/>    messages,<br/>    allowSystemInMessages: true,<br/>    tools,<br/>    ...<br/>})
    Note right of Handler: NEW: allowSystemInMessages suppresses<br/>the “system message in messages” warning

    LLMClient->>AI_SDK: generateText({<br/>    messages,<br/>    allowSystemInMessages: true,<br/>    ...<br/>})

    alt allowSystemInMessages === true
        AI_SDK->>AI_SDK: No warning emitted<br/>(trusted system prompt)
    end

    AI_SDK->>Cache: System message with providerOptions<br/>(Anthropic cache‑control)
    Cache-->>AI_SDK: Cached response (if applicable)

    AI_SDK-->>LLMClient: Generated result
    LLMClient-->>Handler: Result

    Note over Handler: Streamed path also uses<br/>allowSystemInMessages: true

    opt Streaming path
        Handler->>LLMClient: streamText({<br/>            messages,<br/>            allowSystemInMessages: true,<br/>            ...<br/>        })
        Note right of LLMClient: Same flag applied to streamText
        LLMClient->>AI_SDK: streamText(...)
        AI_SDK-->>LLMClient: Streamed chunks
        LLMClient-->>Handler: Streamed result
    end

    Handler-->>Client: Final response

    Note over Handler,AI_SDK: Dependency bump ai ^5.0.133 → ^5.0.185<br/>enables allowSystemInMessages as a typed option.
    Note over LLMClient: Explicit return type LanguageModelV2<br/>on getAISDKLanguageModel avoids TS2742.
Loading

Re-trigger cubic

@shrey150
shrey150 force-pushed the shrey/stg-fix-aisdk-system-in-messages branch from 7454233 to cef8a05 Compare July 2, 2026 18:39
The hybrid/DOM agent loop supplies its system prompt as a system-role
message (so it can carry Anthropic ephemeral cache-control via
providerOptions), which trips AI SDK v5's "System messages in the prompt
or messages fields can be a security risk" warning on every
agent.execute() call. Pass allowSystemInMessages: true to
generateText/streamText so the intentional, Stagehand-authored system
prompt no longer warns, while keeping prompt caching intact.

Bump the ai floor to ^5.0.185 (where allowSystemInMessages exists) and
add an explicit return type to getAISDKLanguageModel so tsc stays
portable under the newer @ai-sdk/provider it pulls in.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shrey150
shrey150 force-pushed the shrey/stg-fix-aisdk-system-in-messages branch from cef8a05 to 257ea32 Compare July 2, 2026 19:30
Comment thread .changeset/aisdk-allow-system-in-messages.md Outdated
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@seanmcguire12
seanmcguire12 merged commit cd1daad into main Jul 6, 2026
701 of 703 checks passed
seanmcguire12 pushed a commit that referenced this pull request Jul 13, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/stagehand@3.7.0

### Minor Changes

- [#2283](#2283)
[`871ca7e`](871ca7e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add
`context.setDomainPolicy({ allowedDomains: ["allowed.domain"] })` which
allows users to define a set of domains that are accessible to stagehand

- [#2274](#2274)
[`f31980f`](f31980f)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add
`context.setDomainPolicy({blockedDomains: ["some.domain"]})` which
allows users to define a list of domains that will be blocked by
stagehand

### Patch Changes

- [#2305](#2305)
[`cd1daad`](cd1daad)
Thanks [@shrey150](https://github.com/shrey150)! - Remove the noisy AI
SDK "system message in messages" warning logged on every hybrid/DOM
`agent.execute()` call.

- [#2328](#2328)
[`d287ff4`](d287ff4)
Thanks [@miguelg719](https://github.com/miguelg719)! - Allow modelName
"auto" in the constructor and per-primitive model overrides when running
through the Stagehand API

- [#2294](#2294)
[`3938590`](3938590)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! -
automatically close popups that violate user defined domain policy

- [#2298](#2298)
[`892701a`](892701a)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Fix CUA
`keypress` actions to press key combinations as a single chord.

- [#2345](#2345)
[`21826c7`](21826c7)
Thanks [@monadoid](https://github.com/monadoid)! - Repair malformed
UTF-16 snapshot text before it reaches model prompts.

- [#2306](#2306)
[`8dcef1b`](8dcef1b)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Use the
screenshot provider's declared media type when sending CUA image
payloads. The `setScreenshotProvider` callback now returns
`ScreenshotProviderResult` (`{ base64, mediaType }`) instead of a bare
base64 string.

- [#2273](#2273)
[`93a23d3`](93a23d3)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add support for
the new `google/gemini-3.5-flash` computer-use tools model

- [#2278](#2278)
[`022d68f`](022d68f)
Thanks [@shrey150](https://github.com/shrey150)! - Fix `TypeError:
Converting circular structure to JSON` when creating an agent with MCP
`integrations` that include a `Client` instance (e.g. a local/stdio
server from `connectToMCPServer`). The agent-creation log serialized the
raw `integrations` array, and a live MCP `Client` is circular. It now
logs a safe descriptor (URL strings kept, client instances summarized)
so `agent({ integrations: [client] })` works.

- [#2288](#2288)
[`bb5ffa6`](bb5ffa6)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - clean up
cdp session event handlers on target detach

## @browserbasehq/stagehand-evals@2.0.4

### Patch Changes

- Updated dependencies
\[[`cd1daad`](cd1daad),
[`d287ff4`](d287ff4),
[`3938590`](3938590),
[`892701a`](892701a),
[`21826c7`](21826c7),
[`8dcef1b`](8dcef1b),
[`93a23d3`](93a23d3),
[`871ca7e`](871ca7e),
[`022d68f`](022d68f),
[`bb5ffa6`](bb5ffa6),
[`f31980f`](f31980f)]:
    -   @browserbasehq/stagehand@3.7.0

## @browserbasehq/stagehand-server-v3@3.7.2

### Patch Changes

- Updated dependencies
\[[`cd1daad`](cd1daad),
[`d287ff4`](d287ff4),
[`3938590`](3938590),
[`892701a`](892701a),
[`21826c7`](21826c7),
[`8dcef1b`](8dcef1b),
[`93a23d3`](93a23d3),
[`871ca7e`](871ca7e),
[`022d68f`](022d68f),
[`bb5ffa6`](bb5ffa6),
[`f31980f`](f31980f)]:
    -   @browserbasehq/stagehand@3.7.0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
shrey150 added a commit that referenced this pull request Jul 14, 2026
…ct/observe (#2359)

## What & why

[#2305](#2305) silenced the
AI SDK v5 "system message in messages" warning, but only for
`agent.execute()`'s outer loop (`v3AgentHandler.ts`). `act()`,
`extract()`, and `observe()` build their system prompt the same way — a
`{ role: "system", ... }` message inside the `messages` array — and
route through a separate call path that was never patched:
`AISdkClient.createChatCompletion()` in
`packages/core/lib/v3/llm/aisdk.ts` (the default client for any
`"provider/model"` string), plus the identical pattern in the public
BYOC client `packages/core/lib/v3/external_clients/aisdk.ts`.

Since the hybrid/DOM agent's own `act`/`extract`/`observe` tools call
these primitives internally on every step, an `agent.execute()` run that
clicks/types repeatedly still spammed the warning even after upgrading
past the first fix — a customer reported exactly this.

### Fix
Add `allowSystemInMessages: true` to the 4 remaining
`generateObject`/`generateText` call sites (2 in `llm/aisdk.ts`, 2 in
`external_clients/aisdk.ts`), same pattern as the original fix.

## E2E Test Matrix

| Command / flow | Observed output | Confidence / sufficiency |
| --- | --- | --- |
| **BEFORE** — published `@browserbasehq/stagehand@alpha` (already
includes #2305's fix), `act()` → `extract()` → `observe()` chain on a
real Browserbase session | `AI SDK system-in-messages warnings emitted:
YES (4)` | Reproduces the customer's exact symptom on the current alpha
— confirms #2305 left this path unpatched. |
| **AFTER** — local patched build (this branch), identical `act()` →
`extract()` → `observe()` chain, same model, real Browserbase session |
`AI SDK system-in-messages warnings emitted: NO (0)` | Proves the fix
removes the warning from all three primitives. |
| **AFTER** — local patched build, full chain: `act()` + `extract()` +
`observe()` + hybrid `agent.execute()` (multi-step form fill, real
Browserbase session) | `AI SDK system-in-messages warnings emitted: NO
(0 total)` | Confirms no regression on the already-fixed
`agent.execute()` outer loop, and that the agent's internal
act/extract/observe tool calls are also silenced end-to-end. |
| `pnpm turbo run build --filter @browserbasehq/stagehand` | `Tasks: 3
successful, 3 total` | Typecheck + emit green. |
| `eslint` + `prettier --check` on changed files | Both clean |
Style/lint gates pass. |

A/B model: `anthropic/claude-haiku-4-5-20251001`, `experimental: true`,
hybrid agent mode — same harness shape as #2305's own E2E matrix.

Closes STG-2573.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Silences the noisy "system message in messages" warning in `act()`,
`extract()`, and `observe()`, including internal tool calls. Sets
`allowSystemInMessages: true` at 4 `generateObject`/`generateText` sites
and adds unit tests for both AISDK clients; closes STG-2573.

<sup>Written for commit d001bd5.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2359?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
…n agent.execute() (browserbase#2305)

## What & why

Every hybrid/DOM `agent.execute()` call prints this AI SDK v5 warning to
the console:

> AI SDK Warning: System messages in the prompt or messages fields can
be a security risk because they may enable prompt injection attacks. Use
the system option instead when possible. Set allowSystemInMessages to
true to suppress this warning, or false to throw an error.

It's cosmetic (a warning, not an error), but it fires on essentially
every agent run, and the "prompt injection" wording reads alarmingly
enough to generate support tickets — it did (customer Christian /
kento9288).

### Root cause
The agent loop builds its system prompt as a **system-role message
inside the `messages` array** (`prependSystemMessage()` in
`v3AgentHandler.ts`) rather than the top-level `system` param. This is
deliberate: it lets the system prompt carry Anthropic **ephemeral
cache-control** via `providerOptions` (see the function's own comment).
AI SDK v5 warns whenever it sees a system message in `messages`, since
it can't distinguish a trusted, library-authored system prompt from
untrusted input.

The committed lockfile pinned `ai@5.0.133`, which predates this warning
— so the repo build never saw it, but the `^5.0.133` range means real
installs resolve to newer 5.0.x (e.g. `5.0.209`) that **do** warn.
That's why users hit it and CI didn't.

### Fix
- Pass `allowSystemInMessages: true` to the `generateText` /
`streamText` calls in the agent loop. This is the AI-SDK-sanctioned
opt-out for an intentional system-in-messages structure, and it **keeps
prompt caching intact** (vs. moving to top-level `system:`, which cannot
carry per-message `providerOptions` and would regress Anthropic
cache-control).
- Bump the `ai` floor `^5.0.133 → ^5.0.185`, where
`allowSystemInMessages` is a typed option.
- Add an explicit return type (`LanguageModelV2`) to
`getAISDKLanguageModel`. The `ai` bump pulls a newer `@ai-sdk/provider`,
and without the annotation tsc emits `TS2742` ("inferred type … not
portable").

## E2E Test Matrix

| Command / flow | Observed output | Confidence / sufficiency |
| --- | --- | --- |
| **BEFORE** — published `@browserbasehq/stagehand@3.6.0` (resolves
`ai@5.0.209`), hybrid `agent.execute()` on a real Browserbase session,
console captured | `AI SDK system-in-messages warning emitted: YES (1)`
— full "…security risk…prompt injection…" text | Reproduces the
customer's exact symptom on the version they run. |
| **AFTER** — local patched build (this branch, same `ai@5.0.209`),
identical hybrid `agent.execute()` flow, same model, real Browserbase
session | `AI SDK system-in-messages warning emitted: NO (0)`; run exits
cleanly | Proves the fix removes the warning without breaking the agent
run. Same harness as BEFORE → clean A/B. |
| `pnpm turbo run build --filter @browserbasehq/stagehand` | `Tasks: 3
successful, 3 total` (fails with `TS2742` before the `LLMProvider`
annotation) | Typecheck + emit green; confirms the `ai` bump +
annotation compile. |
| `prettier --check` + `eslint` on changed files | `All matched files
use Prettier code style!`, eslint clean | Style/lint gates pass. |

A/B model: `anthropic/claude-haiku-4-5-20251001`. Both runs used
identical `mode: "hybrid"` + `systemPrompt` config (the customer's
shape).

Closes STG-2463.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Silences the AI SDK v5 “system message in messages” warning during
hybrid/DOM `agent.execute()` runs while preserving Anthropic
cache-control. Addresses STG-2463.

- **Bug Fixes**
- Pass `allowSystemInMessages: true` to `generateText`/`streamText` so
the agent’s system prompt in `messages` does not warn and caching stays
intact.

- **Dependencies**
  - Bump `ai` to `^5.0.185` (lock resolves to `5.0.209`).
- Add explicit `LanguageModelV2` return type in `getAISDKLanguageModel`
to avoid `TS2742` with newer `@ai-sdk/provider`.

<sup>Written for commit bfc10af.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2305?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

---------
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/stagehand@3.7.0

### Minor Changes

- [browserbase#2283](browserbase#2283)
[`871ca7e`](browserbase@871ca7e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add
`context.setDomainPolicy({ allowedDomains: ["allowed.domain"] })` which
allows users to define a set of domains that are accessible to stagehand

- [browserbase#2274](browserbase#2274)
[`f31980f`](browserbase@f31980f)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add
`context.setDomainPolicy({blockedDomains: ["some.domain"]})` which
allows users to define a list of domains that will be blocked by
stagehand

### Patch Changes

- [browserbase#2305](browserbase#2305)
[`cd1daad`](browserbase@cd1daad)
Thanks [@shrey150](https://github.com/shrey150)! - Remove the noisy AI
SDK "system message in messages" warning logged on every hybrid/DOM
`agent.execute()` call.

- [browserbase#2328](browserbase#2328)
[`d287ff4`](browserbase@d287ff4)
Thanks [@miguelg719](https://github.com/miguelg719)! - Allow modelName
"auto" in the constructor and per-primitive model overrides when running
through the Stagehand API

- [browserbase#2294](browserbase#2294)
[`3938590`](browserbase@3938590)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! -
automatically close popups that violate user defined domain policy

- [browserbase#2298](browserbase#2298)
[`892701a`](browserbase@892701a)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Fix CUA
`keypress` actions to press key combinations as a single chord.

- [browserbase#2345](browserbase#2345)
[`21826c7`](browserbase@21826c7)
Thanks [@monadoid](https://github.com/monadoid)! - Repair malformed
UTF-16 snapshot text before it reaches model prompts.

- [browserbase#2306](browserbase#2306)
[`8dcef1b`](browserbase@8dcef1b)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Use the
screenshot provider's declared media type when sending CUA image
payloads. The `setScreenshotProvider` callback now returns
`ScreenshotProviderResult` (`{ base64, mediaType }`) instead of a bare
base64 string.

- [browserbase#2273](browserbase#2273)
[`93a23d3`](browserbase@93a23d3)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add support for
the new `google/gemini-3.5-flash` computer-use tools model

- [browserbase#2278](browserbase#2278)
[`022d68f`](browserbase@022d68f)
Thanks [@shrey150](https://github.com/shrey150)! - Fix `TypeError:
Converting circular structure to JSON` when creating an agent with MCP
`integrations` that include a `Client` instance (e.g. a local/stdio
server from `connectToMCPServer`). The agent-creation log serialized the
raw `integrations` array, and a live MCP `Client` is circular. It now
logs a safe descriptor (URL strings kept, client instances summarized)
so `agent({ integrations: [client] })` works.

- [browserbase#2288](browserbase#2288)
[`bb5ffa6`](browserbase@bb5ffa6)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - clean up
cdp session event handlers on target detach

## @browserbasehq/stagehand-evals@2.0.4

### Patch Changes

- Updated dependencies
\[[`cd1daad`](browserbase@cd1daad),
[`d287ff4`](browserbase@d287ff4),
[`3938590`](browserbase@3938590),
[`892701a`](browserbase@892701a),
[`21826c7`](browserbase@21826c7),
[`8dcef1b`](browserbase@8dcef1b),
[`93a23d3`](browserbase@93a23d3),
[`871ca7e`](browserbase@871ca7e),
[`022d68f`](browserbase@022d68f),
[`bb5ffa6`](browserbase@bb5ffa6),
[`f31980f`](browserbase@f31980f)]:
    -   @browserbasehq/stagehand@3.7.0

## @browserbasehq/stagehand-server-v3@3.7.2

### Patch Changes

- Updated dependencies
\[[`cd1daad`](browserbase@cd1daad),
[`d287ff4`](browserbase@d287ff4),
[`3938590`](browserbase@3938590),
[`892701a`](browserbase@892701a),
[`21826c7`](browserbase@21826c7),
[`8dcef1b`](browserbase@8dcef1b),
[`93a23d3`](browserbase@93a23d3),
[`871ca7e`](browserbase@871ca7e),
[`022d68f`](browserbase@022d68f),
[`bb5ffa6`](browserbase@bb5ffa6),
[`f31980f`](browserbase@f31980f)]:
    -   @browserbasehq/stagehand@3.7.0
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
…ct/observe (browserbase#2359)

## What & why

[browserbase#2305](browserbase#2305) silenced the
AI SDK v5 "system message in messages" warning, but only for
`agent.execute()`'s outer loop (`v3AgentHandler.ts`). `act()`,
`extract()`, and `observe()` build their system prompt the same way — a
`{ role: "system", ... }` message inside the `messages` array — and
route through a separate call path that was never patched:
`AISdkClient.createChatCompletion()` in
`packages/core/lib/v3/llm/aisdk.ts` (the default client for any
`"provider/model"` string), plus the identical pattern in the public
BYOC client `packages/core/lib/v3/external_clients/aisdk.ts`.

Since the hybrid/DOM agent's own `act`/`extract`/`observe` tools call
these primitives internally on every step, an `agent.execute()` run that
clicks/types repeatedly still spammed the warning even after upgrading
past the first fix — a customer reported exactly this.

### Fix
Add `allowSystemInMessages: true` to the 4 remaining
`generateObject`/`generateText` call sites (2 in `llm/aisdk.ts`, 2 in
`external_clients/aisdk.ts`), same pattern as the original fix.

## E2E Test Matrix

| Command / flow | Observed output | Confidence / sufficiency |
| --- | --- | --- |
| **BEFORE** — published `@browserbasehq/stagehand@alpha` (already
includes browserbase#2305's fix), `act()` → `extract()` → `observe()` chain on a
real Browserbase session | `AI SDK system-in-messages warnings emitted:
YES (4)` | Reproduces the customer's exact symptom on the current alpha
— confirms browserbase#2305 left this path unpatched. |
| **AFTER** — local patched build (this branch), identical `act()` →
`extract()` → `observe()` chain, same model, real Browserbase session |
`AI SDK system-in-messages warnings emitted: NO (0)` | Proves the fix
removes the warning from all three primitives. |
| **AFTER** — local patched build, full chain: `act()` + `extract()` +
`observe()` + hybrid `agent.execute()` (multi-step form fill, real
Browserbase session) | `AI SDK system-in-messages warnings emitted: NO
(0 total)` | Confirms no regression on the already-fixed
`agent.execute()` outer loop, and that the agent's internal
act/extract/observe tool calls are also silenced end-to-end. |
| `pnpm turbo run build --filter @browserbasehq/stagehand` | `Tasks: 3
successful, 3 total` | Typecheck + emit green. |
| `eslint` + `prettier --check` on changed files | Both clean |
Style/lint gates pass. |

A/B model: `anthropic/claude-haiku-4-5-20251001`, `experimental: true`,
hybrid agent mode — same harness shape as browserbase#2305's own E2E matrix.

Closes STG-2573.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Silences the noisy "system message in messages" warning in `act()`,
`extract()`, and `observe()`, including internal tool calls. Sets
`allowSystemInMessages: true` at 4 `generateObject`/`generateText` sites
and adds unit tests for both AISDK clients; closes STG-2573.

<sup>Written for commit d001bd5.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2359?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
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