Skip to content

Error serializing to JSON - can't encode character '\udcc3' #4480

@cl3m3nt

Description

@cl3m3nt

🔴 Required Information

Please ensure all items in this section are completed to allow for efficient
triaging. Requests without complete information may be rejected / deprioritized.
If an item is not applicable to you - please mark it as N/A

Describe the Bug:
adk run crashes on Ubuntu 24.04.4 LTS during interaction with remote LiteLLM model gpt-oss-20b or ministral3.
LLM server is provided using LM Studio which does not crash while adk run client does.
The issue occurs randomly during the interaction which can goes well for a while then client crash.
Initially suspected this might come from special character, but it occurs even with non specific french character.
The issue did NOT show up so far on Mac M4 Sequoia 15.6.1 when using adk run.

Steps to Reproduce:
Please provide a numbered list of steps to reproduce the behavior:

  1. Install '...'
  2. Run '....'
  3. Open '....'
  4. Provide error or stacktrace
    See stacktrace below

Expected Behavior:
The client should keep working correctly.

Observed Behavior:
The adk run client crashes, the Lite LLM server not.

Environment Details:

  • ADK Library Version (pip show google-adk): 1.25.0
  • Desktop OS:** [e.g., macOS, Linux, Windows]: Ubuntu 24.04.4 LTS
  • Python Version (python -V): Python 3.12.12

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: (e.g., gemini-2.5-pro) gpt-oss-20b, ministral-3-3b

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression:
Did this work in a previous version of ADK? If so, which one?
Do not know

Logs:
Please attach relevant logs. Wrap them in code blocks (```) or attach a
text file.

[user]: parce que côté serveur, ça ne plante pas quand le client plante
Traceback (most recent call last):
  File "/home/user/anaconda3/envs/gcpAgent/bin/adk", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/click/core.py", line 1485, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/click/core.py", line 1406, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/click/core.py", line 1873, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/click/core.py", line 1269, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/click/core.py", line 824, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/cli_tools_click.py", line 126, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/cli_tools_click.py", line 569, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/cli_tools_click.py", line 659, in cli_run
    asyncio.run(
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/cli.py", line 244, in run_cli
    await run_interactively(
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/cli.py", line 123, in run_interactively
    async for event in agen:
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/runners.py", line 561, in run_async
    async for event in agen:
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/runners.py", line 529, in _run_with_trace
    invocation_context = await self._setup_context_for_new_invocation(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/runners.py", line 1282, in _setup_context_for_new_invocation
    await self._handle_new_message(
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/runners.py", line 1479, in _handle_new_message
    await self._append_new_message_to_session(
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/runners.py", line 920, in _append_new_message_to_session
    await self.session_service.append_event(session=session, event=event)
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/cli/utils/local_storage.py", line 213, in append_event
    return await service.append_event(session, event)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/google/adk/sessions/sqlite_session_service.py", line 432, in append_event
    event.model_dump_json(exclude_none=True),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/gcpAgent/lib/python3.12/site-packages/pydantic/main.py", line 528, in model_dump_json
    return self.__pydantic_serializer__.to_json(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 24: surrogates not allowed

Screenshots / Video:
If applicable, add screenshots or screen recordings to help explain
your problem.

Additional Context:
Add any other context about the problem here.

Minimal Reproduction Code:
Please provide a code snippet or a link to a Gist/repo that isolates the issue.

import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm

def get_weather(city: str) -> dict:
    """Retrieves the current weather report for a specified city.

    Args:
        city (str): The name of the city for which to retrieve the weather report.

    Returns:
        dict: status and result or error msg.
    """
    if city.lower() == "new york":
        return {
            "status": "success",
            "report": (
                "The weather in New York is sunny with a temperature of 25 degrees"
                " Celsius (77 degrees Fahrenheit)."
            ),
        }
    else:
        return {
            "status": "error",
            "error_message": f"Weather information for '{city}' is not available.",
        }


def get_current_time(city: str) -> dict:
    """Returns the current time in a specified city.

    Args:
        city (str): The name of the city for which to retrieve the current time.

    Returns:
        dict: status and result or error msg.
    """

    if city.lower() == "new york":
        tz_identifier = "America/New_York"
    else:
        return {
            "status": "error",
            "error_message": (
                f"Sorry, I don't have timezone information for {city}."
            ),
        }

    tz = ZoneInfo(tz_identifier)
    now = datetime.datetime.now(tz)
    report = (
        f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
    )
    return {"status": "success", "report": report}


root_agent = Agent(
    name="weather_time_agent",
    model=LiteLlm(   
        model="openai/gpt-oss",           
        api_base="http://x.x.x.x:7777/v1",
        api_key="lm-studio",
        disable_cost_calculation=True), 
    description=(
        "Agent to answer questions about the time and weather in a city."
    ),
    instruction=(
        "You are a helpful agent who can answer user questions about the time and weather in a city."
    ),
    tools=[get_weather, get_current_time],
)

How often has this issue occurred?:

  • Intermittently (<50%)

Metadata

Metadata

Assignees

No one assigned

    Labels

    models[Component] Issues related to model support

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions