Repository navigation
GeminiAgent: Gemini 4 request contract, streaming, and long-decode continuation - #724
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a0bfa819f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6a0bfa8. Configure here.
…nued cap as length GeminiConfig no longer sends temperature 1.0, top_p 0.95, and top_k 40 on every request; unset, each model uses its own sampling. Gemini 4 models ignore sampling parameters, and Gemini 3's recommended temperature is its default. A Gemini 4 turn that reaches the per-request output cap ends with finish reason CONTINUATION. When the client cannot continue it (a google-genai older than 2.30.1), the turn is a truncation, so the run now reports stop_reason=length instead of an empty "done".
6a0bfa8 to
49eae1f
Compare
GeminiAgent made one non-streaming generateContent call per turn. A Gemini 4 turn of 32,768 output tokens took about 645 seconds in measurement, longer than non-streaming request timeouts in front of the model (the HUD gateway allows 600 seconds), and Google recommends streaming for long generations. Each turn now streams and joins the streamed parts into one model turn, kept as received so thought signatures stay on the parts they arrived with. Text and thought fragments concatenate without separators, since streamed fragments split mid-word. Usage, grounding, and finish reason come from the last chunk that carries them.
anthropic 1.x renamed the request TypedDict for citations to
BetaCitationsConfigParamParam; BetaCitationsConfigParam is now the response
model. A plain {"enabled": True} is the citations parameter on both 0.x and 1.x.
Every browser-use release pins google-genai below 2.0 (0.11.13) or to 1.65.0 (0.12.1 and later), and the dev environment resolved together with the browseruse extra. That held SDK tests at google-genai 1.75, openai 2.x, and anthropic 0.x, while installing hud without that extra gets the latest of each. The browseruse extra now resolves apart from dev, and CI runs every other extra. dev requires google-genai 2.30.1 or later, so GeminiAgent's tests cover a stream that stops at the per-request cap and continues with its continuation token as one turn. hud's own google-genai floor is unchanged, so hud[browseruse] still installs. On openai 3.x and anthropic 1.x the SDK clients run on httpx2, so the tests that inject transports or build error responses use httpx2.
49eae1f to
72554d1
Compare

SDK half of HUD-3143 (Migrate the Gemini integration to Google's current GenAI platform) and HUD-3144 (Support Gemini 4 long decode). Gateway side: hud-evals/hud-monorepo#2308.
Summary
GeminiConfig.temperature,top_p, andtop_kdefault to unset. GeminiAgent stopped sending 1.0 / 0.95 / 40 on every request; Gemini 4 ignores sampling parameters, and Gemini 3's recommended temperature is its default anyway.thinking_levelkeeps the union of levels. Gemini returns a clear 400 for a level a model lacks (Argon rejectsminimal).CONTINUATION. With google-genai 2.30.1 or later, the SDK resumes with the continuation token and GeminiAgent records the hops as one turn. If the installed SDK can't continue, the turn is reported asstop_reason="length"instead of an emptydone.browseruseextra. That held SDK tests at google-genai 1.75, openai 2.x and anthropic 0.x, while installing hud without that extra gets the latest of each. Thebrowseruseextra now resolves apart fromdev([tool.uv] conflicts), CI runs every other extra, anddevrequires google-genai 2.30.1 or later for the continuation test. hud's own google-genai floor is unchanged, sohud[browseruse]still installs.citationsfrom a class that anthropic 1.x turned into a response model. It's now a plain dict that is valid on both majors.Testing
Run locally against the dependency set CI will resolve: google-genai 2.31.0, openai 3.31.0, anthropic 1.14.0, everything else up to Oct 8.
uv run pytest: 1,612 passed, 6 skipped.ty check --error-on-warning,ruff format --check,ruff check: clean.CONTINUATIONand resumes with its token through the real SDK (second request is the first pluscontinuationToken; usage summed);CONTINUATIONcounted as truncation.MALFORMED_FUNCTION_CALL, buffered or streamed alike (1 in 8 vs 0 in 8 on the same request), which is model behavior.Notes
include_thoughts=False, a streamed turn sends nothing while the model thinks. A long silent think can hit a gateway's first-chunk deadline, which is 240 seconds on the HUD gateway. Documented indocs/v6/reference/agents.mdx.🤖 Generated with Claude Code
Note
Medium Risk
Changes core Gemini inference (streaming, sampling defaults, truncation semantics) and dependency resolution between dev and browseruse; gateway timeouts and rollout truncation behavior shift for long Gemini 4 runs.
Overview
GeminiAgent now uses streaming (
generate_content_stream) per turn: chunks are merged into one model message with parts (and thought signatures) preserved, and streamed text/thought fragments are concatenated without newlines.Gemini 4 contract:
GeminiConfigdefaults move togemini-3.1-pro-preview;temperature,top_p, andtop_kdefault to unset so the API uses model defaults. Docs cover streaming, long decode (max_output_tokens> 65k +google-genai≥ 2.30.1), andinclude_thoughts.Truncation: Gemini
CONTINUATION(when a turn is not continued) is treated like other output-cap finish reasons →stop_reason="length".Deps / CI:
devpinsgoogle-genai>=2.30.1; uv conflictsbrowserusevsdev; CI runs tests with--no-extra browseruse. Claude web-fetch citations use a plain dict for anthropic 1.x. Tests use httpx2 where newer OpenAI/Anthropic clients expect it.Reviewed by Cursor Bugbot for commit 72554d1. Bugbot is set up for automated code reviews on this repo. Configure here.