fix: scope HITL waiters per agent tool call#22088
Open
fengjikui wants to merge 1 commit into
Open
Conversation
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.
Fixes #22070.
Summary
Parallel
FunctionAgenttool calls can each enter the documented HITL pattern viactx.wait_for_event(...). When those tool functions do not pass an explicitwaiter_id, the workflow runtime derives the same waiter key for every parallel branch, so the later waiter overwrites the earlier one and only oneInputRequiredEventis emitted.This PR scopes the default waiter id used by agent tool contexts to the current tool call id. Explicit
waiter_idvalues are preserved, so callers that intentionally coordinate multiple waits under a shared id can still do so.Changes
Contextbehavior but fills a missingwaiter_idwithagent_tool_call:<tool_id>.FunctionToolcalls from bothBaseWorkflowAgentandAgentWorkflow.InputRequiredEvents and the workflow completes after both responses.Validation
mainwith the issue PoC: only1of3InputRequiredEvents was emitted and the workflow timed out.uv run --python 3.12 --frozen pytest tests/agent/workflow/test_multi_agent_workflow.py::test_parallel_hitl_tool_calls_have_scoped_waiters tests/agent/workflow/test_multi_agent_workflow.py::test_agent_with_hitl tests/agent/workflow/test_multi_agent_workflow.py::test_workflow_pickle_serialize_and_resume -quv run --python 3.12 --frozen pytest tests/agent/workflow/test_function_call.py::test_call_tool_with_exception tests/agent/workflow/test_function_call.py -quv run --python 3.12 --frozen ruff check llama_index/core/agent/workflow/base_agent.py llama_index/core/agent/workflow/multi_agent_workflow.py tests/agent/workflow/test_multi_agent_workflow.pyuv run --python 3.12 --frozen ruff format llama_index/core/agent/workflow/base_agent.py llama_index/core/agent/workflow/multi_agent_workflow.py tests/agent/workflow/test_multi_agent_workflow.py --checkAI assistance was used to inspect the code path and draft the patch; I manually reviewed the diff and validated it with the checks above.