Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions temporalio/contrib/google_adk_agents/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from temporalio.contrib.google_adk_agents._mcp import TemporalMcpToolSetProvider
from temporalio.contrib.google_adk_agents._model import invoke_model
from temporalio.contrib.pydantic import (
PydanticPayloadConverter as _DefaultPydanticPayloadConverter,
PydanticPayloadConverter,
ToJsonOptions,
)
from temporalio.converter import DataConverter, DefaultPayloadConverter
from temporalio.plugin import SimplePlugin
Expand Down Expand Up @@ -112,10 +113,17 @@ def _configure_data_converter(
) -> DataConverter:
if converter is None:
return DataConverter(
payload_converter_class=_DefaultPydanticPayloadConverter
payload_converter_class=_AdkPayloadConverter
)
elif converter.payload_converter_class is DefaultPayloadConverter:
return dataclasses.replace(
converter, payload_converter_class=_DefaultPydanticPayloadConverter
converter, payload_converter_class=_AdkPayloadConverter
)
return converter


class _AdkPayloadConverter(PydanticPayloadConverter):
"""PayloadConverter for Google ADK that strips unset None fields."""

def __init__(self) -> None:
super().__init__(ToJsonOptions(exclude_unset=True))
35 changes: 35 additions & 0 deletions tests/contrib/google_adk_agents/test_google_adk_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Integration tests for ADK Temporal support."""

import json
import logging
import os
import uuid
Expand Down Expand Up @@ -855,3 +856,37 @@ async def test_activity_tool_supports_complex_inputs_via_adk(client: Client):
),
"annotate_trip": "SFO->LAX:3",
}


def test_unset_none_fields_stripped() -> None:
"""ADK plugin converter strips unset None fields from Pydantic payloads."""
plugin = GoogleAdkPlugin()
converter = plugin._configure_data_converter(None)
request = LlmRequest(
model="gemini-2.0-flash",
contents=[Content(parts=[Part(text="hello")])],
)
payloads = converter.payload_converter.to_payloads([request])
serialized = json.loads(payloads[0].data)

assert serialized["model"] == "gemini-2.0-flash"
assert "contents" in serialized
for field in ("cache_config", "cache_metadata",
"cacheable_contents_token_count", "previous_interaction_id"):
assert field not in serialized, f"Unset field {field!r} should be stripped"


def test_explicitly_set_none_preserved() -> None:
"""Explicitly-set None is preserved (exclude_unset, not exclude_none)."""
plugin = GoogleAdkPlugin()
converter = plugin._configure_data_converter(None)
request = LlmRequest(
model="gemini-2.0-flash",
contents=[Content(parts=[Part(text="hello")])],
cache_config=None,
)
payloads = converter.payload_converter.to_payloads([request])
serialized = json.loads(payloads[0].data)

assert "cache_config" in serialized, "Explicitly-set None should be preserved"
assert serialized["cache_config"] is None