Preface¶
When using subagent in DeepSeek Harness (cordis) with run_in_background: true, the call immediately returns a subagentId, and the subagent continues running in the background. Final results are typically delivered via asynchronous settlement notifications. If the next step must depend on the subagent’s stop reason or closing message, there was previously no “blocking wait” mechanism: run_in_background: false only blocks at startup; send_message returns immediately after sending; list_agents is explicitly not designed for polling. Below is an introduction to the workflow plugin dsh-wait-subagent, published by maintainer john-walks-slow. It registers a wait_subagent tool that, under an event-driven, zero-polling approach, blocks until the specified background continuable subagent settles, and returns stop_reason and closing_message within the same call.
What Is This¶
dsh-wait-subagent is a DeepSeek Harness plugin that registers a model-facing Agent tool wait_subagent on each root agent. It does not modify the web client, provides no UI, and has no additional configuration options; after installation, it automatically mounts the loader entry via a bundled cordis.patch.yml.
- Repository: john-walks-slow/dsh-wait-subagent
- Community Directory: SkillHub Plugin Page
- License: MIT (package.json version 1.0.0)
- Runtime Requirements: Node ≥ 22.5; depends on
@deepseek-ai/dsh-tools0.1.2-rc.1 (aligned with the locked version of dsh 0.1.2-rc.1)
The DSH ecosystem emphasizes “everything is a plugin”; community directories such as SkillHub are independent sites and have no official affiliation with DeepSeek / 幻方. The plugin runs under the permissions of the current dsh process. It is recommended to review the source code and license before installation.
Core Features¶
wait_subagent Tool¶
Tool signature (from the README):
wait_subagent(subagent_id: string, timeout_ms?: integer)
→ { status: "settled" | "timeout" | "cancelled",
subagent_id: string,
stop_reason?: "completed" | "aborted" | "error" | "max-tokens" | "refusal" | "unknown",
closing_message?: string }
Key behaviors:
- Membership validation: Validates
subagent_idviactx.subagents.listChildren(parent.id)(the same projection aslist_agents); unknown IDs or child IDs not belonging to this agent will raise an error immediately, prompting the use of IDs returned by background dispatch (refer tolist_agents). - Event waiting: Listens for the
subagent/endlifecycle event (triggered when the child agent’s activation is disposed), subscribes on the plugin context to avoid race conditions with registry updates. - Optional timeout: Passing
timeout_msyieldsstatus: "timeout"upon expiry; omitting it waits indefinitely (documentation recommends usually omitting it; if setting a timeout, prefer a large value rather than simulating polling with multiple short waits). - Cancellation: Respects the caller’s
AbortSignal, returningstatus: "cancelled". - Blocking semantics: During waiting, it occupies the caller agent’s tool lane; this is by design. The wait itself is event-driven, so CPU overhead during blocking is negligible. No side effects such as network access, external services, or file writes.
Installation and Activation¶
After installation, a DSH instance restart is required; cordis.patch.yml will automatically register the loader.
Install from the plugin name (web profile):
dsh plugin --profile web add dsh-wait-subagent
Or install from GitHub source (pure ESM JavaScript, no build step, no pnpm build-script approval needed):
dsh plugin --profile web add github:john-walks-slow/dsh-wait-subagent
Typical Usage¶
First launch the subagent in the background, then call wait_subagent with the returned subagentId:
wait_subagent({ subagent_id: "session-9f2c47ab-83d1-4e06-b5a9-1c7f2d84e0b3" })
The call blocks while the subagent is running; after settlement, the tool returns JSON, and the model-visible text is similar to:
Subagent session-9f2c47ab-83d1-4e06-b5a9-1c7f2d84e0b3 settled: completed
Spec written to docs/plan.md; 3 files changed, ready for review.
Corresponding structured result example:
{
"status": "settled",
"subagent_id": "session-9f2c47ab-83d1-4e06-b5a9-1c7f2d84e0b3",
"stop_reason": "completed",
"closing_message": "Spec written to docs/plan.md; 3 files changed, ready for review."
}
Other common outcomes:
| Situation | Result |
|---|---|
| Subagent already settled before the call | status: "settled", stop_reason may be unknown; indicates it had already settled earlier, and the closing message may have been delivered separately via a settlement notification |
timeout_ms expires |
status: "timeout"; the subagent may still be running |
| Caller’s AbortSignal triggers | status: "cancelled" |
| Unknown ID or ID not belonging to this child agent | Rejected with an error |
Use case: When your next action depends on the subagent’s result, use wait_subagent to actively wait, rather than guessing or polling list_agents.
Use Cases and Caveats¶
Suitable for: Orchestrating workflows where “background tasks explore / write specs / modify files + main conversation waits for results before deciding”; scenarios where stop_reason and closing_message need to be obtained within the same tool call.
Caveats:
- Do not parallelize
wait_subagentandinterrupt_agentin the same step. Althoughwait_subagentis concurrency-safe,interrupt_agentrequires exclusive access to the tool lane and must be queued after any in-progress calls; when parallelized in the same step, the wait often times out first before the interrupt takes effect. You should callinterrupt_agentfirst, then callwait_subagentin the next step (an interrupted subagent will settle relatively quickly). - Infinite waiting will occupy the tool lane for an extended period; this is inherent to the feature. Set
timeout_mswhen an upper bound is needed. - The community directory page shows zero stars, which does not mean the functionality is unverified; refer to the README and source code.
Summary¶
dsh-wait-subagent fills the gap between the “fire-and-forget” nature of run_in_background and asynchronous settlement notifications: an event-driven wait_subagent that allows the main agent to block and wait when dependent on subagent results, and read the closing information in one go.
- Directory Page: https://www.skillhub.cn/plugins/john-walks-slow/dsh-wait-subagent
- GitHub: https://github.com/john-walks-slow/dsh-wait-subagent