Repository navigation
[EPIC-Y][LOU-Y4] Background sub-agents: task background:true with agent_status, agent_await and agent_cancel - #91
Merged
Conversation
…nt_status, agent_await and agent_cancel
The task tool takes background: true, which starts the sub-agent and
returns { taskId, status: 'running', agent } at once. Agents with
subagents also get agent_status, agent_await and agent_cancel.
withSubagentOptions(subagents, { maxConcurrent }) bounds running
background children per lead run (default 3); the rest queue. Background
children inherit the lead run's runtime and depth budget, and aborting the
lead cancels them. A child that pauses for approval reports
awaiting-approval with its approvalId.
Cancelling or awaiting background children when the lead run finishes
needs a run-end hook in AgentExecutor (out of scope here): left to
LOU-Y4.2 and documented.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR
7 tasks done
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.
What
taskgainsbackground?: boolean(default false). Withtrueit starts the sub-agent and returns{ taskId, status: 'running', agent }right away. If the concurrency limit is full it returnsstatus: 'queued'instead.subagentsis set, three tools are registered alongsidetask:agent_status({ taskId? })returns{ tasks: [{ taskId, agent, status, elapsedMs, approvalId?, toolName?, error? }] }.statusis one ofqueued | running | done | failed | cancelled | awaiting-approval.agent_await({ taskId | taskIds, timeoutMs? })returns the same result text the synchronoustaskpath returns (inresult), or anerror. A task still running when the timeout passes reportsstatus: 'timeout'.agent_cancel({ taskId }).withSubagentOptions(subagents, { maxConcurrent })sets the per-lead-run concurrency (default 3, validated). It is a new export insrc/subagentsand the package root. Calls beyond the limit queue and start as slots free.runSubagent), so they inherit hooks, tracing,onEvent/stream, usage roll-up and the depth budget. Each child gets its ownAbortController, bound to the same parent tool-call scope. Aborting the lead's signal cancels every queued or running background child.awaiting-approval, with the child'sapprovalIdandtoolName.agent_awaitreturns that state immediately.agent_status,agent_awaitoragent_cancelnow conflicts withsubagents, the same way a tool namedtaskalready did.agent_awaitbefore it finishes.Why
Parity gap with eve (background tasks) and open-harness (background sub-agents with
agent_await/status/cancelandmaxConcurrent). Todaytaskblocks the lead until the child finishes.Acceptance criteria
tasktakesbackground?: boolean. Withtrueit returns{ taskId, status: 'running', agent }immediately. The child inherits the parent runtime, and aborting the parent cancels background children.agent_status,agent_await(result summary ortimeout) andagent_cancelare registered alongsidetask.maxConcurrent(default 3) bounds running background children. Further calls getqueuedand start as slots free.maxSubagentDepthstill applies.awaiting-approvalinagent_status. It cannot be resumed in this PR, soagent_awaitreturnsawaiting-approvalwith theapprovalId(fallback described in the ticket; limitation documented).mockModelcover: results flow back throughagent_status/agent_await,maxConcurrentqueues,agent_awaittimeout, cancel, parent abort cancels children, approval pause, depth limit, unknown ids and bad options.Deferred to LOU-Y4.2 (needs an executor change, which this ticket does not allow): when the lead run finishes, still-running background children are not yet cancelled, awaited (
awaitBackgroundOnFinish), or reported (result.backgroundTasks/subagent.cancelled).withSubagents()and the tools never see the run end:AgentExecutor.withExtensionspasses only(agent, toolRegistry, subagents, depth), andfinishRun/abortRun/savePausecall nothing insrc/subagentsor in the allowedsrc/executionfiles. Proposed Y4.2 change, about 10 lines in AgentExecutor: letwithSubagentsreturn anonRunEnd(result), call it in afinallyaroundrunAgentLoop, and have it cancel children (or await them whenawaitBackgroundOnFinishis set) and attachbackgroundTasksto the result. Until then, the docs tell users to have the leadagent_awaitits tasks or to abort the signal they passed.How verified
npx tsc --noEmit: no errorsnpm run lint: 0 errors, 420 warnings (same count as main)npm run test:types: no type errorsnpx vitest run(after build): 147 files passed; 2104 tests passed, 3 skippednpm run build && npm run build --workspace=packages/create-loushy-agent: both succeednpm run docs:verify-snippets -- --skip-build: all 103 snippets type-check, 6 also run cleanlynpm run docs:llms:check: up to datenpm run test:coverage: 2104 passed, 3 skipped. The first run had one failing test that I could not identify. The next 3 full runs passed, and the sub-agent suites passed 5 times in a row.npm run fallow: exit 0, "No issues found" (dead code). The one reported clone group is the existing AnthropicProvider/OpenAIProvider duplication, unchanged by this PR.Scope: only
src/subagents/*, docs/sub-agents.md, CHANGELOG.md and llms-full.txt. No changes tosrc/execution/*, AgentExecutor.ts, createAgent.ts or package.json.🤖 Generated with Claude Code
https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR
Generated by Claude Code