Skip to content

feat(live): forward safety_settings from generate_content_config to the Live API - #6641

Merged
wuliang229 merged 2 commits into
google:v1from
wuliang229:fix/live-safety-settings-v1
Aug 7, 2026
Merged

feat(live): forward safety_settings from generate_content_config to the Live API#6641
wuliang229 merged 2 commits into
google:v1from
wuliang229:fix/live-safety-settings-v1

Conversation

@wuliang229

Copy link
Copy Markdown
Collaborator

Summary

Backport of #0a6d05da3b6ce912fa6f53eef1d97f638522817c (feat(live): forward safety_settings from generate_content_config to the Live API, PiperOrigin-RevId: 961126550) from main to v1.

Safety settings configured via LlmAgent.generate_content_config are silently dropped on the Live (bidiGenerateContent) path. Gemini.connect() copies only system_instruction and tools from LlmRequest.config into LlmRequest.live_connect_config, so setup.safetySettings never reaches the server, on either the Vertex AI or the Gemini API backend. The non-live path is unaffected because it forwards the whole GenerateContentConfig to generate_content.

There is no workaround: RunConfig exposes no safety settings (and is extra='forbid'), and before_model_callback does not run on the live path.

This has been the behavior since the first release — it is not a regression.

Change

Gemini.connect() now forwards llm_request.config.safety_settings to live_connect_config.safety_settings. A value already set on live_connect_config takes precedence.

Differences from the main commit

The upstream commit's context included the thinking_config forwarding block, which does not exist on v1 (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_settings exists at v1's pinned google-genai floor (>=2.9), verified against google-genai==2.9.0; its _LiveConnectConfig_to_mldev / _to_vertex converters both emit setup.safetySettings.
  • Serialized the config produced by the real Gemini.connect() (websocket transport mocked) through those converters: setup.safetySettings is 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_settings fails when the fix is reverted.
  • isort and pyink clean.

Note

This gets the field onto the wire. Whether the Live server honors setup.safetySettings — in particular HARM_CATEGORY_JAILBREAK — has not been exercised end to end, since ADK has never sent it.

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.
@adk-bot adk-bot added the live [Component] This issue is related to live, voice and video chat label Aug 7, 2026
@wuliang229 wuliang229 changed the title fix(live): Port safety_settings forwarding for the Live API to v1 feat(live): forward safety_settings from generate_content_config to the Live API Aug 7, 2026
@wuliang229
wuliang229 merged commit 99c1aa3 into google:v1 Aug 7, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

live [Component] This issue is related to live, voice and video chat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants