Repository navigation
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
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
WorkflowLlmAgentnode with two pending tool confirmations does not keep waiting when only one is answered; the next node runs too early #7684Problem:
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).SequentialAgentandLoopAgentonly 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 aParallelAgent, 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,
SequentialAgentandLoopAgentalso check whether the current invocation still has an unanswered interrupt. This reusesindex_open_interrupts, which the router and the runner already use, through a new privateInvocationContext._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
LlmAgentorParallelAgentroot, which already wait correctly.Testing Plan
Unit Tests:
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_pausedAll three fail on main: the first answer runs the next agent. They pass with this change.
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:
aprintspublisher: end_of_agent,root: end_of_agent, and answeringbprints nothingaprints nothing; answeringbprintsreviewer: both approved,publisher: published,root: end_of_agentChecklist