feat(subagent): ✨ Add nested subagent delegation with configurable depth limits#223
Merged
Conversation
…mits Implement multi-level subagent delegation where agents can delegate tasks to other subagents, with safety bounds: - Add `can_delegate` and `max_delegation_depth` fields to custom subagent model, DTO, and persistence layer - Introduce `HelperDelegationContext` for recursive delegation in the orchestrator, with `run_helper_boxed` to break the infinite opaque-type recursion cycle - Enforce global max depth (5) and per-agent max delegation depth - Built-in explore cannot delegate; review can delegate up to depth 3 - Refactor `resolve_custom_subagent_profile` into reusable free functions for pool-based access from both main session and helpers - Support `agent_parallel` delegation from delegating helpers (sequential at deeper levels to bound resource usage) - Add UI controls for delegation settings in agents settings panel - Add i18n strings for both en and zh-CN locales
… cancellation - Extract `validate_delegation_capability` as a standalone pure function shared by the recursive subagent path, improving testability - Add unit tests covering all delegation validation edge cases - Move `MAIN_AGENT_CHILD_DEPTH` to module-level constant for reuse - Cancel in-flight subagents on checkpoint to prevent helpers from continuing mid-LLM-turn after abort signal - Extract `SUBAGENT_COLUMNS_PREFIXED` constant to avoid duplicating qualified column lists in JOIN queries - Add DB CHECK constraint tests for delegation field boundary values - Show delegation capability badges in built-in agent settings UI - Add i18n keys for "No delegation" badge label
When a run was cancelled, in-flight helper agents could remain stuck at `running` in the database because their cleanup futures were dropped before they could write a terminal status. Additionally, concurrent cancellation and normal completion could emit duplicate `SubagentFailed` events. - Add `RegisteredHelper` struct to retain metadata needed for synthetic terminal event synthesis during cancellation - Check `session_abort_signal` before inserting a `running` row to avoid spawning helpers for already-cancelled sessions - Handle the race between DB insert and cancellation registration by proactively marking and emitting `SubagentFailed` - Make `mark_failed` return `bool` and guard against overwriting terminal states, preventing duplicate event emission - Add `mark_interrupted_if_active` for safe proactive interruption during `cancel_run` - Replace native `<select>` with custom `Select` component in agents settings panel for consistent UI
AI Code Review SummaryPR: #223 (feat(subagent): ✨ Add nested subagent delegation with configurable depth limits) Overall AssessmentNo blocking issue was detected in the reviewed diff; keep focused regression testing before merge. Major Findings by SeverityNo major issues identified from the reviewed diff. Actionable Suggestions
Potential Risks
Test Suggestions
File-Level Coverage Notes
Inline Downgraded Items (processed but not inline)
Coverage Status
Uncovered list:
No-patch covered list:
Runtime/Budget
|
| @@ -49,32 +49,22 @@ struct ResolvedHelperDelegate { | |||
| model_role: ResolvedModelRole, | |||
There was a problem hiding this comment.
Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.
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.
Summary
can_delegateandmax_delegation_depthChanges
Backend (Rust)
can_delegate/max_delegation_depthcolumns tocustom_subagentsSubagentProfileextended withcan_delegate()/max_delegation_depth()methodsdelegation_tools_for_helper()injects agent_* tools for subagents when permitted by depthrun_helpertool_executor intercepts agent_* calls and recurses intorun_child_delegationHelperRunRequestcarriesdelegation_depth,model_plan, and custom targetsFrontend (TypeScript/React)
canDelegate/maxDelegationDepthTest Plan
cargo fmt --checkpassescargo test --locked— 800 unit + 283 integration tests passnpm run typecheckpassesnpm run test:unit— 840 Vitest tests pass🤖 Generated with TiyCode