docs: add native multi-agent fleet architecture - #8719
Closed
yiliang114 wants to merge 6 commits into
Closed
Conversation
This was referenced Aug 9, 2026
Collaborator
Author
|
Superseded by #8804, which includes a smaller design aligned with the implemented 中文说明该方案已由 #8804 替代;新 PR 包含一个与已实现 |
Evolves this PR's plan into a concrete target architecture for native herdr-like multi-agent work, traced against the current implementation rather than derived from the earlier proposal. The original plan sequenced everything behind finishing the Agent View PTY stack (#7800-#7803). Tracing the code showed that ordering is inverted: the coordination plane is already cross-process capable, and the semantic layer can ship with no PTY infrastructure at all. Key changes from the previous plan: - Splits the fused 20-method Backend into AgentSession (semantics), AgentRuntime (lifecycle) and AgentSurface (presentation). TeamManager depends only on the first two. - Separates the semantic channel (JSON: status, turn correlation, approvals with call IDs) from the terminal channel (PTY bytes, used only for raw attach). The semantic channel is authoritative, which is the thing screen-scraping multiplexers cannot provide. - Drops the multiplexer ambition. tmux/iTerm2 become optional surfaces. - Records four settled product decisions: transcript-tab inspection for MVP, read-only teammates with leader-routed writer approvals, clean exit stops teammates while crash leaves them reattachable, and one fleet per project behind a single-leader lock. - Resolves the cross-process locking question: tasks.ts and mailbox.ts already pair an in-process mutex with a proper-lockfile cross-process lock, so no upgrade is needed. Phases 1-4 are pure refactors with no user-visible change; six of them land independently. Behaviour changes begin at phase 5. Refs #8718.
added 2 commits
August 10, 2026 15:24
Replaces the eight-phase / six-refactor sequencing with a PR-shaped plan, and grounds it in measurements of the current tree rather than estimates derived from the architecture. The earlier structure front-loaded four pure refactors before anything was exercisable. That is the wrong shape: the first PR should deliver behaviour a reviewer can run. Measured findings that set the sizing: - ~4,360 LOC is reusable unchanged (tasks, mailbox, supervisor store / server / client, terminal-bridge, protocol, history adapter). - ~900 LOC of existing code needs adapting, concentrated in TeamManager (19 call sites) and InProcessBackend (split, six no-ops deleted). - ~2,480 LOC is genuinely new, over half of it the supervisor ops, subprocess entrypoint and remote transport. - `--internal-agent-view-supervisor` is spawned but never handled, so the supervisor process entrypoint is also missing, not just the teammate one. - `ToolCallConfirmationDetails` carries `onConfirm` on all six variants, so approval serialization is real work rather than a type alias. - `createPerAgentConfig` is private inside InProcessBackend; extracting it lets the leader and the teammate subprocess share one agent construction path. Sizing the whole MVP as one PR gives ~3,400 production and ~3,400 test LOC across ~50 files, which is not reviewable here. The plan therefore splits it once, at the process boundary, into 1A (in-process semantics, demonstrable via correlated turns, call-ID approvals and enforced read-only teammates) and 1B (supervised runtime, the full MVP demo). Four PRs total, each with an internal commit sequence. Also records three items that cannot be deferred out of 1B once subprocesses exist: supervisor-driven shutdown, nested fan-out denial, and token sanitisation. Stale generation rejection genuinely can wait, since 1B has neither respawn nor reattach. Refs #8718.
The plan described what to build and in what order, but not how the work is handed between implementation agents. This adds that contract so a stage can be picked up from its issue plus the previous handoff, with no chat history. Structure: reuse #8718 as the umbrella rather than opening a second one, plus four implementation issues at exactly the 1A/1B/2/3 granularity. One issue per PR, so each has a single place to read the goal and a single place to leave a handoff. Stage 3 is deliberately thin and blocked, because its real scope depends on what Stage 2 leaves behind. Issue bodies carry only what is needed to start and link to the stage specs here, rather than duplicating them; the doc stays the single source of truth so the two cannot drift. Handoff packets are posted as a final issue comment before closing, not in the issue body (which stays the spec) and not in the PR description (which is gated against the PR template). Each stage's prerequisites link directly to the previous handoff comment. Adds per-stage specifications covering objective, scope, non-goals, prerequisites, expected files, expected behaviour, acceptance criteria, required tests, security invariants, risks, deferrable work, and explicit may-assume / must-not-assume lists — including the three security invariants that cannot be deferred out of Stage 1B once subprocesses exist. Refs #8718.
This was referenced Aug 10, 2026
Collaborator
Author
|
After re-evaluating this direction against the merged #8804, the broader Fleet architecture is no longer the next step. |
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 this PR does
This PR replaces the earlier native multi-agent collaboration plan on this branch with a concrete target architecture for a herdr-like multi-agent experience built natively in Qwen Code. The document is traced against the current implementation at
002305b90rather than derived from the previous proposal, and every structural claim carries a file reference.The architecture splits today's fused 20-method
Backendinto three contracts:AgentSession(semantics — status, turn correlation, message delivery, approval requests),AgentRuntime(lifecycle — start, reattach, list, stop, kill, answer routing) andAgentSurface(presentation — visibility, focus, raw attach).TeamManagerdepends only on the first two and must never see a surface, a PTY, or a socket. Core defines the contracts; the CLI implements the supervised runtime and injects it.The organising distinction is between a semantic channel (JSON over the supervisor socket, carrying status, turn text, approvals with call IDs and transcript deltas) and a terminal channel (PTY bytes, used only for raw attach). The semantic channel is authoritative. That is precisely what a screen-scraping multiplexer cannot provide, and it is why the semantic fleet layer can ship with no PTY infrastructure at all.
The document also records four settled product decisions, a component-by-component disposition table, an explicit MVP boundary, an eight-phase plan, and six refactors that land before any user-visible change.
Why it's needed
The previous plan on this branch sequenced all coordination work behind finishing the Agent View PTY stack (#7800–#7803). Tracing the code showed that ordering is inverted:
tasks.tsandmailbox.tsare already file-based with a two-tier lock — an in-processasync-mutexwrapping aproper-lockfilecross-process file lock overatomicWriteJSON. The coordination plane was built for multi-process access, so no second task database and no lock upgrade are needed.ensureLeaderInboxPolling/drainLeaderInbox), so teammate → leader messaging needs no new transport for a first release.AgentChatContentalready supports a read-only mode andAgentMessage[]is documented append-only, so remote transcript rendering reuses the existing tab UI.TeamManageruses only five methods ofTeamAgentHandleand four of nineteen event types, so the semantic seam is cheap to extract.Conversely,
InProcessBackend— the only backend wired up — implements six ofBackend's display methods as no-ops. The interface is wrong for its primary implementer, and its optionalgetAgent?()escape hatch is what structurally forces teammates to stay in-process.This PR also corrects the framing of the earlier plan. Herdr is a terminal multiplexer that hosts unmodified agents and infers their state from the screen; Qwen Code is one of the agents it hosts. Rebuilding a multiplexer inside Qwen Code is not the goal. Building the semantic coordination herdr structurally lacks — task ownership, reliable mailbox, turn-level correlation, explicit routable approvals — is.
Reviewer Test Plan
How to verify
002305b90: theBackendconcern table againstpackages/core/src/agents/backends/types.ts, the no-op display methods againstInProcessBackend.ts:338–376, and the four consumed event types againstTeamManager.ts:1486-1510.packages/core/src/agents/team/tasks.ts(lock options,withTaskFileLock) andmailbox.ts(withInboxLock), including the in-source rationale that the file lock guards "writers in other agent processes".packages/cli/src/agent-view/protocol.tsseparates session / process / attach / ownership state and defines ananswercontrol event carryingcallIdand anoutcomeenum, whilesupervisor-process.ts:113-147implements onlystatus,list,subscribeandshutdown.Evidence (Before & After)
N/A — documentation only. No runtime code is changed by this PR.
Tested on
Environment (optional)
N/A — documentation only.
Risk & Scope
Linked Issues
Refs #8718. Re-frames #8804 and the #7800–#7803 stack. Related to #6383.
中文说明
本 PR 做了什么
本 PR 将本分支上原有的原生多 Agent 协作计划,替换为一份在 Qwen Code 内原生构建 herdr 式多 Agent 体验的具体目标架构文档。该文档基于
002305b90的当前实现逐条追踪得出,而不是从此前的提案推导,每一处结构性论断都附有文件引用。该架构把当前融合了 20 个方法的
Backend拆成三个契约:AgentSession(语义层——状态、轮次关联、消息投递、审批请求)、AgentRuntime(生命周期——启动、重连、列举、停止、终止、审批路由)和AgentSurface(展示层——可见性、聚焦、原始 attach)。TeamManager只依赖前两者,且绝不接触 surface、PTY 或 socket。Core 定义契约,CLI 实现受管 runtime 并注入。核心区分在于语义通道(经 supervisor socket 的 JSON,承载状态、轮次文本、带 call ID 的审批和 transcript 增量)与终端通道(PTY 字节,仅用于原始 attach)。语义通道是权威来源。这正是靠读屏推断状态的多路复用器无法提供的能力,也是语义 fleet 层可以完全不依赖 PTY 基础设施就先行落地的原因。
文档同时记录了四项已确定的产品决策、逐组件的处置表、明确的 MVP 边界、八个阶段的计划,以及六项在任何用户可见变更之前即可独立合入的重构。
为什么需要
本分支此前的计划把所有协作工作排在完成 Agent View PTY 堆栈(#7800–#7803)之后。追踪代码后发现这个顺序是反的:
tasks.ts与mailbox.ts已经是基于文件的,并采用两级锁——进程内async-mutex包裹proper-lockfile跨进程文件锁,底层是atomicWriteJSON。协作平面本就是为多进程访问设计的,因此既不需要第二套任务数据库,也不需要升级锁。ensureLeaderInboxPolling/drainLeaderInbox),所以队友到 leader 的消息在首个版本中无需任何新传输层。AgentChatContent已支持只读模式,且AgentMessage[]文档标明为仅追加,因此远程 transcript 渲染可直接复用现有标签页 UI。TeamManager只用到TeamAgentHandle的五个方法和十九种事件中的四种,因此语义接缝的抽取成本很低。反过来,唯一真正接入的 backend
InProcessBackend,把Backend的六个展示方法实现成空操作。这个接口对它的主要实现者来说是错的,而其可选的getAgent?()逃生口正是从结构上迫使队友只能留在进程内的原因。本 PR 也修正了此前计划的定位。Herdr 是承载未经修改的 Agent 的终端多路复用器,并通过读屏推断其状态;Qwen Code 是它承载的 Agent 之一。在 Qwen Code 内重建一个多路复用器并不是目标;构建 herdr 结构上缺失的语义协作——任务归属、可靠 mailbox、轮次级关联、显式可路由审批——才是。
Reviewer 测试计划
如何验证
002305b90的代码核对文档的结构性论断:Backend职责表对应packages/core/src/agents/backends/types.ts,空操作展示方法对应InProcessBackend.ts:338–376,四种被消费的事件类型对应TeamManager.ts:1486-1510。packages/core/src/agents/team/tasks.ts(锁选项、withTaskFileLock)与mailbox.ts(withInboxLock),包括源码中「文件锁用于防护其他 agent 进程的写入者」这一说明。packages/cli/src/agent-view/protocol.ts区分 session / process / attach / ownership 四类状态,并定义了携带callId与outcome枚举的answer控制事件;而supervisor-process.ts:113-147只实现了status、list、subscribe和shutdown。证据(修改前与修改后)
N/A——仅文档变更,本 PR 不改动任何运行时代码。
测试平台
环境(可选)
N/A——仅文档变更。
风险与范围
关联 Issue
参考 #8718。重新定位 #8804 与 #7800–#7803 堆栈。另关联 #6383。