feat(chat): add async non-blocking subagent delegation#3752
Open
feat(chat): add async non-blocking subagent delegation#3752
Conversation
- Add completion channel for real-time subagent finish notifications - Support concurrent tasks per agent (remove single-task restriction) - Notify user inline when background agents complete - Queue completed agent summaries as context for next prompt - Use tokio::select! to monitor completions alongside response stream Ref: aws/q-command-line-discussions#318
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.
Problem
When the CLI delegates work to a subagent, the main conversation is blocked until the subagent completes. For longer-running tasks (30-60+ seconds), the user is stuck waiting and can't interact with the agent.
Solution
Add async, non-blocking subagent delegation so the user regains control immediately after launching a background agent.
Changes
tokio::sync::mpsc::unbounded):ChatSessionholds a sender/receiver pair. The sender is cloned into each spawned agent process; the receiver is polled during the response stream loop.task_idand its own JSON file ({agent}_{task_id}.json).pending_additional_contextand included in the next user prompt.tokio::select!: The response stream loop now usestokio::select!to concurrently monitor subagent completions alongside the model response stream.Files changed
crates/chat-cli/src/cli/chat/mod.rsChatSession, usetokio::select!in response loopcrates/chat-cli/src/cli/chat/tools/delegate.rscrates/chat-cli/src/cli/chat/tools/mod.rscompletion_txthroughTool::invokeTesting
cargo test— 326 passed, 0 failed, 13 ignored (CI-only).References
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.