Skip to content

Python: Gemini chat client silently drops all but the first candidate when candidate_count > 1 #9928

Closed

Description

Description

The Gemini chat client silently drops all but the first candidate when candidate_count > 1 is requested.

Both parsers read candidates[0] only:

  • non-streaming: python/packages/gemini/agent_framework_gemini/_chat_client.py _parse_response — candidate = response.candidates[0]
  • streaming: _process_chunk — candidate = chunk.candidates[0]

candidate_count is not declared anywhere in the client; it reaches the API through the generic option passthrough in _prepare_config (kwargs[_OPTION_TRANSLATIONS.get(key, key)] = value), so options={"candidate_count": 2} is a valid, billable request whose response is then truncated to candidate 0 — with finish reasons and usage also attributed to candidate 0 alone, and no warning or error.

Repro

from agent_framework_gemini import GeminiChatClient

client = GeminiChatClient(model="gemini-2.5-flash")
# behind the scenes: config = client._prepare_config({"candidate_count": 2}, None)
# -> GenerateContentConfig(candidate_count=2) is sent, but any response is parsed as
#    response.candidates[0] only; candidates[1:] never surface.

Expected

The client already has a precedent for provider options it cannot honor faithfully: the Ollama chat client rejects unsupported tool_choice modes with ChatClientInvalidRequestException "instead of silently behaving like 'auto'" (python/packages/ollama/agent_framework_ollama/_chat_client.py). Multi-candidate responses deserve the same explicit rejection at request build time (or full multi-candidate support), not silent truncation.

Environment

  • Package: agent-framework-gemini
  • Observed on main at fc3c3c0

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 1, 2026
  2. changed the title [-]Gemini chat client silently drops all but the first candidate when candidate_count > 1[/-] [+]Python: Gemini chat client silently drops all but the first candidate when candidate_count > 1[/+] on Nov 1, 2026
  3. eavanvalkenburg commented on Nov 2, 2026

    @eavanvalkenburg
    Member

    Thanks for reporting this. Preventing silent loss of requested Gemini output is in scope for MAF, and the team will consider a core change. This is not a commitment to implementation or timing, or approval of a particular multi-candidate API. We will first plan the bounded early-rejection approach proposed in #9929, including compatibility with documented provider-option passthrough and streaming behavior. Please coordinate work through that existing PR rather than starting a parallel implementation.

  4. eavanvalkenburg commented on Nov 2, 2026

    @eavanvalkenburg
    Member

    /plan Plan explicit safe handling of Gemini candidate_count without introducing a multi-candidate response API. Evaluate bounded early rejection of requests the current single-candidate abstraction cannot honor, as proposed in #9929. Verify real google-genai request/response semantics and the compatibility impact on documented generic-option passthrough; distinguish normal omitted/None/one values from unsupported multiple candidates and malformed values, preserving SDK/framework error boundaries. Cover streaming and non-streaming paths, prevention of provider calls on rejected requests, finish/usage semantics, and supported model/backend differences where material. Coordinate the existing #9929 implementation and focused tests; do not create a parallel fix. Keep the issue in triage while this contract is being planned.

  5. added a commit that references this issue on Nov 11, 2026
    fd12c25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: Pythonready-for-implementationMaintainers agree the problem and direction are ready for implementation.triageUsage: [Issues], Target: All issues that still need to be triaged

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions