File tree Expand file tree Collapse file tree 6 files changed +54
-0
lines changed Expand file tree Collapse file tree 6 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ class LoopAgent(BaseAgent):
66
66
async def _run_async_impl (
67
67
self , ctx : InvocationContext
68
68
) -> AsyncGenerator [Event , None ]:
69
+ if not self .sub_agents :
70
+ return
71
+
69
72
times_looped = 0
70
73
while not self .max_iterations or times_looped < self .max_iterations :
71
74
for sub_agent in self .sub_agents :
Original file line number Diff line number Diff line change @@ -175,6 +175,9 @@ class ParallelAgent(BaseAgent):
175
175
async def _run_async_impl (
176
176
self , ctx : InvocationContext
177
177
) -> AsyncGenerator [Event , None ]:
178
+ if not self .sub_agents :
179
+ return
180
+
178
181
agent_runs = [
179
182
sub_agent .run_async (
180
183
_create_branch_ctx_for_sub_agent (self , sub_agent , ctx )
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ class SequentialAgent(BaseAgent):
51
51
async def _run_async_impl (
52
52
self , ctx : InvocationContext
53
53
) -> AsyncGenerator [Event , None ]:
54
+ # Skip if there is no sub-agent.
55
+ if not self .sub_agents :
56
+ return
57
+
54
58
for sub_agent in self .sub_agents :
55
59
pause_invocation = False
56
60
@@ -80,6 +84,9 @@ async def _run_live_impl(
80
84
Args:
81
85
ctx: The invocation context of the agent.
82
86
"""
87
+ if not self .sub_agents :
88
+ return
89
+
83
90
# There is no way to know if it's using live during init phase so we have to init it here
84
91
for sub_agent in self .sub_agents :
85
92
# add tool
Original file line number Diff line number Diff line change @@ -114,6 +114,20 @@ async def test_run_async(request: pytest.FixtureRequest):
114
114
assert events [1 ].content .parts [0 ].text == f'Hello, async { agent .name } !'
115
115
116
116
117
+ @pytest .mark .asyncio
118
+ async def test_run_async_skip_if_no_sub_agent (request : pytest .FixtureRequest ):
119
+ loop_agent = LoopAgent (
120
+ name = f'{ request .function .__name__ } _test_loop_agent' ,
121
+ max_iterations = 2 ,
122
+ sub_agents = [],
123
+ )
124
+ parent_ctx = await _create_parent_invocation_context (
125
+ request .function .__name__ , loop_agent
126
+ )
127
+ events = [e async for e in loop_agent .run_async (parent_ctx )]
128
+ assert not events
129
+
130
+
117
131
@pytest .mark .asyncio
118
132
async def test_run_async_with_escalate_action (request : pytest .FixtureRequest ):
119
133
non_escalating_agent = _TestingAgent (
Original file line number Diff line number Diff line change @@ -184,6 +184,19 @@ async def test_generating_one_event_per_agent_at_once(
184
184
# Asserts on event are done in _TestingAgentWithMultipleEvents.
185
185
186
186
187
+ @pytest .mark .asyncio
188
+ async def test_run_async_skip_if_no_sub_agent (request : pytest .FixtureRequest ):
189
+ parallel_agent = ParallelAgent (
190
+ name = f'{ request .function .__name__ } _test_parallel_agent' ,
191
+ sub_agents = [],
192
+ )
193
+ parent_ctx = await _create_parent_invocation_context (
194
+ request .function .__name__ , parallel_agent
195
+ )
196
+ events = [e async for e in parallel_agent .run_async (parent_ctx )]
197
+ assert not events
198
+
199
+
187
200
class _TestingAgentWithException (_TestingAgent ):
188
201
"""Mock agent for testing."""
189
202
Original file line number Diff line number Diff line change @@ -91,6 +91,20 @@ async def test_run_async(request: pytest.FixtureRequest):
91
91
assert events [1 ].content .parts [0 ].text == f'Hello, async { agent_2 .name } !'
92
92
93
93
94
+ @pytest .mark .asyncio
95
+ async def test_run_async_skip_if_no_sub_agent (request : pytest .FixtureRequest ):
96
+ sequential_agent = SequentialAgent (
97
+ name = f'{ request .function .__name__ } _test_agent' ,
98
+ sub_agents = [],
99
+ )
100
+ parent_ctx = await _create_parent_invocation_context (
101
+ request .function .__name__ , sequential_agent
102
+ )
103
+ events = [e async for e in sequential_agent .run_async (parent_ctx )]
104
+
105
+ assert not events
106
+
107
+
94
108
@pytest .mark .asyncio
95
109
async def test_run_live (request : pytest .FixtureRequest ):
96
110
agent_1 = _TestingAgent (name = f'{ request .function .__name__ } _test_agent_1' )
You can’t perform that action at this time.
0 commit comments