Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion hud/agents/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import logging
from typing import Any, ClassVar, cast
from typing import TYPE_CHECKING, Any, ClassVar, cast

import mcp.types as types
from google import genai
Expand All @@ -15,6 +15,9 @@
from hud.utils.hud_console import HUDConsole
from hud.utils.types import with_signature

if TYPE_CHECKING:
import httpx

from .base import BaseCreateParams, MCPAgent

logger = logging.getLogger(__name__)
Expand All @@ -28,6 +31,7 @@ class GeminiConfig(BaseAgentConfig):
model_name: str = "Gemini"
model: str = "gemini-3-pro-preview"
model_client: genai.Client | None = None
httpx_client: httpx.AsyncClient | None = None
temperature: float = 1.0
top_p: float = 0.95
top_k: int = 40
Expand Down Expand Up @@ -78,11 +82,18 @@ def __init__(self, params: GeminiCreateParams | None = None, **kwargs: Any) -> N
self.top_k = self.config.top_k
self.max_output_tokens = self.config.max_output_tokens
self.hud_console = HUDConsole(logger=logger)
self._httpx_client = self.config.httpx_client

# Track mapping from Gemini tool names to MCP tool names
self._gemini_to_mcp_tool_map: dict[str, str] = {}
self.gemini_tools: genai_types.ToolListUnion = []

async def _cleanup(self) -> None:
await super()._cleanup()
if self._httpx_client is not None:
await self._httpx_client.aclose()
self._httpx_client = None

def _on_tools_ready(self) -> None:
"""Build Gemini-specific tool mappings after tools are discovered."""
self._convert_tools_for_gemini()
Expand Down
6 changes: 6 additions & 0 deletions hud/cli/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,23 @@ def get_agent_kwargs(self) -> dict[str, Any]:
)
hud_console.info("🌐 Using HUD Gateway for OpenAI-compatible API")
elif self.agent_type in (AgentType.GEMINI, AgentType.GEMINI_CUA):
import httpx
from google import genai
from google.genai.types import HttpOptions

httpx_async_client = httpx.AsyncClient()
kwargs["model_client"] = genai.Client(
api_key="PLACEHOLDER",
http_options=HttpOptions(
api_version="v1beta",
base_url=settings.hud_gateway_url,
headers={"Authorization": f"Bearer {hud_api_key}"},
# Important: By default this uses aiohttp, but
# we use an httpx hook for injecting Trace-Id
httpx_async_client=httpx_async_client,
),
)
kwargs["httpx_client"] = httpx_async_client
hud_console.info("🌐 Using HUD Gateway for Gemini API")

return kwargs
Expand Down
Loading