fix(roundtable): 业务链条「本阶段目标」串行链可保存/回显 + 新增「总控提示词」

本阶段目标 bug:每步只有一个智能体(无并行)时,stageGroupsToStagePayload/
stageGroupsToStageGoals 一律折叠为 null(旧设计=线性链),导致目标保存即丢、
无从回显。改为「有并行 或 任一 stage 填了目标」就落显式分层,串行带目标链按
分层 DAG 跑(总控逐阶段按目标派活);BusinessChainPicker 同步:有并行/有目标/
有总控提示都走 dag。

新增「总控提示词」(per-chain,仅 dag 模式生效):写给总控的整体派活指引。
后端 roundtable_chains 加 coordinator_prompt LONGTEXT 列 + migration 20260608_06;
前端编辑器加输入框,注入 buildDagStageLeaderTask 每阶段派活提示。填了总控提示
也强制显式分层(forceExplicit),否则纯线性链里被静默忽略。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-09 13:41:20 +08:00
1 parent 1938c80061
commit 3405795371
13 files changed
+275 -24

No files matched your search

@@ -150,6 +150,8 @@ export default function BusinessChainEditorPage() {
const [publishing, setPublishing] = useState(false);
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
// 写给总控的「编排提示」:告诉总控该怎么派活、做什么(仅分层 DAG 模式注入)。
const [coordinatorPrompt, setCoordinatorPrompt] = useState("");
// 分层编排是唯一数据源;落库时展平为 seats + 折叠为 stages。
const [stageGroups, setStageGroups] = useState<StageGroups>([]);
const [saving, setSaving] = useState(false);
@@ -246,6 +248,7 @@ export default function BusinessChainEditorPage() {
setCurrentChainMine(chain.isMine !== false);
setTitle(chain.title);
setDescription(chain.description ?? "");
setCoordinatorPrompt(chain.coordinatorPrompt ?? "");
setStageGroups(chainToStageGroups(chain));
}, []);
@@ -255,6 +258,7 @@ export default function BusinessChainEditorPage() {
setCurrentChainMine(true);
setTitle("");
setDescription("");
setCoordinatorPrompt("");
setStageGroups([]);
}, []);
@@ -425,16 +429,21 @@ export default function BusinessChainEditorPage() {
}
setSaving(true);
try {
// 展平 + 折叠:seats 用候选池最新 name/description 覆盖快照;stages 全单席位 → null。
// 展平 + 折叠:seats 用候选池最新 name/description 覆盖快照;stages 在「全单席位且无
// 目标」时折叠为 null(线性链),有并行或填了「本阶段目标」时落显式分层。
const flat = stageGroupsToSeats(stageGroups);
const payloadSeats = flat.map((s) => ({
agent_id: s.agent_id,
name: poolById.get(s.agent_id)?.name ?? s.name,
description: poolById.get(s.agent_id)?.description ?? s.description ?? "",
}));
const stages = stageGroupsToStagePayload(stageGroups);
// 每阶段目标,与 stages 同下标对齐(无并行时同样为 null)。
const stageGoals = stageGroupsToStageGoals(stageGroups);
// 总控编排提示:trim 后空串落 null(清空),与后端「空=不注入」一致。
const coordPrompt = coordinatorPrompt.trim() || null;
// 填了「总控编排提示」也强制落显式分层 —— 该提示仅 dag 模式注入,否则纯线性链里被静默忽略。
const forceExplicit = coordPrompt !== null;
const stages = stageGroupsToStagePayload(stageGroups, forceExplicit);
// 每阶段目标,与 stages 同下标对齐、同步折叠(stages 为 null 时这里也是 null)。
const stageGoals = stageGroupsToStageGoals(stageGroups, forceExplicit);
if (currentChainId) {
const updated = await updateChain(currentChainId, {
title: title.trim(),
@@ -442,6 +451,7 @@ export default function BusinessChainEditorPage() {
seats: payloadSeats,
stages,
stageGoals,
coordinatorPrompt: coordPrompt,
});
if (!updated) {
toast.error("链条已不存在,可能被删除");
@@ -459,6 +469,7 @@ export default function BusinessChainEditorPage() {
seats: payloadSeats,
stages,
stageGoals,
coordinatorPrompt: coordPrompt,
});
setCurrentChainId(created.id);
toast.success("已创建业务链条");
@@ -472,6 +483,7 @@ export default function BusinessChainEditorPage() {
}, [
title,
description,
coordinatorPrompt,
stageGroups,
seatCountInvalid,
currentChainId,
@@ -737,6 +749,29 @@ export default function BusinessChainEditorPage() {
/>
</div>
</div>
{/* 总控编排提示:写给总控(协调)智能体的整体派活指引,仅分层 DAG 模式生效。 */}
<div
className={cn(
"mt-4 overflow-hidden border border-border bg-card transition focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30",
R_CTRL,
)}
>
<div className="flex items-center justify-between border-b border-border bg-muted/50 px-4 py-2">
<span className="select-none text-sm font-medium text-muted-foreground">总控提示词</span>
<span className="select-none text-[10px] text-muted-foreground/70">
写给总控:怎么派活、做什么(仅分层研讨生效,可选)
</span>
</div>
<textarea
value={coordinatorPrompt}
onChange={(e) => setCoordinatorPrompt(e.target.value)}
maxLength={4000}
rows={3}
placeholder="例如:你是本次研讨的总控。请严格按阶段顺序派活,每阶段先明确产出目标再分配;要求各席位的交付聚焦本职、显式承接上一阶段结论;最终阶段做综合收口,给出可落地的全案。"
className="w-full resize-y bg-card px-4 py-2.5 text-sm leading-relaxed text-foreground placeholder:text-muted-foreground/60 focus:outline-none"
/>
</div>
</section>
{/* 双栏拖拽编辑器 */}
@@ -1258,8 +1293,8 @@ function StageSection({
)}
/>
{!hasParallelStage && (group.goal?.trim()?.length ?? 0) > 0 && (
<p className="mt-1 text-[10px] text-amber-600 dark:text-amber-400">
提示:当前链条全为串行,目标仅在含并行 Stage 的分层(DAG)研讨中生效。
<p className="mt-1 text-[10px] text-muted-foreground">
提示:填写本阶段目标后,本链条将按阶段顺序由总控逐阶段派活(分层研讨),并把该目标注入总控。
</p>
)}
</div>