feat(subagent): run background sub-agents for focused task and return results #5801
+2,083
−6
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.
Add a subagent tool (experiment-gated) that runs a focused sub-task in the background. Parent task stays in view; result is returned as the tool result. Supports explore (read-only) and general modes. Inspired by Cursors's Task tool.
Context
Big projects require a lot of intermediate research, web fetching and code explorations. It's filled chat's context with unnecessary information. With this PR the main task stays in view while the model runs focused sub-tasks (research, exploration, or multi-step work) in the background with its own context. The subagent’s result is returned as a single tool result, so the main chat isn’t filled with the sub-task’s intermediate steps and tool calls. As a result, reducing context pollution and keeping the main thread readable.
Implementation
SubagentToolposts "running", provider creates a child task and runs its loop. Child has restricted tools (explore = read-only +attempt_completion; no nested subagent or interactive tools). Child’sattempt_completionresolves the parent’s promise with the result; parent continues.TaskgetssubagentType,needUpdateHistory,backgroundCompletionResolve, progress callback, andrunBackgroundSubagentLoop. Provider implementsrunSubagentInBackground; cancel only stops the subagent and returns a cancellation message.ChatRow+ i18n).Screenshots
Example:

Before:

After:

Context pollution is reduced.
How to Test
src/index.tsand summarize what each does”.subagenttool: the main task should remain the active/visible task (no switch to a new task); you should see a chat row like “Running subagent: <description>”. When the subagent finishes, “Subagent completed” and the main task should receive the tool result and continue (e.g. next turn using that result).Get in Touch
Email me or telegram: @kelsnewman