Skip to content

feat(chat): add async non-blocking subagent delegation#3752

Open
ajsivsan1 wants to merge 1 commit intoaws:mainfrom
ajsivsan1:feat/async-subagent-delegation
Open

feat(chat): add async non-blocking subagent delegation#3752
ajsivsan1 wants to merge 1 commit intoaws:mainfrom
ajsivsan1:feat/async-subagent-delegation

Conversation

@ajsivsan1
Copy link
Copy Markdown

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

  • Completion channel (tokio::sync::mpsc::unbounded): ChatSession holds a sender/receiver pair. The sender is cloned into each spawned agent process; the receiver is polled during the response stream loop.
  • Concurrent tasks per agent: Removed the single-task-per-agent restriction. Each execution gets a unique task_id and its own JSON file ({agent}_{task_id}.json).
  • Inline notifications: When a subagent finishes, the user sees an inline status message on stderr without disrupting the model stream.
  • Context injection: Completed agent summaries are queued as pending_additional_context and included in the next user prompt.
  • tokio::select!: The response stream loop now uses tokio::select! to concurrently monitor subagent completions alongside the model response stream.

Files changed

File Summary
crates/chat-cli/src/cli/chat/mod.rs Add completion channel to ChatSession, use tokio::select! in response loop
crates/chat-cli/src/cli/chat/tools/delegate.rs Concurrent task support, completion channel plumbing, updated file storage
crates/chat-cli/src/cli/chat/tools/mod.rs Thread completion_tx through Tool::invoke

Testing

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.

- 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
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.

1 participant