feat(roundtable): 圆桌 Step2 分层 DAG 编排(并行/沙箱双模式 + 流程图 + 按需取全文)
数据模型/编辑器:链条加 stages 分层(前后端 + alembic 20260607_03);BusinessChainEditorPage 竖列 Stage 编辑 + 底部只读流程图预览;lib/dag-types + chain-stages 纯逻辑(含单测)。 调度(runDagOrchestration,方案 A 总控驱动):每个 stage 由总控经 agent_orchestration 派活给计划钉死的席位,批内 Promise.all 并行、批间 barrier 串行;末尾交回 runOrchestration 收口。抑制 leader 预广播 + 干净席位任务,根治『席位模仿派活』。 执行子模式:快速(双列·产物走正文·禁写文件 seat_parallel)/ 沙箱(单列·写 .md·沙箱跟随预览 seat);统一禁 bash(防 .py 脚本),提示词禁 .py。 显示:头像条 + 两列/单列 + ref 全量累积 + 节流 flush(仅选中渲染);DAG 流程图弹窗(按 stage 分列,节点随执行点亮,只到共识);沙箱跟随当前席位(防错位 + 修第一个席位自动开沙箱)。 按需取全文:新增 harness 只读工具 read_peer_delivery(从 run context 取网关注入的前序席位完整交付),席位默认看摘要、需要时取全文。 修:宽表溢出、并行自动下滑、data-lov-id Fragment 警告等。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5164fd362c
commit
7b8c11852e
26 files changed
+3719
-216
No files matched your search
@@ -46,6 +46,9 @@ class ChainResponse(BaseModel):
|
||||
title: str = ""
|
||||
description: str | None = None
|
||||
seats: list[ChainSeatSchema] = []
|
||||
# Optional layered orchestration: list of stages, each a list of agent_ids
|
||||
# run in parallel (stages run serially). None/absent = linear chain.
|
||||
stages: list[list[str]] | None = None
|
||||
created_at: datetime | str | None = None
|
||||
updated_at: datetime | str | None = None
|
||||
|
||||
@@ -61,6 +64,7 @@ class ChainCreateRequest(BaseModel):
|
||||
title: str = Field(default="", max_length=512)
|
||||
description: str | None = Field(default=None, max_length=2048)
|
||||
seats: list[ChainSeatSchema] = []
|
||||
stages: list[list[str]] | None = None
|
||||
|
||||
|
||||
class ChainUpdateRequest(BaseModel):
|
||||
@@ -68,6 +72,7 @@ class ChainUpdateRequest(BaseModel):
|
||||
title: str | None = Field(default=None, max_length=512)
|
||||
description: str | None = Field(default=None, max_length=2048)
|
||||
seats: list[ChainSeatSchema] | None = None
|
||||
stages: list[list[str]] | None = None
|
||||
|
||||
|
||||
# ── helpers ──────────────────────────────────────────────────────────────
|
||||
@@ -101,6 +106,45 @@ def _validate_seats(seats: list[ChainSeatSchema]) -> None:
|
||||
seen.add(s.agent_id)
|
||||
|
||||
|
||||
def _validate_stages(seats: list[ChainSeatSchema], stages: list[list[str]] | None) -> None:
|
||||
"""Validate the optional layering. ``stages`` must partition the seats.
|
||||
|
||||
Rules (None = linear chain, always valid):
|
||||
- at least one stage, no empty stage;
|
||||
- every agent_id in a stage must be one of the chain's seats;
|
||||
- no agent_id appears twice (within or across stages);
|
||||
- every seat must appear in exactly one stage (full coverage), so the
|
||||
stored layering and the seat list never drift apart.
|
||||
"""
|
||||
if stages is None:
|
||||
return
|
||||
if len(stages) == 0:
|
||||
raise HTTPException(status_code=400, detail="编排分层不能为空(至少一个阶段)")
|
||||
seat_ids = {s.agent_id for s in seats}
|
||||
seen: set[str] = set()
|
||||
for idx, stage in enumerate(stages):
|
||||
if not stage:
|
||||
raise HTTPException(status_code=400, detail=f"第 {idx + 1} 阶段为空,请删除或放入席位")
|
||||
for agent_id in stage:
|
||||
if agent_id not in seat_ids:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"编排分层包含不在席位列表中的智能体: {agent_id}",
|
||||
)
|
||||
if agent_id in seen:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"智能体 {agent_id} 在编排分层中重复出现,每个席位只能跑一次",
|
||||
)
|
||||
seen.add(agent_id)
|
||||
if seen != seat_ids:
|
||||
missing = seat_ids - seen
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"编排分层未覆盖全部席位,缺少: {', '.join(sorted(missing))}",
|
||||
)
|
||||
|
||||
|
||||
# ── routes ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -115,6 +159,7 @@ async def list_chains(request: Request) -> ChainListResponse:
|
||||
@router.post("", response_model=ChainResponse, status_code=201)
|
||||
async def create_chain(request: Request, body: ChainCreateRequest) -> ChainResponse:
|
||||
_validate_seats(body.seats)
|
||||
_validate_stages(body.seats, body.stages)
|
||||
store = _get_store(request)
|
||||
user_id = _current_user_id(request)
|
||||
row = await store.create_chain(
|
||||
@@ -124,6 +169,7 @@ async def create_chain(request: Request, body: ChainCreateRequest) -> ChainRespo
|
||||
"title": body.title.strip(),
|
||||
"description": body.description,
|
||||
"seats": [s.model_dump() for s in body.seats],
|
||||
"stages": body.stages,
|
||||
},
|
||||
)
|
||||
return ChainResponse(**row)
|
||||
@@ -143,6 +189,12 @@ async def get_chain(request: Request, chain_id: str) -> ChainResponse:
|
||||
async def update_chain(request: Request, chain_id: str, body: ChainUpdateRequest) -> ChainResponse:
|
||||
if body.seats is not None:
|
||||
_validate_seats(body.seats)
|
||||
# A non-null stages layering can only be validated against seats; the editor
|
||||
# always saves both together. Reject a layering update that omits seats.
|
||||
if body.stages is not None:
|
||||
if body.seats is None:
|
||||
raise HTTPException(status_code=400, detail="更新编排分层时必须同时提交席位列表")
|
||||
_validate_stages(body.seats, body.stages)
|
||||
store = _get_store(request)
|
||||
user_id = _current_user_id(request)
|
||||
# Distinguish "omitted" from "explicitly sent"; only forward provided fields.
|
||||
|
||||
Reference in new issue
Block a user