Skip to content

fix(cli): serialize LiteLlm graph models safely#5956

Open
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/graph-lite-llm-model
Open

fix(cli): serialize LiteLlm graph models safely#5956
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/graph-lite-llm-model

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #5949.

The graph serializer currently passes model fields through when their value is not a simple collection or nested agent. For LiteLlm that leaves the runtime LiteLLMClient object inside the serialized graph payload, so JSON encoding the graph fails.

This patch serializes BaseLlm values through pydantic and drops the runtime llm_client field. The graph output keeps the public model configuration, for example {"model": "ollama_chat/llama3"}, while avoiding non-JSON-safe runtime clients.

Validation:

  • .venv\Scripts\python.exe -m pytest tests\unittests\cli\utils\test_graph_serialization.py -q
  • .venv\Scripts\python.exe -m py_compile src\google\adk\cli\utils\graph_serialization.py tests\unittests\cli\utils\test_graph_serialization.py
  • .venv\Scripts\python.exe -m pyink --check src\google\adk\cli\utils\graph_serialization.py tests\unittests\cli\utils\test_graph_serialization.py
  • .venv\Scripts\python.exe -c "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')); data=serialize_agent(agent); print(data['model']); json.dumps(data); print('json ok')"
  • git diff --check

Note: I used the repo-local virtualenv because the base Python environment still has an older google-genai that lacks types.AvatarConfig.

@adk-bot adk-bot added the models [Component] Issues related to model support label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants