Skip to content

Non-serializable FunctionTool objects in state_delta cause PydanticSerializationError in AG-UI integration #5051

@surfai

Description

@surfai

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).

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementationrequest clarification[Status] The maintainer need clarification or more information from the author

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions