Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 11 additions & 5 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 @@ -111,11 +112,16 @@ def _configure_data_converter(
self, converter: DataConverter | None
) -> DataConverter:
if converter is None:
return DataConverter(
payload_converter_class=_DefaultPydanticPayloadConverter
)
return DataConverter(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))
39 changes: 39 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 @@ -963,3 +964,41 @@ def supported_models(cls) -> list[str]:
assert result.content is not None
assert result.content.parts is not None
assert result.content.parts[0].text == "hello from litellm"


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
Loading