Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/google/adk/cli/utils/graph_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
logger = logging.getLogger("google_adk." + __name__)

from ...agents.base_agent import BaseAgent
from ...models.base_llm import BaseLlm
from ...tools.base_toolset import BaseToolset

# Node type mapping for cleaner lookup
Expand Down Expand Up @@ -227,6 +228,10 @@ def serialize_agent(agent: BaseAgent) -> dict[str, Any]:
# Handle nested agents
if isinstance(value, BaseAgent):
agent_dict[field_name] = serialize_agent(value)
elif isinstance(value, BaseLlm):
agent_dict[field_name] = value.model_dump(
mode="python", exclude={"llm_client"}, exclude_none=True
)
# Handle simple types and collections
elif isinstance(value, (str, int, float, bool, list, dict)):
agent_dict[field_name] = value
Expand Down
16 changes: 16 additions & 0 deletions tests/unittests/cli/utils/test_graph_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

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

import json

from google.adk.agents import LlmAgent
from google.adk.cli.utils.graph_serialization import serialize_agent
from google.adk.models.lite_llm import LiteLlm
from google.adk.tools.base_toolset import BaseToolset
from google.adk.workflow import START
from google.adk.workflow import Workflow
Expand Down Expand Up @@ -126,3 +130,15 @@ def __init__(self):
assert len(result['tools']) == 1
assert result['tools'][0]['name'] == 'MockToolset'
assert result['tools'][0]['type'] == 'tool'


def test_serialize_agent_with_litellm_model_is_json_safe() -> None:
agent = LlmAgent(
name='repro',
model=LiteLlm(model='ollama_chat/llama3'),
)

result = serialize_agent(agent)

assert result['model'] == {'model': 'ollama_chat/llama3'}
json.dumps(result)