-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Messages and abort #1345
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
Open
tkattkat
wants to merge
16
commits into
main
Choose a base branch
from
messages-and-abort
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Messages and abort #1345
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
915a613
initial commit
tkattkat f8c3554
add abort on close
tkattkat b4ac3ff
remove example
tkattkat 544f90b
format
tkattkat ebb3dcb
changeset
tkattkat 4682188
address cubic review
tkattkat a5979c3
update test, and abort signal handling
tkattkat f02957c
format
tkattkat 955adb7
update timeouts
tkattkat 2db278f
adjust abort handling in stream, and update test
tkattkat 58223c4
lint
tkattkat 2196ff5
update streaming test
tkattkat 646e679
simplify abort logic
tkattkat 53b10f1
Merge branch 'main' into messages-and-abort
tkattkat d329871
remove old comment
tkattkat 9d2a4a6
remove error handling that is no longer necessary
tkattkat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@browserbasehq/stagehand": patch | ||
| --- | ||
|
|
||
| Add support for aborting / stopping an agent run & continuing an agent run using messages from prior runs |
91 changes: 91 additions & 0 deletions
91
packages/core/lib/v3/agent/utils/validateExperimentalFeatures.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { | ||
| ExperimentalNotConfiguredError, | ||
| StagehandInvalidArgumentError, | ||
| } from "../../types/public/sdkErrors"; | ||
| import type { AgentConfig, AgentExecuteOptionsBase } from "../../types/public"; | ||
|
|
||
| export interface AgentValidationOptions { | ||
| /** Whether experimental mode is enabled */ | ||
| isExperimental: boolean; | ||
| /** Agent config options (integrations, tools, stream, cua, etc.) */ | ||
| agentConfig?: Partial<AgentConfig>; | ||
| /** Execute options (callbacks, signal, messages, etc.) */ | ||
| executeOptions?: | ||
| | (Partial<AgentExecuteOptionsBase> & { callbacks?: unknown }) | ||
| | null; | ||
| /** Whether this is streaming mode (can be derived from agentConfig.stream) */ | ||
| isStreaming?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Validates agent configuration and experimental feature usage. | ||
| * | ||
| * This utility consolidates all validation checks for both CUA and non-CUA agent paths: | ||
| * - Invalid argument errors for CUA (streaming, abort signal, message continuation are not supported) | ||
| * - Experimental feature checks for non-CUA (integrations, tools, callbacks, signal, messages, streaming) | ||
| * | ||
| * Throws StagehandInvalidArgumentError for invalid/unsupported configurations. | ||
| * Throws ExperimentalNotConfiguredError if experimental features are used without experimental mode. | ||
| */ | ||
| export function validateExperimentalFeatures( | ||
| options: AgentValidationOptions, | ||
| ): void { | ||
| const { isExperimental, agentConfig, executeOptions, isStreaming } = options; | ||
|
|
||
| // CUA-specific validation: certain features are not available at all | ||
| if (agentConfig?.cua) { | ||
| const unsupportedFeatures: string[] = []; | ||
|
|
||
| if (agentConfig?.stream) { | ||
| unsupportedFeatures.push("streaming"); | ||
| } | ||
| if (executeOptions?.signal) { | ||
| unsupportedFeatures.push("abort signal"); | ||
| } | ||
| if (executeOptions?.messages) { | ||
| unsupportedFeatures.push("message continuation"); | ||
| } | ||
|
|
||
| if (unsupportedFeatures.length > 0) { | ||
| throw new StagehandInvalidArgumentError( | ||
| `${unsupportedFeatures.join(", ")} ${unsupportedFeatures.length === 1 ? "is" : "are"} not supported with CUA (Computer Use Agent) mode.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Skip experimental checks if already in experimental mode | ||
| if (isExperimental) return; | ||
|
|
||
| const features: string[] = []; | ||
|
|
||
| // Check agent config features (check array length to avoid false positives for empty arrays) | ||
| const hasIntegrations = | ||
| agentConfig?.integrations && agentConfig.integrations.length > 0; | ||
| const hasTools = | ||
| agentConfig?.tools && Object.keys(agentConfig.tools).length > 0; | ||
| if (hasIntegrations || hasTools) { | ||
| features.push("MCP integrations and custom tools"); | ||
| } | ||
|
|
||
| // Check streaming mode (either explicit or derived from config) - only for non-CUA | ||
| if (!agentConfig?.cua && (isStreaming || agentConfig?.stream)) { | ||
| features.push("streaming"); | ||
| } | ||
|
|
||
| // Check execute options features - only for non-CUA | ||
| if (executeOptions && !agentConfig?.cua) { | ||
| if (executeOptions.callbacks) { | ||
| features.push("callbacks"); | ||
| } | ||
| if (executeOptions.signal) { | ||
| features.push("abort signal"); | ||
| } | ||
| if (executeOptions.messages) { | ||
| features.push("message continuation"); | ||
| } | ||
| } | ||
|
|
||
| if (features.length > 0) { | ||
| throw new ExperimentalNotConfiguredError(`Agent ${features.join(", ")}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.