Skip to content

build_graph 500: serialize_agent fails to JSON-serialize LiteLlm model (LiteLLMClient) #5949

Closed

Description

@rcchirwa

Describe the Bug:
The dev UI's agent-graph panel calls GET /dev/apps/{app}/build_graph, which returns 500 for any agent whose model is a LiteLlm instance. serialize_agent calls model_dump() on the model field, which embeds the live LiteLLMClient (LiteLlm.llm_client) — a non-JSON-serializable object — so FastAPI's response serialization raises PydanticSerializationError. Affects every LiteLLM-backed agent.

Steps to Reproduce:

  1. Install google-adk==2.1.0.
  2. Minimal, framework-only reproduction:
    import json
    from google.adk.agents import LlmAgent
    from google.adk.models.lite_llm import LiteLlm
    from google.adk.cli.utils.graph_serialization import serialize_agent
    
    agent = LlmAgent(name="repro", model=LiteLlm(model="ollama_chat/llama3"))
    json.dumps(serialize_agent(agent))
    # TypeError: Object of type LiteLLMClient is not JSON serializable
  3. End to end: run adk web with a LiteLlm agent, open the agent in the UI; the graph panel fires GET /dev/apps/{app}/build_graph -> 500.

Expected Behavior:
build_graph returns a JSON graph of the agent; the model field is summarized (e.g. model name/string) rather than dumping the runtime client.

Observed Behavior:
500 Internal Server Error. Stack trace tail:

File ".../fastapi/_compat/v2.py", line 231, in serialize_json
    return self._type_adapter.dump_json(...)
File ".../pydantic/type_adapter.py", line 677, in dump_json
    return self.serializer.to_json(...)
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.adk.models.lite_llm.LiteLLMClient'>

Root cause: cli/utils/graph_serialization.py serialize_agent -> the generic else branch does value.model_dump() on the model field; LiteLlm.model_dump() includes llm_client: LiteLLMClient. The /dev/apps/{app}/build_graph route returns this raw (-> Any, no response model), so FastAPI then can't JSON-encode it. (Note: the route is already marked # TODO: remove this endpoint once build_graph_image is completed; build_graph_image returns 200.)

Environment Details:

  • ADK Library Version (pip show google-adk): 2.1.0
  • Desktop OS: macOS 26.5 (arm64)
  • Python Version (python -V): 3.11.15

Model Information:

  • Are you using LiteLLM: Yes (litellm 1.86.2)
  • Which model is being used: ollama_chat/* via LiteLlm (e.g. ollama_chat/gemma4)

Activity

  1. added
    models[Component] This issue is related to model support
    on Jun 3, 2026
  2. added theissue type on Jun 3, 2026
  3. jordanchendev commented on Jun 3, 2026

    @jordanchendev
    Contributor

    Hi maintainers, I'd like to work on this issue if that's okay.

    I reproduced the failure locally with a regression test for LlmAgent(model=LiteLlm(...)): serialize_agent() currently includes LiteLlm's runtime llm_client object in the graph payload, which makes the result fail JSON serialization.

    The local fix I'm testing is small: exclude the runtime llm_client field when graph serialization dumps model config, while keeping the configured LiteLlm model name in the graph response. I also added a unit test under tests/unittests/cli/utils/test_graph_serialization.py to assert the serialized graph is JSON-safe.

    If this direction looks acceptable, I can open a PR linked to this issue.

  4. boyangsvl commented on Jun 3, 2026

    @boyangsvl
    Collaborator

    /adk-issue-analyzze

  5. llalitkumarrr commented on Jun 4, 2026

    @llalitkumarrr
    Collaborator

    Hello @rcchirwa ,

    We were able to reproduce the issue and observed the same behavior. To help resolve this, could you please update line 2184 in src/google/adk/models/lite_llm.py?

    Please change:
    llm_client: LiteLLMClient = Field(default_factory=LiteLLMClient)

    to:
    llm_client: LiteLLMClient = Field(default_factory=LiteLLMClient, exclude=True)
    Could you please test this change and let us know if it resolves the issue for you?

  6. added
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

models[Component] This issue is related to model supportrequest 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