feat(live): forward safety_settings from generate_content_config to the Live API - #6641
Merged
Merged
Conversation
Safety settings configured via `LlmAgent.generate_content_config` were silently dropped on the Live (bidiGenerateContent) path. `Gemini.connect()` copied only `system_instruction` and `tools` from `LlmRequest.config` into `LlmRequest.live_connect_config`, so `safetySettings` never reached the server on either the Vertex AI or the Gemini API backend. The non-live path was unaffected, because it forwards the whole `GenerateContentConfig` to `generate_content`. `RunConfig` exposes no safety settings either, and `before_model_callback` does not run on the live path, so there was no supported way to configure safety for a live agent. Safety settings are now forwarded to `live_connect_config` when the agent supplies them. A value already set on `live_connect_config` continues to take precedence. This has been the behavior since the first release; it is not a regression. BEHAVIOR CHANGE: agents that set `safety_settings` in `generate_content_config` and run under `run_live()` will now have those settings applied. Review the safety configuration of live agents before upgrading. Backport of 0a6d05d from main. The upstream commit also touched the `thinking_config` forwarding block, which does not exist on v1 (it came from a separate change that was never ported); that hunk was dropped so this backport is scoped to safety settings only.
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
Backport of #0a6d05da3b6ce912fa6f53eef1d97f638522817c (
feat(live): forward safety_settings from generate_content_config to the Live API, PiperOrigin-RevId: 961126550) frommaintov1.Safety settings configured via
LlmAgent.generate_content_configare silently dropped on the Live (bidiGenerateContent) path.Gemini.connect()copies onlysystem_instructionandtoolsfromLlmRequest.configintoLlmRequest.live_connect_config, sosetup.safetySettingsnever reaches the server, on either the Vertex AI or the Gemini API backend. The non-live path is unaffected because it forwards the wholeGenerateContentConfigtogenerate_content.There is no workaround:
RunConfigexposes no safety settings (and isextra='forbid'), andbefore_model_callbackdoes not run on the live path.This has been the behavior since the first release — it is not a regression.
Change
Gemini.connect()now forwardsllm_request.config.safety_settingstolive_connect_config.safety_settings. A value already set onlive_connect_configtakes precedence.Differences from the
maincommitThe upstream commit's context included the
thinking_configforwarding block, which does not exist onv1(it came from a separate change never ported). That hunk and its test were dropped, so this backport is scoped to safety settings only.Verification
LiveConnectConfig.safety_settingsexists atv1's pinned google-genai floor (>=2.9), verified againstgoogle-genai==2.9.0; its_LiveConnectConfig_to_mldev/_to_vertexconverters both emitsetup.safetySettings.Gemini.connect()(websocket transport mocked) through those converters:setup.safetySettingsis absent before the change and present after, on both backends.pytest tests/unittests/models/test_google_llm.py— 65 passed, including 4 new tests.test_connect_forwards_safety_settingsfails when the fix is reverted.isortandpyinkclean.Note
This gets the field onto the wire. Whether the Live server honors
setup.safetySettings— in particularHARM_CATEGORY_JAILBREAK— has not been exercised end to end, since ADK has never sent it.