Skip to content

Commit ec7d9b0

Browse files
Jacksunweicopybara-github
authored andcommitted
chore(config): Moves agent configs to separate python files
PiperOrigin-RevId: 787245794
1 parent 6419a2a commit ec7d9b0

11 files changed

+264
-172
lines changed

src/google/adk/agents/agent_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
from ..utils.feature_decorator import working_in_progress
2424
from .base_agent import BaseAgentConfig
25-
from .llm_agent import LlmAgentConfig
26-
from .loop_agent import LoopAgentConfig
25+
from .llm_agent_config import LlmAgentConfig
26+
from .loop_agent_config import LoopAgentConfig
2727
from .parallel_agent import ParallelAgentConfig
2828
from .sequential_agent import SequentialAgentConfig
2929

src/google/adk/agents/config_agent_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
from .base_agent_config import SubAgentConfig
2828
from .common_configs import CodeConfig
2929
from .llm_agent import LlmAgent
30-
from .llm_agent import LlmAgentConfig
30+
from .llm_agent_config import LlmAgentConfig
3131
from .loop_agent import LoopAgent
32-
from .loop_agent import LoopAgentConfig
32+
from .loop_agent_config import LoopAgentConfig
3333
from .parallel_agent import ParallelAgent
3434
from .parallel_agent import ParallelAgentConfig
3535
from .sequential_agent import SequentialAgent

src/google/adk/agents/llm_agent.py

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
from typing import AsyncGenerator
2222
from typing import Awaitable
2323
from typing import Callable
24-
from typing import List
2524
from typing import Literal
2625
from typing import Optional
2726
from typing import Type
2827
from typing import Union
2928

3029
from google.genai import types
3130
from pydantic import BaseModel
32-
from pydantic import ConfigDict
3331
from pydantic import Field
3432
from pydantic import field_validator
3533
from pydantic import model_validator
@@ -54,10 +52,10 @@
5452
from ..tools.tool_context import ToolContext
5553
from ..utils.feature_decorator import working_in_progress
5654
from .base_agent import BaseAgent
57-
from .base_agent_config import BaseAgentConfig
5855
from .callback_context import CallbackContext
5956
from .common_configs import CodeConfig
6057
from .invocation_context import InvocationContext
58+
from .llm_agent_config import LlmAgentConfig
6159
from .readonly_context import ReadonlyContext
6260

