Skip to content
Merged
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
9 changes: 0 additions & 9 deletions src/google/adk/agents/base_agent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,3 @@ class BaseAgentConfig(BaseModel):
default=None,
description='Optional. The after_agent_callbacks of the agent.',
)

def to_agent_config(
self, custom_agent_config_cls: Type[TBaseAgentConfig]
) -> TBaseAgentConfig:
"""Converts this config to the concrete agent config type.

NOTE: this is for ADK framework use only.
"""
return custom_agent_config_cls.model_validate(self.model_dump())
21 changes: 19 additions & 2 deletions tests/unittests/agents/test_agent_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Literal

from google.adk.agents.agent_config import AgentConfig
Expand Down Expand Up @@ -115,9 +129,12 @@ class MyCustomAgentConfig(BaseAgentConfig):

config = AgentConfig.model_validate(config_data)

assert isinstance(config.root, BaseAgentConfig)
# pylint: disable=unidiomatic-typecheck Needs exact class matching.
assert type(config.root) is BaseAgentConfig
assert config.root.agent_class == "mylib.agents.MyCustomAgent"
assert config.root.model_extra == {"other_field": "other value"}

my_custom_config = config.root.to_agent_config(MyCustomAgentConfig)
my_custom_config = MyCustomAgentConfig.model_validate(
config.root.model_dump()
)
assert my_custom_config.other_field == "other value"