fix(agents): reject candidate_count greater than one - #7039
Open
claxman wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
LlmAgent accepted GenerateContentConfig(candidate_count=2). Gemini and Apigee then billed extra candidates and LlmResponse kept the first one. 25f5214 logs that drop. Construction now errors, same validator as generate_content_config.tools. svfat proposed a request-side raise in google#6519. The landed import kept the log-only half. This check is on LlmAgent, not the adapters. Fixes google#6518
claxman
force-pushed
the
fix/6518-reject-candidate-count
branch
from
September 7, 2026 02:56
1971fe5 to
40864d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
LlmAgent(name='x', generate_content_config=GenerateContentConfig(candidate_count=2))constructs with candidate_count 2. Extra candidates are dropped atLlmResponse.create, which keepscandidates[0].25f5214(from #6519) logs the drop in the adapters but construction stays silent.Issue script on
b0180620,PYTHONPATH=src:Solution:
Reject
candidate_count > 1inLlmAgent.validate_generate_content_config, the validator that already rejectstools,system_instruction,response_schema, andhttp_options.base_url. The error namesgenerate_content_config=and says extras are discarded.candidate_count=1stays allowed.Adapters are left at
25f5214. #6519 put the check there and the import kept only the log. Mappingcandidate_counttonand returning extras is out:LlmResponseis single-candidate. svfat filed the issue and the first raise.Testing Plan
Unit Tests:
New tests:
test_validate_generate_content_config_candidate_count_throwandtest_validate_generate_content_config_candidate_count_one_allowedintests/unittests/agents/test_llm_agent_fields.py, plus a case intests/unittests/agents/test_llm_agent_error_messages.py::TestValidateGenerateContentConfigErrors.6 passed.
Removed the validator block and reran the two throw tests. Both failed with DID NOT RAISE ValueError. Restored the block.
13981 passed, 84 skipped, 27 xfailed, 2 xpassed in 137s.
Manual End-to-End (E2E) Tests:
No live provider key. After the change,
LlmAgent(name='x', generate_content_config=types.GenerateContentConfig(candidate_count=2))raises a pydantic ValidationError whose value error iscandidate_count must be 1 or unset. LlmResponse keeps one candidate, so extra values are requested then discarded. Pass generate_content_config=types.GenerateContentConfig() without candidate_count, or set candidate_count=1.Additional context
Asked xuanyang15 on #6518 whether construct-time raise is wanted after 25f5214. #6518 (comment)
Checklist