Skip to content

Commit 2b2b6f2

Browse files
committed
fix(cli): serialize LiteLlm graph models safely
1 parent 47ceeba commit 2b2b6f2

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/google/adk/cli/utils/graph_serialization.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
logger = logging.getLogger("google_adk." + __name__)
2323

2424
from ...agents.base_agent import BaseAgent
25+
from ...models.base_llm import BaseLlm
2526
from ...tools.base_toolset import BaseToolset
2627

2728
# Node type mapping for cleaner lookup
@@ -227,6 +228,10 @@ def serialize_agent(agent: BaseAgent) -> dict[str, Any]:
227228
# Handle nested agents
228229
if isinstance(value, BaseAgent):
229230
agent_dict[field_name] = serialize_agent(value)
231+
elif isinstance(value, BaseLlm):
232+
agent_dict[field_name] = value.model_dump(
233+
mode="python", exclude={"llm_client"}, exclude_none=True
234+
)
230235
# Handle simple types and collections
231236
elif isinstance(value, (str, int, float, bool, list, dict)):
232237
agent_dict[field_name] = value

tests/unittests/cli/utils/test_graph_serialization.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
"""Tests for graph_serialization edge handling with routing maps."""
1616

17+
import json
18+
19+
from google.adk.agents import LlmAgent
1720
from google.adk.cli.utils.graph_serialization import serialize_agent
21+
from google.adk.models.lite_llm import LiteLlm
1822
from google.adk.tools.base_toolset import BaseToolset
1923
from google.adk.workflow import START
2024
from google.adk.workflow import Workflow
@@ -126,3 +130,15 @@ def __init__(self):
126130
assert len(result['tools']) == 1
127131
assert result['tools'][0]['name'] == 'MockToolset'
128132
assert result['tools'][0]['type'] == 'tool'
133+
134+
135+
def test_serialize_agent_with_litellm_model_is_json_safe() -> None:
136+
agent = LlmAgent(
137+
name='repro',
138+
model=LiteLlm(model='ollama_chat/llama3'),
139+
)
140+
141+
result = serialize_agent(agent)
142+
143+
assert result['model'] == {'model': 'ollama_chat/llama3'}
144+
json.dumps(result)

0 commit comments

Comments
 (0)