6361
logger = logging.getLogger('google_adk.' + __name__)
@@ -603,115 +601,3 @@ def from_config(
603601

604602

605603
Agent: TypeAlias = LlmAgent
606-
607-
608-
class LlmAgentConfig(BaseAgentConfig):
609-
"""The config for the YAML schema of a LlmAgent."""
610-
611-
model_config = ConfigDict(
612-
extra='forbid',
613-
)
614-
615-
agent_class: Literal['LlmAgent', ''] = 'LlmAgent'
616-
"""The value is used to uniquely identify the LlmAgent class. If it is
617-
empty, it is by default an LlmAgent."""
618-
619-
model: Optional[str] = None
620-
"""Optional. LlmAgent.model. If not set, the model will be inherited from
621-
the ancestor."""
622-
623-
instruction: str
624-
"""Required. LlmAgent.instruction."""
625-
626-
disallow_transfer_to_parent: Optional[bool] = None
627-
"""Optional. LlmAgent.disallow_transfer_to_parent."""
628-
629-
disallow_transfer_to_peers: Optional[bool] = None
630-
"""Optional. LlmAgent.disallow_transfer_to_peers."""
631-
632-
input_schema: Optional[CodeConfig] = None
633-
"""Optional. LlmAgent.input_schema."""
634-
635-
output_schema: Optional[CodeConfig] = None
636-
"""Optional. LlmAgent.output_schema."""
637-
638-
output_key: Optional[str] = None
639-
"""Optional. LlmAgent.output_key."""
640-
641-
include_contents: Literal['default', 'none'] = 'default'
642-
"""Optional. LlmAgent.include_contents."""
643-
644-
tools: Optional[list[CodeConfig]] = None
645-
"""Optional. LlmAgent.tools.
646-
647-
Examples:
648-
649-
For ADK built-in tools in `google.adk.tools` package, they can be referenced
650-
directly with the name:
651-
652-
```
653-
tools:
654-
- name: google_search
655-
- name: load_memory
656-
```
657-
658-
For user-defined tools, they can be referenced with fully qualified name:
659-
660-
```
661-
tools:
662-
- name: my_library.my_tools.my_tool
663-
```
664-
665-
For tools that needs to be created via functions:
666-
667-
```
668-
tools:
669-
- name: my_library.my_tools.create_tool
670-
args:
671-
- name: param1
672-
value: value1
673-
- name: param2
674-
value: value2
675-
```
676-
677-
For more advanced tools, instead of specifying arguments in config, it's
678-
recommended to define them in Python files and reference them. E.g.,
679-
680-
```
681-
# tools.py
682-
my_mcp_toolset = MCPToolset(
683-
connection_params=StdioServerParameters(
684-
command="npx",
685-
args=["-y", "@notionhq/notion-mcp-server"],
686-
env={"OPENAPI_MCP_HEADERS": NOTION_HEADERS},
687-
)
688-
)
689-
```
690-
691-
Then, reference the toolset in config:
692-
693-
```
694-
tools:
695-
- name: tools.my_mcp_toolset
696-
```
697-
"""
698-
699-
before_model_callbacks: Optional[List[CodeConfig]] = None
700-
"""Optional. LlmAgent.before_model_callbacks.
701-
702-
Example:
703-
704-
```
705-
before_model_callbacks:
706-
- name: my_library.callbacks.before_model_callback
707-
```
708-
"""
709-
710-
after_model_callbacks: Optional[List[CodeConfig]] = None
711-
"""Optional. LlmAgent.after_model_callbacks."""
712-
713-
before_tool_callbacks: Optional[List[CodeConfig]] = None
714-
"""Optional. LlmAgent.before_tool_callbacks."""
715-
716-
after_tool_callbacks: Optional[List[CodeConfig]] = None
717-
"""Optional. LlmAgent.after_tool_callbacks."""
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
import logging
18+
from typing import List
19+
from typing import Literal
20+
from typing import Optional
21+
22+
from pydantic import ConfigDict
23+
24+
from .base_agent_config import BaseAgentConfig
25+
from .common_configs import CodeConfig
26+
27+
logger = logging.getLogger('google_adk.' + __name__)
28+
29+
30+
class LlmAgentConfig(BaseAgentConfig):
31+
"""The config for the YAML schema of a LlmAgent."""
32+
33+
model_config = ConfigDict(
34+
extra='forbid',
35+
)
36+
37+
agent_class: Literal['LlmAgent', ''] = 'LlmAgent'
38+
"""The value is used to uniquely identify the LlmAgent class. If it is
39+
empty, it is by default an LlmAgent."""
40+
41+
model: Optional[str] = None
42+
"""Optional. LlmAgent.model. If not set, the model will be inherited from
43+
the ancestor."""
44+
45+
instruction: str
46+
"""Required. LlmAgent.instruction."""
47+
48+
disallow_transfer_to_parent: Optional[bool] = None
49+
"""Optional. LlmAgent.disallow_transfer_to_parent."""
50+
51+
disallow_transfer_to_peers: Optional[bool] = None
52+
"""Optional. LlmAgent.disallow_transfer_to_peers."""
53+
54+
input_schema: Optional[CodeConfig] = None
55+
"""Optional. LlmAgent.input_schema."""
56+
57+
output_schema: Optional[CodeConfig] = None
58+
"""Optional. LlmAgent.output_schema."""
59+
60+
output_key: Optional[str] = None
61+
"""Optional. LlmAgent.output_key."""
62+
63+
include_contents: Literal['default', 'none'] = 'default'
64+
"""Optional. LlmAgent.include_contents."""
65+
66+
tools: Optional[list[CodeConfig]] = None
67+
"""Optional. LlmAgent.tools.
68+
69+
Examples:
70+
71+
For ADK built-in tools in `google.adk.tools` package, they can be referenced
72+
directly with the name:
73+
74+
```
75+
tools:
76+
- name: google_search
77+
- name: load_memory
78+
```
79+
80+
For user-defined tools, they can be referenced with fully qualified name:
81+
82+
```
83+
tools:
84+
- name: my_library.my_tools.my_tool
85+
```
86+
87+
For tools that needs to be created via functions:
88+
89+
```
90+
tools:
91+
- name: my_library.my_tools.create_tool
92+
args:
93+
- name: param1
94+
value: value1
95+
- name: param2
96+
value: value2
97+
```
98+
99+
For more advanced tools, instead of specifying arguments in config, it's
100+
recommended to define them in Python files and reference them. E.g.,
101+
102+
```
103+
# tools.py
104+
my_mcp_toolset = MCPToolset(
105+
connection_params=StdioServerParameters(
106+
command="npx",
107+
args=["-y", "@notionhq/notion-mcp-server"],
108+
env={"OPENAPI_MCP_HEADERS": NOTION_HEADERS},
109+
)
110+
)
111+
```
112+
113+
Then, reference the toolset in config:
114+
115+
```
116+
tools:
117+
- name: tools.my_mcp_toolset
118+
```
119+
"""
120+
121+
before_model_callbacks: Optional[List[CodeConfig]] = None
122+
"""Optional. LlmAgent.before_model_callbacks.
123+
124+
Example:
125+
126+
```
127+
before_model_callbacks:
128+
- name: my_library.callbacks.before_model_callback
129+
```
130+
"""
131+
132+
after_model_callbacks: Optional[List[CodeConfig]] = None
133+
"""Optional. LlmAgent.after_model_callbacks."""
134+
135+
before_tool_callbacks: Optional[List[CodeConfig]] = None
136+
"""Optional. LlmAgent.before_tool_callbacks."""
137+
138+
after_tool_callbacks: Optional[List[CodeConfig]] = None
139+
"""Optional. LlmAgent.after_tool_callbacks."""

src/google/adk/agents/loop_agent.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
from __future__ import annotations
1818

1919
from typing import AsyncGenerator
20-
from typing import Literal
2120
from typing import Optional
2221
from typing import Type
2322

24-
from pydantic import ConfigDict
2523
from typing_extensions import override
2624

2725
from ..agents.invocation_context import InvocationContext
2826
from ..events.event import Event
2927
from ..utils.feature_decorator import working_in_progress
3028
from .base_agent import BaseAgent
31-
from .base_agent_config import BaseAgentConfig
29+
from .loop_agent_config import LoopAgentConfig
3230

3331

3432
class LoopAgent(BaseAgent):
@@ -83,17 +81,3 @@ def from_config(
8381
if config.max_iterations:
8482
agent.max_iterations = config.max_iterations
8583
return agent
86-
87-
88-
@working_in_progress('LoopAgentConfig is not ready for use.')
89-
class LoopAgentConfig(BaseAgentConfig):
90-
"""The config for the YAML schema of a LoopAgent."""
91-
92-
model_config = ConfigDict(
93-
extra='forbid',
94-
)
95-
96-
agent_class: Literal['LoopAgent'] = 'LoopAgent'
97-
98-
max_iterations: Optional[int] = None
99-
"""Optional. LoopAgent.max_iterations."""
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Loop agent implementation."""
16+
17+
from __future__ import annotations
18+
19+
from typing import Literal
20+
from typing import Optional
21+
22+
from pydantic import ConfigDict
23+
24+
from ..utils.feature_decorator import working_in_progress
25+
from .base_agent_config import BaseAgentConfig
26+
27+
28+
@working_in_progress('LoopAgentConfig is not ready for use.')
29+
class LoopAgentConfig(BaseAgentConfig):
30+
"""The config for the YAML schema of a LoopAgent."""
31+
32+
model_config = ConfigDict(
33+
extra='forbid',
34+
)
35+
36+
agent_class: Literal['LoopAgent'] = 'LoopAgent'
37+
38+
max_iterations: Optional[int] = None
39+
"""Optional. LoopAgent.max_iterations."""

0 commit comments

Comments
 (0)