Skip to content

feat(cli): support background subagents#9612

Draft
Githubguy132010 wants to merge 18 commits intoKilo-Org:mainfrom
Githubguy132010:feat/background-subagents
Draft

feat(cli): support background subagents#9612
Githubguy132010 wants to merge 18 commits intoKilo-Org:mainfrom
Githubguy132010:feat/background-subagents

Conversation

@Githubguy132010
Copy link
Copy Markdown
Contributor

Context

Enable interactive CLI agents to delegate independent work to background subagents so the main agent can continue while child sessions run. This implements the v1 scope from #9611: model-initiated backgrounding, user notification, and parent-agent notification when the subagent finishes.

Implementation

  • Extended the task tool with background?: boolean while preserving existing foreground behavior by default.
  • Reused the existing child-session subagent model, storing metadata.background alongside metadata.sessionId.
  • Added a background prompt path that immediately returns to the parent, runs the child session in the session prompt runtime, publishes a completion event, and queues a synthetic parent-session message with the result or error.
  • Updated the TUI task renderer to show background task state from child session status and added a completion toast for background subagent close events.
  • Added task-tool test coverage for immediate-return background behavior and updated test stubs for the new prompt op.

Screenshots

before after
Not captured Not captured

How to Test

  • Run bun test test/tool/task.test.ts test/kilocode/tool-task-model.test.ts from packages/opencode/.
  • Run bun run typecheck from packages/opencode/.
  • In the TUI, ask the main agent to start an independent investigation in a background subagent and continue with another task.
  • Confirm the task tool returns immediately with a task_id, the child session continues running, and a toast plus synthetic parent-session update appear when it finishes.

Get in Touch

Open to feedback directly on this PR.

Fixes #9611

Githubguy132010 and others added 18 commits April 28, 2026 12:14
Refactor the `BackgroundSubagentClose` event definition to use `Schema.Struct` and `CloseReasonSchema` for better consistency. Update the SDK type definitions to include `EventSessionBackgroundSubagentClose` and reorganize `EventIndexingStatus` within the `GlobalEvent` and `Event` unions.

Update tests to include the `background` property in session metadata and provide a mock implementation for the `background` method in `TaskPromptOps`.
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.

[FEATURE]: Enable background subagents in the CLI

1 participant