Skip to content

fix: use Modality enum for RunConfig.response_modalities#4889

Closed
brucearctor wants to merge 7 commits into
google:mainfrom
brucearctor:fix/response-modalities-type
Closed

fix: use Modality enum for RunConfig.response_modalities#4889
brucearctor wants to merge 7 commits into
google:mainfrom
brucearctor:fix/response-modalities-type

Conversation

@brucearctor

Copy link
Copy Markdown
Contributor

Description

Fixes #4869

RunConfig.response_modalities is typed as Optional[list[str]], but it gets assigned to LiveConnectConfig.response_modalities which expects Optional[list[Modality]] (an enum from google-genai). This type mismatch causes Pydantic to emit a PydanticSerializationUnexpectedValue warning on every live streaming session, polluting production logs.

Changes

  • run_config.py: Changed response_modalities type from Optional[list[str]] to Optional[list[types.Modality]]
  • runners.py: Updated two string literal 'AUDIO' usages to types.Modality.AUDIO for consistency

This is backwards compatible — Modality is a string enum, so Pydantic automatically coerces string values like 'AUDIO' to Modality.AUDIO.

Testing Plan

Added 3 new unit tests in test_run_config.py:

  • test_response_modalities_accepts_enum — enum values are stored correctly
  • test_response_modalities_coerces_string_to_enum — string values still work (backwards compat)
  • test_response_modalities_serialization_no_warningmodel_dump() produces no Pydantic warnings
$ pytest tests/unittests/agents/test_run_config.py -v
8 passed in 1.22s

RunConfig.response_modalities was typed as Optional[list[str]] but is
assigned to LiveConnectConfig.response_modalities which expects
Optional[list[Modality]]. This type mismatch caused Pydantic
serialization warnings on every live streaming session.

Change the type to Optional[list[types.Modality]] and update string
literal usages in runners.py to use the enum. This is backwards
compatible since Modality is a string enum and Pydantic coerces string
values automatically.

Fixes: google#4869
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@adk-bot adk-bot added the live [Component] This issue is related to live, voice and video chat label Mar 18, 2026
@rohityan rohityan self-assigned this Mar 19, 2026
@brucearctor

Copy link
Copy Markdown
Contributor Author

/gemini review

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 20, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @brucearctor ,Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing mypy-diff tests

@brucearctor

Copy link
Copy Markdown
Contributor Author

@rohityan - yes, those were fixed awhile ago.

@wuliang229 wuliang229 self-assigned this Jun 15, 2026
copybara-service Bot pushed a commit that referenced this pull request Jun 19, 2026
Merge #4889

## Description

Fixes #4869

`RunConfig.response_modalities` is typed as `Optional[list[str]]`, but it gets assigned to `LiveConnectConfig.response_modalities` which expects `Optional[list[Modality]]` (an enum from `google-genai`). This type mismatch causes Pydantic to emit a `PydanticSerializationUnexpectedValue` warning on every live streaming session, polluting production logs.

## Changes

- **`run_config.py`**: Changed `response_modalities` type from `Optional[list[str]]` to `Optional[list[types.Modality]]`
- **`runners.py`**: Updated two string literal `'AUDIO'` usages to `types.Modality.AUDIO` for consistency

This is backwards compatible — `Modality` is a string enum, so Pydantic automatically coerces string values like `'AUDIO'` to `Modality.AUDIO`.

## Testing Plan

Added 4 new unit tests in `test_run_config.py`:

- `test_response_modalities_accepts_enum` — enum values are stored correctly
- `test_response_modalities_coerces_string_to_enum` — string values still work (backwards compat)
- `test_response_modalities_coerces_lowercase_string_to_enum` — lowercase string values also work (backwards compat)
- `test_response_modalities_serialization_no_warning` — `LiveConnectConfig.model_dump()` produces no Pydantic warnings

Co-authored-by: Liang Wu <wuliang@google.com>
COPYBARA_INTEGRATE_REVIEW=#4889 from brucearctor:fix/response-modalities-type e67f715
PiperOrigin-RevId: 934659835
@adk-bot

adk-bot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you @brucearctor for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 5c8c55a.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jun 19, 2026
@adk-bot adk-bot closed this Jun 19, 2026
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 merged [Status] This PR is merged request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pydantic serializer warnings for internal issue (response_modalities)

4 participants