Description
When using ADK with ag_ui_adk, the event encoder fails with PydanticSerializationError because state_delta events contain FunctionTool objects that Pydantic cannot serialize to JSON.
The AG-UI event encoder calls event.model_dump_json() on StateDeltaEvent, which includes state_delta values. ADK injects internal objects (e.g. FunctionTool instances) into the session state, and these end up in state_delta patches sent to the frontend.
Error
Event encoding failed: Unable to serialize unknown type: <class 'google.adk.tools.function_tool.FunctionTool'>
Steps to Reproduce
from google.adk.agents import LlmAgent
from ag_ui_adk import ADKAgent, add_adk_fastapi_endpoint
agent = LlmAgent(
name="my_agent",
model="gemini-2.5-flash",
instruction="You are helpful.",
tools=[my_function_tool],
)
adk_agent = ADKAgent(
adk_agent=agent,
app_name="demo",
user_id="user1",
use_in_memory_services=True,
)
# Send any message — the state_delta event will contain FunctionTool references
Expected Behavior
state_delta events should only contain JSON-serializable values. Internal ADK objects should be filtered out before emitting state events.
Workaround
Filter non-serializable values from state_delta before creating the event:
import json
from ag_ui_adk.event_translator import EventTranslator
def _is_json_serializable(value):
try:
json.dumps(value)
return True
except (TypeError, ValueError, OverflowError):
return False
_orig = EventTranslator._create_state_delta_event
def _patched(self, state_delta, thread_id, run_id):
filtered = {k: v for k, v in state_delta.items() if _is_json_serializable(v)}
return _orig(self, filtered, thread_id, run_id)
EventTranslator._create_state_delta_event = _patched
Related
Environment
google-adk==2.0.0a2
ag-ui-adk==0.5.1
- Python 3.14
- macOS
Note: This issue was identified with AI assistance (Claude Code).
Description
When using ADK with
ag_ui_adk, the event encoder fails withPydanticSerializationErrorbecausestate_deltaevents containFunctionToolobjects that Pydantic cannot serialize to JSON.The AG-UI event encoder calls
event.model_dump_json()onStateDeltaEvent, which includesstate_deltavalues. ADK injects internal objects (e.g.FunctionToolinstances) into the session state, and these end up instate_deltapatches sent to the frontend.Error
Steps to Reproduce
Expected Behavior
state_deltaevents should only contain JSON-serializable values. Internal ADK objects should be filtered out before emitting state events.Workaround
Filter non-serializable values from
state_deltabefore creating the event:Related
SecuritySchemeType)Environment
google-adk==2.0.0a2ag-ui-adk==0.5.1