Skip to content

fix: allows current sub-agent to finish execution before exiting the loop agent due to a sub-agent's escalation. This commit also disables the summarization for exit_loop tool#2079

Merged
copybara-service[bot] merged 1 commit intomainfrom
copybara/785493297
Jul 21, 2025

Conversation

@copybara-service
Copy link
Copy Markdown

@copybara-service copybara-service Bot commented Jul 21, 2025

fix: allows current sub-agent to finish execution before exiting the loop agent due to a sub-agent's escalation. This commit also disables the summarization for exit_loop tool

Fixes #423

Related to #1670

  • This avoids the GeneratorExit error thrown, which would crash OTel metric collection and cause Failed to detach context error.
  • This also allows all function calls are processed when exit_loop is called together with other tools in the same LLmResponse.

A sample agent for testing:

from google.adk import Agent
from google.adk.agents.loop_agent import LoopAgent
from google.adk.tools.exit_loop_tool import exit_loop

worker_1 = Agent(
    name='worker_1',
    description='Worker 1',
    instruction="""\
Just say job #1 is done.

If job #1 is said to be done. Call exit_loop tool.""",
    tools=[exit_loop],
)

worker_2 = Agent(
    name='worker_2',
    description='Worker 2',
    instruction="""\
Just say job #2 is done.

If job #2 is said to be done. Call exit_loop tool.""",
    tools=[exit_loop],
)

work_agent = LoopAgent(
    name='work_agent',
    description='Do all work.',
    sub_agents=[worker_1, worker_2],
    max_iterations=5,
)

root_agent = Agent(
    model='gemini-2.0-flash',
    name='hello_world_agent',
    description='hello world agent that can roll a  check prime',
    instruction="""Hand off works to sub agents.""",
    sub_agents=[work_agent],
)

@copybara-service copybara-service Bot force-pushed the copybara/785493297 branch 2 times, most recently from 63f7058 to 955f477 Compare July 21, 2025 18:47
@copybara-service copybara-service Bot changed the title fix: allows current sub-agent to finish execution before exiting the loop agent due to a sub-agent's escalation fix: allows current sub-agent to finish execution before exiting the loop agent due to a sub-agent's escalation. This commit also disables the summarization for exit_loop tool Jul 21, 2025
@copybara-service copybara-service Bot force-pushed the copybara/785493297 branch from 955f477 to eb5bc10 Compare July 21, 2025 19:37
…loop agent due to a sub-agent's escalation. This commit also disables the summarization for `exit_loop` tool

Fixes #423

Related to #1670

- This avoids the `GeneratorExit` error thrown, which would crash OTel metric collection and cause `Failed to detach context` error.
- This also allows all function  calls are processed when exit_loop is called together with other tools in the same LLmResponse.

A sample agent for testing:

```
from google.adk import Agent
from google.adk.agents.loop_agent import LoopAgent
from google.adk.tools.exit_loop_tool import exit_loop

worker_1 = Agent(
    name='worker_1',
    description='Worker 1',
    instruction="""\
Just say job #1 is done.

If job #1 is said to be done. Call exit_loop tool.""",
    tools=[exit_loop],
)

worker_2 = Agent(
    name='worker_2',
    description='Worker 2',
    instruction="""\
Just say job #2 is done.

If job #2 is said to be done. Call exit_loop tool.""",
    tools=[exit_loop],
)

work_agent = LoopAgent(
    name='work_agent',
    description='Do all work.',
    sub_agents=[worker_1, worker_2],
    max_iterations=5,
)

root_agent = Agent(
    model='gemini-2.0-flash',
    name='hello_world_agent',
    description='hello world agent that can roll a  check prime',
    instruction="""Hand off works to sub agents.""",
    sub_agents=[work_agent],
)
```
PiperOrigin-RevId: 785538101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Failed to detach context

1 participant