mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
feat(browser): add maxActionsPerTask for browser agent setting (#23216)
This commit is contained in:
@@ -97,6 +97,10 @@ export class BrowserManager {
|
||||
private mcpTransport: StdioClientTransport | undefined;
|
||||
private discoveredTools: McpTool[] = [];
|
||||
|
||||
/** State for action rate limiting */
|
||||
private actionCounter = 0;
|
||||
private readonly maxActionsPerTask: number;
|
||||
|
||||
/**
|
||||
* Whether to inject the automation overlay.
|
||||
* Always false in headless mode (no visible window to decorate).
|
||||
@@ -108,6 +112,8 @@ export class BrowserManager {
|
||||
const browserConfig = config.getBrowserAgentConfig();
|
||||
this.shouldInjectOverlay = !browserConfig?.customConfig?.headless;
|
||||
this.shouldDisableInput = config.shouldDisableBrowserUserInput();
|
||||
this.maxActionsPerTask =
|
||||
browserConfig?.customConfig.maxActionsPerTask ?? 100;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,6 +157,16 @@ export class BrowserManager {
|
||||
throw signal.reason ?? new Error('Operation cancelled');
|
||||
}
|
||||
|
||||
// Hard enforcement of per-action rate limit
|
||||
if (this.actionCounter > this.maxActionsPerTask) {
|
||||
const error = new Error(
|
||||
`Browser agent reached maximum action limit (${this.maxActionsPerTask}). ` +
|
||||
`Task terminated to prevent runaway execution. To config the limit, use maxActionsPerTask in the settings.`,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
this.actionCounter++;
|
||||
|
||||
const errorMessage = this.checkNavigationRestrictions(toolName, args);
|
||||
if (errorMessage) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user