Skip to content

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

@rcchirwa

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)

Metadata

Metadata

Assignees

Labels

models[Component] Issues related to model supportrequest clarification[Status] The maintainer need clarification or more information from the author

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions