Skip to content

Commit 86de366

Browse files
committed
chore: move gemini's MAX_RECENT_TURN_WITH_SCREENSHOTS to env vars
1 parent f47363a commit 86de366

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

hud/agents/gemini.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
logger = logging.getLogger(__name__)
2626

27-
# Maximum number of recent turns to keep screenshots for
28-
MAX_RECENT_TURN_WITH_SCREENSHOTS = 3
29-
3027
# Predefined Gemini computer use functions
3128
PREDEFINED_COMPUTER_USE_FUNCTIONS = [
3229
"open_web_browser",
@@ -110,6 +107,12 @@ def __init__(
110107
self.excluded_predefined_functions = excluded_predefined_functions or []
111108
self.hud_console = HUDConsole(logger=logger)
112109

110+
# Context management: Maximum number of recent turns to keep screenshots for
111+
# Configurable via GEMINI_MAX_RECENT_TURN_WITH_SCREENSHOTS environment variable
112+
self.max_recent_turn_with_screenshots = (
113+
computer_settings.GEMINI_MAX_RECENT_TURN_WITH_SCREENSHOTS
114+
)
115+
113116
self.model_name = self.model
114117

115118
# Track mapping from Gemini tool names to MCP tool names
@@ -458,7 +461,7 @@ def _convert_tools_for_gemini(self) -> list[genai_types.Tool]:
458461
def _remove_old_screenshots(self, messages: list[genai_types.Content]) -> None:
459462
"""
460463
Remove screenshots from old turns to manage context length.
461-
Keeps only the last MAX_RECENT_TURN_WITH_SCREENSHOTS turns with screenshots.
464+
Keeps only the last N turns with screenshots (configured via self.max_recent_turn_with_screenshots).
462465
"""
463466
turn_with_screenshots_found = 0
464467

@@ -478,7 +481,7 @@ def _remove_old_screenshots(self, messages: list[genai_types.Content]) -> None:
478481
if has_screenshot:
479482
turn_with_screenshots_found += 1
480483
# Remove the screenshot image if the number of screenshots exceeds the limit
481-
if turn_with_screenshots_found > MAX_RECENT_TURN_WITH_SCREENSHOTS:
484+
if turn_with_screenshots_found > self.max_recent_turn_with_screenshots:
482485
for part in content.parts:
483486
if (
484487
part.function_response

hud/tools/computer/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class ComputerSettings(BaseSettings):
109109
description="Whether to rescale images to the agent width and height",
110110
validation_alias="GEMINI_RESCALE_IMAGES",
111111
)
112+
GEMINI_MAX_RECENT_TURN_WITH_SCREENSHOTS: int = Field(
113+
default=3,
114+
description="Maximum number of recent turns to keep screenshots for in Gemini agent",
115+
validation_alias="GEMINI_MAX_RECENT_TURN_WITH_SCREENSHOTS",
116+
)
112117

113118

114119
computer_settings = ComputerSettings()

0 commit comments

Comments
 (0)