You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
build_graph 500: serialize_agent fails to JSON-serialize LiteLlm model (LiteLLMClient) #5949
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:
Install google-adk==2.1.0.
Minimal, framework-only reproduction:
importjsonfromgoogle.adk.agentsimportLlmAgentfromgoogle.adk.models.lite_llmimportLiteLlmfromgoogle.adk.cli.utils.graph_serializationimportserialize_agentagent=LlmAgent(name="repro", model=LiteLlm(model="ollama_chat/llama3"))
json.dumps(serialize_agent(agent))
# TypeError: Object of type LiteLLMClient is not JSON serializable
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.pyserialize_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)
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.
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?
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?
Activity
jordanchendev commentedon Jun 3, 2026
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 runtimellm_clientobject in the graph payload, which makes the result fail JSON serialization.The local fix I'm testing is small: exclude the runtime
llm_clientfield when graph serialization dumps model config, while keeping the configured LiteLlm model name in the graph response. I also added a unit test undertests/unittests/cli/utils/test_graph_serialization.pyto assert the serialized graph is JSON-safe.If this direction looks acceptable, I can open a PR linked to this issue.
boyangsvl commentedon Jun 3, 2026
/adk-issue-analyzze
llalitkumarrr commentedon Jun 4, 2026
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?
fix(cli): Serialize LiteLlm graph models safely
fix(cli): Serialize LiteLlm graph models safely
fix(cli): Serialize LiteLlm graph models safely
fix(cli): Serialize LiteLlm graph models safely