adk web build_graph crashes with LiteLlm model due to non-serializable LiteLLMClient
## Describe the Bug
When an ADK app uses google.adk.models.lite_llm.LiteLlm as the root agent model, adk web loads the app successfully but the dev builder endpoint crashes when rendering the graph.
The failing endpoint is:
GET /dev/build_graph/{app_name}
The crash happens because LiteLlm contains an internal llm_client: LiteLLMClient field, and ADK's builder serialization path calls model_dump() on the model object. That includes the LiteLLMClient instance, which Pydantic cannot serialize.
Steps to Reproduce
- Install
google-adkwith LiteLLM support. - Create a minimal agent like this:
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm
root_agent = Agent(
name="root_agent",
model=LiteLlm(model="openrouter/openai/gpt-5.4-mini"),
instruction="You are a helpful assistant.",
)
- Run:
adk web
- Open the dev UI or request:
http://127.0.0.1:8000/dev/build_graph/src
Expected Behavior
/dev/build_graph/{app_name} should return the serialized graph JSON and the dev UI should render normally.
Observed Behavior
/dev/build_graph/{app_name} returns 500 Internal Server Error.
Traceback:
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.adk.models.lite_llm.LiteLLMClient'>
In my local repro, LiteLlm.model_dump(mode="python", exclude_none=True) includes:
{
"model": "openrouter/openai/gpt-5.4-mini",
"llm_client": <google.adk.models.lite_llm.LiteLLMClient object at ...>,
}
Root Cause
The builder endpoint in google/adk/cli/adk_web_server.py serializes agent fields like this:
elif hasattr(value, "model_dump"):
agent_dict[field_name] = value.model_dump(mode="python", exclude_none=True)
For LiteLlm, that includes llm_client, which is not serializable.
LiteLlm currently defines:
llm_client: LiteLLMClient = Field(default_factory=LiteLLMClient)
so the model shape itself is not safe for this serialization path.
Environment Details
- ADK Library Version: 1.31.0
- Desktop OS: Windows 11
- Python Version: 3.12
Model Information
- Are you using LiteLLM: Yes
- Which model is being used:
openrouter/openai/gpt-5.4-mini
Additional Context
The app itself imports and loads correctly. The failure is specific to the ADK Web builder serialization path.
As a local workaround, excluding llm_client from Pydantic serialization fixes the issue, e.g. by marking the field exclude=True in a subclass of LiteLlm.
That suggests the fix likely belongs either in:
LiteLlmitself (excludellm_clientfrom serialization), or- the
/dev/build_graphserializer (special-case model objects / use a safer fallback path for non-serializable fields).
Hi, I'd like to work on this.
I've gone through the root cause -- the fix likely sits in LiteLlm itself, marking llm_client with Field(exclude=True) so it's dropped from model_dump() output before the builder serialization path sees it. Option 2 (fallback in the serializer) could also work as a safety net.
Could you assign this to me? Happy to have a PR up shortly.
Hi @LukasKH , Thanks for reporting this and detailed write up, your analysis of the serialization path is exactly right. I have successfully reproduced the issue on my end.
I see @ammarfitwalla , has already raised a PR to address this. Our team will review the PR, and it will get merged once it is approved. If you have a moment, I would highly suggest checking out that PR and letting us know if it fully resolves the problem on your end. While the PR is in review you can try this workaround:
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm
from typing import Any, Dict
class WebSafeLiteLlm(LiteLlm):
"""
Dev-Server-safe wrapper around LiteLlm.
Overrides serialization to prevent `adk web` from crashing on llm_client.
"""
def model_dump(self, *args, **kwargs) -> Dict[str, Any]:
return {
"model": self.model,
"type": "LiteLlm (Web Safe Workaround)"
}
# Instantiate your agent using the safe wrapper
root_agent = Agent(
name="root_agent",
model=WebSafeLiteLlm(model="openrouter/openai/gpt-4o-mini"),
instruction="You are a helpful assistant."
)
We appreciate your contributions.
Hi @sanketpatil06,
I was also facing the same issue; your workaround fixed this issue for me however I faced another problem that the frontend dev-UI was calling an endpoint which the backend doesn't expose.
INFO: ::1:50647 - "GET /dev/build_graph_image/{app_name}?dark_mode=true HTTP/1.1" 404 Not Found
Issue is mentioned here: https://github.com/google/adk-python/issues/5430
Hi @LukasKH, I am closing this issue. Feel free to reach out if you need any help. Thanks.