Skip to content

fix: reject multiple response candidates - #6519

Open
svfat wants to merge 1 commit into
google:mainfrom
svfat:fix/validate-candidate-count
Open

fix: reject multiple response candidates#6519
svfat wants to merge 1 commit into
google:mainfrom
svfat:fix/validate-candidate-count

Conversation

@svfat

@svfat svfat commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Closes #6518.

  • reject candidate_count > 1 before sending model request
  • apply same single-candidate contract to Gemini, LiteLLM and Apigee paths
  • add regression tests for request validation and existing first-candidate response conversion

Why

ADK exposes one model result through LlmResponse, but behavior for
candidate_count > 1 was inconsistent:

  • LiteLLM ignored the option and requested one choice
  • native Gemini requested multiple candidates and ADK kept only first one
  • Apigee requested multiple choices and kept only first one

This can give false expectation that multiple results are available. It can
also waste billed candidate tokens when extra outputs are generated and then
discarded.

Complete multi-candidate support would require change to LlmResponse and
downstream event/streaming APIs. This patch keeps current single-candidate
contract and returns clear error instead of silently ignoring or discarding
results.

Testing

  • pytest -q tests/unittests/models/test_llm_response.py tests/unittests/models/test_google_llm.py tests/unittests/models/test_litellm.py tests/unittests/models/test_completions_http_client.py
    • 471 passed
  • focused tests on Python 3.10, 3.11, 3.12, 3.13 and 3.14
  • pre-commit hooks
  • Talisman

@adk-bot adk-bot added the models [Component] This issue is related to model support label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] This issue is related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

candidate_count > 1 is ignored by LiteLLM and discarded by other adapters

3 participants