Skip to content

fix(google): forward configured topP to Gemini requests - #190054

Closed
yetval wants to merge 1 commit into
openclaw:mainfrom
yetval:fix/provider-google-top-p
Closed

yetval wants to merge 1 commit into
openclaw:mainfrom
yetval:fix/provider-google-top-p

Conversation

@yetval

@yetval yetval commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

A Gemini model configured with nucleus sampling (agents.defaults.models["google/<model>"].params.topP, or the documented params.top_p alias) sends no topP to Google. The shared extra-params wrapper resolves either spelling into the topP stream option, as docs/gateway/config-agents/models.md documents ("Nucleus sampling accepts params.topP or params.top_p"), and OpenAI and Ollama honor it, but every Google request builder drops it. temperature from the same params block does reach the request, so the dropped value is silent.

Root cause

The Google transports copy only temperature, maxTokens and stop from the stream options into the request. extensions/google/transport-stream.ts (buildGoogleGenerativeAiParams, used for Gemini API and Vertex turns):

// before
if (typeof options?.temperature === "number") {
  generationConfig.temperature = options.temperature;
}
if (options?.stop !== undefined && options.stop.length > 0) {
  generationConfig.stopSequences = options.stop;
}

The same gap exists in packages/ai/src/providers/google-interactions-request.ts (buildGoogleInteractionsParams, whose request type already declares generation_config.top_p but never sets it) and in packages/ai/src/providers/google-shared.ts (buildGoogleGenerateContentParams, the built-in Gemini path).

Fix

Each Google request builder maps the topP stream option to its native field, next to temperature:

// after
if (typeof options?.temperature === "number") {
  generationConfig.temperature = options.temperature;
}
if (typeof options?.topP === "number") {
  generationConfig.topP = options.topP;
}

Interactions writes generation_config.top_p, and the built-in generateContent builder writes config.topP. GoogleTransportOptions and GoogleProviderOptions gain topP?: number, matching how the OpenAI and Ollama transports type the same option.

Why this is the right boundary

Config resolution is already correct: createStreamFnWithExtraParams resolves topP/top_p into one topP stream option for every provider, and the OpenAI and Ollama transports consume it. The drop happens only where the Google transports build their wire payload, so the mapping belongs in those builders. All three Google request shapes (generateContent via the plugin, Interactions, and the built-in generateContent path) are covered so no Google route keeps the gap. Nothing is sent unless topP is configured or passed per request, so existing requests are byte-identical. Other transports are untouched.

Verification

  • extensions/google/transport-stream.request-config.test.ts: the generation config built by buildGoogleGenerativeAiParams now includes topP: 0.4 next to temperature, max output tokens and stop sequences.
  • packages/ai/src/providers/google-interactions-shared.convert.test.ts: buildGoogleInteractionsParams emits generation_config: { temperature: 0.2, top_p: 0.4 }.
  • packages/ai/src/providers/google-shared.test.ts: buildGoogleGenerateContentParams emits config.topP.
  • Each of the three files was run with node scripts/run-vitest.mjs <file>: the new assertions fail on pristine main and pass with the patch. oxfmt --check is clean on all changed files.
  • Local tsgo and oxlint were not run per the contributor workflow for this batch; GitHub Actions covers them.

Real behavior proof

Behavior addressed: A configured Gemini params.topP (or params.top_p) was resolved by OpenClaw but never sent in the Google streamGenerateContent request, while temperature from the same block was sent.
Real environment tested: The real CLI from source, node --import tsx/esm src/entry.ts agent --local --agent main --message ping --json, with an isolated HOME/OPENCLAW_STATE_DIR whose openclaw.json sets agents.defaults.model.primary: "google/gemini-2.5-flash", agents.defaults.models["google/gemini-2.5-flash"].params: { temperature: 0.2, topP: 0.4 }, and models.providers.google.baseUrl pointing at a loopback HTTP server that stands in for the Gemini API, records each request body and answers with one SSE chunk (pong). The bundled Google plugin, its transport, the extra-params wrapper, config loading and the embedded agent run are all real; only the Google HTTP endpoint is replaced. Run on pristine main 72cab24, then on this patch with identical config.
Exact steps or command run after this patch: HOME=$H OPENCLAW_HOME=$H OPENCLAW_STATE_DIR=$H/.openclaw node --import tsx/esm src/entry.ts agent --local --agent main --message ping --json, then printed the generationConfig of the recorded request; repeated with params.top_p: 0.7 instead of topP to cover the documented alias.
Evidence after fix:

# BEFORE (pristine main 72cab24990b)
params: { "temperature": 0.2, "topP": 0.4 }
agent reply: pong (provider google, model gemini-2.5-flash)
POST /v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse generationConfig={"temperature":0.2}

# AFTER (this patch, identical inputs)
params: { "temperature": 0.2, "topP": 0.4 }
agent reply: pong (provider google, model gemini-2.5-flash)
POST /v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse generationConfig={"temperature":0.2,"topP":0.4}

# AFTER, documented alias
params: { "temperature": 0.2, "top_p": 0.7 }
POST /v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse generationConfig={"temperature":0.2,"topP":0.7}

Observed result after fix: The Gemini request now carries the configured nucleus sampling value (topP: 0.4, and 0.7 via top_p) next to temperature; on main the same config produced a request with temperature only.
What was not tested: No live Google API request (loopback endpoint only); the Interactions and Vertex routes were not driven end to end through the CLI, only the shared request builders; full build not run.

Model params.topP and params.top_p reach the stream options as topP, but the
Google transports only copied temperature, maxTokens and stop into the
request, so Gemini generateContent, Vertex and Interactions requests went out
without nucleus sampling. Map topP to generationConfig.topP and
generation_config.top_p.
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR forwards configured nucleus sampling values into three Google request formats.

Example: Use google/gemini-2.5-flash through GenerateContent with params.topP set to 0.4.

  • Before: The outgoing generationConfig omits topP.
  • After: The outgoing generationConfig includes topP: 0.4.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The narrow mappings are useful and CI passes, but the default Gemini route still drops the configured value.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Gemini requests silently ignore an explicitly configured, documented nucleus sampling value.
Reason: Restoring the existing sampling contract has clear value and needs no new setting or product decision.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR addresses a documented sampling bug, but its fix remains incomplete: Google's simple-stream adapters discard topP before the patched builders receive it.

Priority: P2
Reviewed head: 73fbaeda28eabdd4006745fd6686306491100634

Before merge

  • Add real behavior proof - The contributor's CLI traces exercise the real config resolver and Google GenerateContent transport against a loopback HTTP endpoint, showing topP: 0.4 and alias-derived topP: 0.7 after the fix; however, the default Interactions path is covered only by direct builder tests that bypass its option projection, so provide a redacted CLI or real-transport request trace for that path after repair, excluding credentials and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • [P2] Preserve topP through Google's simple-stream adapters (P2) - For an official AI Studio google/gemini-2.5-flash model configured with params.topP: 0.4, the plugin selects Interactions and calls provider.streamSimple. streamSimpleGoogleInteractions then calls buildBaseOptions, whose explicit projection omits topP, and never restores it. Consequently options.topP is undefined at this new branch and generation_config.top_p remains absent. The built-in GenerateContent and Vertex simple adapters lose it through the same projection. Preserve the numeric option through the Google simple adapters and add a regression that captures the request through those callers; direct builder assertions bypass this loss.

Findings

  • [P2] [P2] Preserve topP through Google's simple-stream adapters — packages/ai/src/providers/google-interactions-request.ts:261-263

Tests

  • Missing end-to-end proof: The supplied CLI trace does not exercise configured topP through the production Interactions simple-stream adapter.
Agent review details

How this fits together

Agent config resolves topP and top_p into stream options; Google adapters project those options into GenerateContent or Interactions requests and consume streamed responses.

flowchart TD
  A[Model sampling configuration] --> B[Extra params resolver]
  B --> C[Google plugin transport]
  C --> D[GenerateContent request builder]
  C --> E[Interactions simple adapter]
  E --> F[Interactions request builder]
  D --> G[Google HTTP endpoint]
  F --> G
Loading

Technical review

Best possible solution:

Preserve topP through Google's existing simple-stream adapters and retain the three native request mappings.

Do we have a high-confidence way to reproduce the issue?

Current source establishes the request-field omission and the remaining simple-adapter drop; the contributor supplies a GenerateContent CLI reproduction, and this review ran no target code.

Is this the best way to solve the issue?

Mapping the existing option at each wire builder is appropriate, but the complete fix must also preserve it across the Google simple-stream projections.

Full review comments:

  • [P2] [P2] Preserve topP through Google's simple-stream adapters — packages/ai/src/providers/google-interactions-request.ts:261-263
    For an official AI Studio google/gemini-2.5-flash model configured with params.topP: 0.4, the plugin selects Interactions and calls provider.streamSimple. streamSimpleGoogleInteractions then calls buildBaseOptions, whose explicit projection omits topP, and never restores it. Consequently options.topP is undefined at this new branch and generation_config.top_p remains absent. The built-in GenerateContent and Vertex simple adapters lose it through the same projection. Preserve the numeric option through the Google simple adapters and add a regression that captures the request through those callers; direct builder assertions bypass this loss.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b1b0a88900d8.

Provenance checked

  • Google plugin request construction keeps the original intent (e697fa5: Introduced the Google transport runtime; later request-preparation work retained its existing builder ownership.)
  • Shared Google GenerateContent construction keeps the original intent (a18bc56: Shared Google provider stream helpers and request assembly across the Google routes.)
  • Google Interactions request construction keeps the original intent (feat(gemini): add google-interactions api backend #149880: Added a separate stateless Interactions backend while reusing provider lifecycle and replay contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test packages/ai/src/providers/google-interactions.test.ts --maxWorkers=1
  • pnpm test packages/ai/src/providers/google-client-auth.test.ts --maxWorkers=1
  • pnpm test packages/ai/src/providers/google-shared.test.ts packages/ai/src/providers/google-interactions-shared.convert.test.ts extensions/google/transport-stream.request-config.test.ts --maxWorkers=1
  • pnpm test src/agents/agent-tools.prefix-stability.test.ts --maxWorkers=1
  • Show the new simple-adapter regression failing before repair and passing afterward.

What I checked:

Likely related people:

  • Vincent Koc: Raw commit e697fa5 adds src/agents/google-transport-stream.ts:426 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e697fa5e7591; files: src/agents/google-transport-stream.ts)
  • Mark McDonald: Raw commit e952abb adds packages/ai/src/providers/google-interactions-request.ts:267 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e952abb4aff8; files: packages/ai/src/providers/google-interactions-request.ts)

PR surface

Source +9, Tests +13. Total +22 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 9 0 +9
Tests 3 13 0 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 22 0 +22

Labels

Label changes:

  • add P2: Configured Google nucleus sampling is silently ignored, but ordinary agent requests remain usable.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Configured Google nucleus sampling is silently ignored, but ordinary agent requests remain usable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 31, 2026, 11:57 PM ET / November 1, 2026, 03:57 UTC.

@yetval

yetval commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of tracking issue #190468. The defect is still present on current main (2775e24), reconfirmed today; the fix and regression coverage remain on branch fix/provider-google-top-p for anyone who wants to pick it up.

@yetval yetval closed this Nov 1, 2026
obviyus added a commit that referenced this pull request Nov 1, 2026
fix(google): forward the configured topP to Gemini requests

Fixes #190468.

A configured `topP` was dropped from Gemini requests on the Interactions, GenerateContent and Vertex routes, so the model ran with the provider default. The existing `topP` option is now passed through the Google adapter to all three request builders. When `topP` is not set, it is left out, and other generation parameters are unchanged. No public SDK export changes.

Evidence: built CLI in secretless Node 24.22.1 Docker with local Interactions and GenerateContent fixtures and a faithful Vertex wire fixture. On each route, main dropped `topP` twice and this change forwarded it twice, for both spellings. Unset controls left it out, and other generation parameters matched in 9 of 9 comparisons. Details: #190695 (comment).

Thanks @Yigtwxx, and @yetval for the earlier attempt in #190054.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
fix(google): forward the configured topP to Gemini requests

Fixes openclaw#190468.

A configured `topP` was dropped from Gemini requests on the Interactions, GenerateContent and Vertex routes, so the model ran with the provider default. The existing `topP` option is now passed through the Google adapter to all three request builders. When `topP` is not set, it is left out, and other generation parameters are unchanged. No public SDK export changes.

Evidence: built CLI in secretless Node 24.22.1 Docker with local Interactions and GenerateContent fixtures and a faithful Vertex wire fixture. On each route, main dropped `topP` twice and this change forwarded it twice, for both spellings. Unset controls left it out, and other generation parameters matched in 9 of 9 comparisons. Details: openclaw#190695 (comment).

Thanks @Yigtwxx, and @yetval for the earlier attempt in openclaw#190054.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant