fix: omit system parameter when None in AnthropicLlm#5335
Open
voidborne-d wants to merge 2 commits intogoogle:mainfrom
Open
fix: omit system parameter when None in AnthropicLlm#5335voidborne-d wants to merge 2 commits intogoogle:mainfrom
voidborne-d wants to merge 2 commits intogoogle:mainfrom
Conversation
When system_instruction is None (e.g. during event compaction via LlmEventSummarizer), the Anthropic API rejects system=None with a 400 Bad Request. Use NOT_GIVEN instead so the parameter is omitted from the API call entirely. Fixes google#5318
Collaborator
|
Response from ADK Triaging Agent Hello @voidborne-d, thank you for submitting this pull request! To ensure code quality and prevent future regressions, could you please add a unit test that covers the case where Thanks! |
Adds two tests covering the fix for google#5318: - test_generate_content_async_none_system_instruction_non_streaming - test_generate_content_async_none_system_instruction_streaming Both verify that system=NOT_GIVEN (not None) is passed to the Anthropic API when system_instruction is unset, preventing 400 Bad Request errors during event compaction.
Author
|
Thanks for the review! I've added two unit tests in 7ccb1c9:
Both follow the existing patterns in |
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.
Summary
Fixes #5318.
AnthropicLlm.generate_content_asyncpassessystem=Noneto the Anthropic API when no system instruction is set (e.g. whenLlmEventSummarizertriggers event compaction). The Anthropic API rejectsNone— it expects either astr, a list of content blocks, or the parameter to be omitted entirely.Changes
system_instructiononce before the stream/non-stream branch: use the config value when present, otherwiseNOT_GIVEN(which the Anthropic SDK treats as "omit this parameter").messages.createcall and the streaming helper_generate_content_streaming.Reproduction
EventsCompactionConfig.LlmEventSummarizercreates anLlmRequestwithconfig.system_instruction = None.400 Bad Request—system: Input should be a valid list.systemparameter is omitted from the API call.