Skip to content

fix(agents): keep a resumed SequentialAgent or LoopAgent paused while a long-running call is unanswered - #8486

Open
chaitanya0305 wants to merge 1 commit into
google:mainfrom
chaitanya0305:fix/sequential-resume-pending-long-running
Open

chaitanya0305 wants to merge 1 commit into
google:mainfrom
chaitanya0305:fix/sequential-resume-pending-long-running

Conversation

@chaitanya0305

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:

In a resumable app, a sub-agent that resumes but is still waiting on a long-running call returns without yielding anything (llm_agent.py:674). SequentialAgent and LoopAgent only notice a pause through the events their sub-agent yields, so they treat it as finished and run the next sub-agent. If the client answers one of two long-running calls, or one branch of a ParallelAgent, the rest of the workflow runs early and the invocation ends. The later answer is then ignored.

Solution:

Before moving to the next sub-agent, SequentialAgent and LoopAgent also check whether the current invocation still has an unanswered interrupt. This reuses index_open_interrupts, which the router and the runner already use, through a new private InvocationContext._has_open_interrupts(). An answer from the user, or a sealing error response, still closes an interrupt the same way.

Nothing changes for non-resumable apps, for answers sent together in one message, or for a single LlmAgent or ParallelAgent root, which already wait correctly.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

New tests in tests/unittests/runners/test_resume_invocation.py:

  • test_answering_one_of_two_long_running_calls_keeps_workflow_paused[SequentialAgent]
  • test_answering_one_of_two_long_running_calls_keeps_workflow_paused[LoopAgent]
  • test_answering_one_parallel_branch_keeps_sequential_agent_paused

All three fail on main: the first answer runs the next agent. They pass with this change.

tests/unittests/agents tests/unittests/runners tests/unittests/test_runners.py
tests/unittests/flows tests/unittests/a2a tests/unittests/plugins
5736 passed, 59 skipped, 4 xfailed

uvx pre-commit run --files <changed files> passes.

Manual End-to-End (E2E) Tests:

The script in the issue, with a scripted model and no API key:

  • before: answering a prints publisher: end_of_agent, root: end_of_agent, and answering b prints nothing
  • after: answering a prints nothing; answering b prints reviewer: both approved, publisher: published, root: end_of_agent

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

… a long-running call is unanswered

In a resumable app, a sub-agent that resumes but still waits on a
long-running call ends its run without yielding the call again (the call
was already yielded and persisted). SequentialAgent and LoopAgent only
detect a pause from the events their sub-agent yields, so they treated the
waiting sub-agent as finished and ran the next one. Answering one of two
long-running calls, or one branch of a ParallelAgent, therefore ran the
rest of the workflow early, ended the invocation, and the later answer was
dropped.

Both agents now also check the current invocation for interrupts that are
still unanswered (index_open_interrupts) before moving to the next
sub-agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant