Skip to content

fix: Rollback https://github.com/google/adk-python/commit/2aab1cf98e1d0e8454764b549fac21475a633409 temporally #2169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 1 addition & 6 deletions src/google/adk/agents/loop_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ async def _run_async_impl(
times_looped = 0
while not self.max_iterations or times_looped < self.max_iterations:
for sub_agent in self.sub_agents:
should_exit = False
async for event in sub_agent.run_async(ctx):
yield event
if event.actions.escalate:
should_exit = True

if should_exit:
return

return
times_looped += 1
return

Expand Down
1 change: 0 additions & 1 deletion src/google/adk/tools/exit_loop_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ def exit_loop(tool_context: ToolContext):
Call this function only when you are instructed to do so.
"""
tool_context.actions.escalate = True
tool_context.actions.skip_summarization = True
17 changes: 2 additions & 15 deletions tests/unittests/agents/test_loop_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ async def _run_async_impl(
),
actions=EventActions(escalate=True),
)
yield Event(
author=self.name,
invocation_id=ctx.invocation_id,
content=types.Content(
parts=[types.Part(text=f'I have done my job after escalation!!')]
),
)


async def _create_parent_invocation_context(
Expand Down Expand Up @@ -122,20 +115,17 @@ async def test_run_async_with_escalate_action(request: pytest.FixtureRequest):
escalating_agent = _TestingAgentWithEscalateAction(
name=f'{request.function.__name__}_test_escalating_agent'
)
ignored_agent = _TestingAgent(
name=f'{request.function.__name__}_test_ignored_agent'
)
loop_agent = LoopAgent(
name=f'{request.function.__name__}_test_loop_agent',
sub_agents=[non_escalating_agent, escalating_agent, ignored_agent],
sub_agents=[non_escalating_agent, escalating_agent],
)
parent_ctx = await _create_parent_invocation_context(
request.function.__name__, loop_agent
)
events = [e async for e in loop_agent.run_async(parent_ctx)]

# Only two events are generated because the sub escalating_agent escalates.
assert len(events) == 3
assert len(events) == 2
assert events[0].author == non_escalating_agent.name
assert events[1].author == escalating_agent.name
assert events[0].content.parts[0].text == (
Expand All @@ -144,6 +134,3 @@ async def test_run_async_with_escalate_action(request: pytest.FixtureRequest):
assert events[1].content.parts[0].text == (
f'Hello, async {escalating_agent.name}!'
)
assert (
events[2].content.parts[0].text == 'I have done my job after escalation!!'
)
4 changes: 3 additions & 1 deletion tests/unittests/flows/llm_flows/test_agent_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ def test_auto_to_loop():
name='exit_loop', response={'result': None}
),
),
# root_agent summarizes.
('root_agent', 'response4'),
]

# root_agent should still be the current agent because sub_agent_1 is loop.
assert testing_utils.simplify_events(runner.run('test2')) == [
('root_agent', 'response4'),
('root_agent', 'response5'),
]
Loading