Skip to content

Commit a313c2c

Browse files
wuliang229copybara-github
authored andcommitted
feat(config): add configs for ParallelAgent and SequentialAgent
PiperOrigin-RevId: 781704814
1 parent d833627 commit a313c2c

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed

src/google/adk/agents/agent_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
from ..utils.feature_decorator import working_in_progress
2222
from .llm_agent import LlmAgentConfig
2323
from .loop_agent import LoopAgentConfig
24+
from .parallel_agent import ParallelAgentConfig
25+
from .sequential_agent import SequentialAgentConfig
2426

2527
# A discriminated union of all possible agent configurations.
2628
ConfigsUnion = Union[
2729
LlmAgentConfig,
2830
LoopAgentConfig,
31+
ParallelAgentConfig,
32+
SequentialAgentConfig,
2933
]
3034

3135

src/google/adk/agents/config_schemas/AgentConfig.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,58 @@
107107
],
108108
"title": "LoopAgentConfig",
109109
"type": "object"
110+
},
111+
"ParallelAgentConfig": {
112+
"additionalProperties": false,
113+
"description": "The config for the YAML schema of a ParallelAgent.",
114+
"properties": {
115+
"agent_class": {
116+
"const": "ParallelAgent",
117+
"default": "ParallelAgent",
118+
"title": "Agent Class",
119+
"type": "string"
120+
},
121+
"name": {
122+
"title": "Name",
123+
"type": "string"
124+
},
125+
"description": {
126+
"default": "",
127+
"title": "Description",
128+
"type": "string"
129+
}
130+
},
131+
"required": [
132+
"name"
133+
],
134+
"title": "ParallelAgentConfig",
135+
"type": "object"
136+
},
137+
"SequentialAgentConfig": {
138+
"additionalProperties": false,
139+
"description": "The config for the YAML schema of a SequentialAgent.",
140+
"properties": {
141+
"agent_class": {
142+
"const": "SequentialAgent",
143+
"default": "SequentialAgent",
144+
"title": "Agent Class",
145+
"type": "string"
146+
},
147+
"name": {
148+
"title": "Name",
149+
"type": "string"
150+
},
151+
"description": {
152+
"default": "",
153+
"title": "Description",
154+
"type": "string"
155+
}
156+
},
157+
"required": [
158+
"name"
159+
],
160+
"title": "SequentialAgentConfig",
161+
"type": "object"
110162
}
111163
},
112164
"anyOf": [
@@ -115,6 +167,12 @@
115167
},
116168
{
117169
"$ref": "#/$defs/LoopAgentConfig"
170+
},
171+
{
172+
"$ref": "#/$defs/ParallelAgentConfig"
173+
},
174+
{
175+
"$ref": "#/$defs/SequentialAgentConfig"
118176
}
119177
],
120178
"description": "The config for the YAML schema to create an agent.",

src/google/adk/agents/parallel_agent.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818

1919
import asyncio
2020
from typing import AsyncGenerator
21+
from typing import Literal
22+
from typing import Type
2123

2224
from typing_extensions import override
2325

26+
from ..agents.base_agent import BaseAgentConfig
27+
from ..agents.base_agent import working_in_progress
2428
from ..agents.invocation_context import InvocationContext
2529
from ..events.event import Event
2630
from .base_agent import BaseAgent
@@ -33,9 +37,9 @@ def _create_branch_ctx_for_sub_agent(
3337
) -> InvocationContext:
3438
"""Create isolated branch for every sub-agent."""
3539
invocation_context = invocation_context.model_copy()
36-
branch_suffix = f"{agent.name}.{sub_agent.name}"
40+
branch_suffix = f'{agent.name}.{sub_agent.name}'
3741
invocation_context.branch = (
38-
f"{invocation_context.branch}.{branch_suffix}"
42+
f'{invocation_context.branch}.{branch_suffix}'
3943
if invocation_context.branch
4044
else branch_suffix
4145
)
@@ -109,5 +113,21 @@ async def _run_async_impl(
109113
async def _run_live_impl(
110114
self, ctx: InvocationContext
111115
) -> AsyncGenerator[Event, None]:
112-
raise NotImplementedError("This is not supported yet for ParallelAgent.")
116+
raise NotImplementedError('This is not supported yet for ParallelAgent.')
113117
yield # AsyncGenerator requires having at least one yield statement
118+
119+
@classmethod
120+
@override
121+
@working_in_progress('ParallelAgent.from_config is not ready for use.')
122+
def from_config(
123+
cls: Type[ParallelAgent],
124+
config: ParallelAgentConfig,
125+
) -> ParallelAgent:
126+
return super().from_config(config)
127+
128+
129+
@working_in_progress('ParallelAgentConfig is not ready for use.')
130+
class ParallelAgentConfig(BaseAgentConfig):
131+
"""The config for the YAML schema of a ParallelAgent."""
132+
133+
agent_class: Literal['ParallelAgent'] = 'ParallelAgent'

src/google/adk/agents/sequential_agent.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
from __future__ import annotations
1818

1919
from typing import AsyncGenerator
20+
from typing import Literal
21+
from typing import Type
2022

2123
from typing_extensions import override
2224

25+
from ..agents.base_agent import BaseAgentConfig
26+
from ..agents.base_agent import working_in_progress
2327
from ..agents.invocation_context import InvocationContext
2428
from ..events.event import Event
2529
from .base_agent import BaseAgent
@@ -60,7 +64,7 @@ def task_completed():
6064
Signals that the model has successfully completed the user's question
6165
or task.
6266
"""
63-
return "Task completion signaled."
67+
return 'Task completion signaled.'
6468

6569
if isinstance(sub_agent, LlmAgent):
6670
# Use function name to dedupe.
@@ -74,3 +78,19 @@ def task_completed():
7478
for sub_agent in self.sub_agents:
7579
async for event in sub_agent.run_live(ctx):
7680
yield event
81+
82+
@classmethod
83+
@override
84+
@working_in_progress('SequentialAgent.from_config is not ready for use.')
85+
def from_config(
86+
cls: Type[SequentialAgent],
87+
config: SequentialAgentConfig,
88+
) -> SequentialAgent:
89+
return super().from_config(config)
90+
91+
92+
@working_in_progress('SequentialAgentConfig is not ready for use.')
93+
class SequentialAgentConfig(BaseAgentConfig):
94+
"""The config for the YAML schema of a SequentialAgent."""
95+
96+
agent_class: Literal['SequentialAgent'] = 'SequentialAgent'

0 commit comments

Comments
 (0)