π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ feat(goal): let the distill turn send probes that fall short of the plan back (#21207)
Arvin Xu62e9dc22efc6
diff --git a/apps/cli/src/commands/goal/index.ts b/apps/cli/src/commands/goal/index.tsindex b10fd4433dc..8e97e07f7ec 100644--- a/apps/cli/src/commands/goal/index.ts+++ b/apps/cli/src/commands/goal/index.ts@@ -494,7 +494,7 @@ export function registerGoalCommand(program: Command) {).requiredOption('--file <path>',- 'JSON plan: action tasks/wait/verify/retry/escalate/release/revise_plan, reason and action fields; a tasks plan may add "rollout" to run its units as a batch; release answers a batch release handed to this turn; revise_plan answers a plan the owner sent back, with "recipe" the full revised plan and optional "rerun" the experiment unit ids to run again on it (omitted: all), and answers settled probes to distill with "recipe" alone',+ 'JSON plan: action tasks/wait/verify/retry/escalate/release/revise_plan, reason and action fields; a tasks plan may add "rollout" to run its units as a batch; release answers a batch release handed to this turn; revise_plan answers a plan the owner sent back, with "recipe" the full revised plan and optional "rerun" the experiment unit ids to run again on it (omitted: all), and answers settled probes to distill with "recipe" and optional "rerun" the probe ids that fall short of it (omitted: none)',).requiredOption('--token <token>', 'Current server-issued planning turn token').option('--operation <id>', 'Defaults to LOBEHUB_OPERATION_ID')diff --git a/apps/server/src/services/goal/manager.README.md b/apps/server/src/services/goal/manager.README.mdindex 40ad88f16d5..1ce12d6bf17 100644--- a/apps/server/src/services/goal/manager.README.md+++ b/apps/server/src/services/goal/manager.README.md@@ -84,7 +84,10 @@ commands. It submits a JSON file through `lh goal plan <goal-id> --token <turn>what the probes ran into and answers `revise_plan` with the full plan, whichbecomes the plan skill's next version, and the same advance judges the gatestraight from that step, so the owner reviews the probes against the plan- they taught. Without a+ they taught. A probe whose delivery falls short of that plan (a skipped step,+ failing CI, open review) the Agent names in `rerun`: it re-opens in place on+ the plan, continuing its delivery, and the round is distilled again once the+ re-runs settle, before the gate judges it. Without aturn to spend, the gate judges them on the plan as written.- `verify`: reason; requests the ordinary independent final acceptance Task.This does not mark the Goal achieved.diff --git a/apps/server/src/services/goal/manager/submit.ts b/apps/server/src/services/goal/manager/submit.tsindex 279120e6b15..e8542d200be 100644--- a/apps/server/src/services/goal/manager/submit.ts+++ b/apps/server/src/services/goal/manager/submit.ts@@ -270,7 +270,8 @@ export const submitPlan = async (});} else if (plan.action === 'revise_plan' && state.problemKind === 'rollout_distill') {// The plan distilled from the settled probes lands with the plan; the next- // advance writes it as the plan skill's next version, then judges the gate.+ // advance writes it as the plan skill's next version, then judges the gate+ // β or first re-runs the probes the Agent found falling short of it.const rollout = goal.config?.rolloutState;if (rollout?.phase !== 'plan_distill')throw new TRPCError({@@ -279,7 +280,11 @@ export const submitPlan = async (});await model.updateRolloutState(goalId, {...rollout,- pendingDistill: { reason: plan.reason, recipe: plan.recipe },+ pendingDistill: {+ reason: plan.reason,+ recipe: plan.recipe,+ ...(plan.rerun?.length && { rerun: plan.rerun }),+ },});} else if (plan.action === 'revise_plan') {// The rewrite lands with the plan; the next advance re-runs the units it names.diff --git a/apps/server/src/services/goal/probeDistill.test.ts b/apps/server/src/services/goal/probeDistill.test.tsindex 1979a4768ad..c17ea09a0b8 100644--- a/apps/server/src/services/goal/probeDistill.test.ts+++ b/apps/server/src/services/goal/probeDistill.test.ts@@ -149,6 +149,58 @@ describe('distilling the plan from settled probes', () => {expect(round.metadata!.releaseGate!.plan.content).toContain('Pitfalls the probes hit');});+ it('re-runs the probes the main Agent sends back, then distills the round again', async () => {+ const { id, probeIds } = await probesSettled();+ const [shortProbe, metProbe] = probeIds;+ await service().tick(id);+ const first = await distillTurn(db, userId, id);+ await manager().submit(id, first.state.token, first.op.id, {+ action: 'revise_plan',+ reason: 'Device list stopped at an open PR: CI fails and a P1 review finding is unresolved',+ recipe: distilled,+ rerun: [shortProbe],+ });+ await ops().recordCompletion(first.op.id, { status: 'done' });+ await service().tick(id);+ await service().tick(id);++ // The plan lands, but the gate does not judge the probe sent back.+ const config = (await model().findById(id))!.config!;+ let state = config.rolloutState!;+ expect(state.phase).toBe('probe');+ expect(state.pendingDistill).toBeUndefined();+ expect(state.planVersions).toEqual({ '1': 2 });+ expect(config.rollout!.spec!.recipeOutline).toBe(distilled);+ expect(await pendingRelease(service(), id)).toBeUndefined();++ // The re-run takes the sent-back probe's place, continuing it; the other stays.+ const rerunId = state.probeNodeIds[0];+ expect(rerunId).not.toBe(shortProbe);+ expect(state.probeNodeIds[1]).toBe(metProbe);+ const graph = await service().graph(id);+ const rerun = graph.nodes.find((node) => node.id === rerunId)!;+ expect(rerun.title).toBe('Device list');+ expect(rerun.description).toContain('Persist device:listDevices');+ expect(rerun.description).toContain('a P1 review finding is unresolved');+ expect(+ graph.edges.some(+ (edge) =>+ edge.kind === 'derived_from' &&+ edge.sourceNodeId === rerunId &&+ edge.targetNodeId === shortProbe,+ ),+ ).toBe(true);++ // Once the re-run settles, the round goes back to the main Agent before the gate.+ await db.update(goalNodes).set({ status: 'resolved' }).where(eq(goalNodes.id, rerunId));+ await answerDistill(service(), db, userId, id, distilled);++ state = (await model().findById(id))!.config!.rolloutState!;+ expect(state.phase).toBe('release_review');+ expect(state.probeNodeIds).toEqual([rerunId, metProbe]);+ expect(await pendingRelease(service(), id)).toBeDefined();+ });+it('distills a round with a broken probe too, before the gate breaks on it', async () => {const { id } = await probesSettled('rejected');diff --git a/apps/server/src/services/goal/probeDistill.ts b/apps/server/src/services/goal/probeDistill.tsindex 5a5b1d4d5d7..a7f6cab7fa5 100644--- a/apps/server/src/services/goal/probeDistill.ts+++ b/apps/server/src/services/goal/probeDistill.ts@@ -9,6 +9,7 @@ import type { LobeChatDatabase } from '@/database/type';import { BatchPlanSkillService } from './batchPlanSkill';import { GoalManagerService } from './manager';import { activeStatuses } from './manager/turnState';+import { deliveredUnits, pickRerunUnits, reopenRoundUnits, rerunUnitNote } from './rolloutBatch';const log = debug('lobe-server:goal-rollout');@@ -57,7 +58,10 @@ const planVersionOf = (state: GoalRolloutState) =>* The step between a round's settled probes and its gate: the main Agent reads* what the probes ran into and rewrites the plan skill from it, so the owner* reviews the probes against the plan they taught and every later wave runs on- * it. The probes are not run again. A goal whose main Agent cannot take the+ * it. A probe whose delivery falls short of that plan β it skipped a step the+ * plan calls done, its review or CI is still open β the main Agent sends back:+ * it runs again on the plan, continuing its delivery, and the round is+ * distilled again once it settles, before the gate judges it. A goal whose main Agent cannot take the* turn (no turns or budget left) keeps its plan as written and goes on to the* gate rather than stopping on it.*/@@ -70,18 +74,16 @@ export class GoalProbeDistill {/*** Drive the distill step. Returns the tick result while it waits on the main- * Agent; `undefined` once the plan is ready, and the caller judges the gate in- * the same advance β straight from `plan_distill`, never back through `probe`.+ * Agent, or once it sent probes back to run again; `undefined` once the plan+ * is ready, and the caller judges the gate in the same advance β straight+ * from `plan_distill`, never back through `probe`.*/route = async (snapshot: GoalGraphSnapshot): Promise<GoalTickResult | undefined> => {let graph = snapshot;const goalId = graph.goal.id;const state = graph.goal.config!.rolloutState!;if (probesDistilled(state)) return undefined;- if (state.phase === 'plan_distill' && state.pendingDistill) {- await this.apply(graph);- return undefined;- }+ if (state.phase === 'plan_distill' && state.pendingDistill) return this.apply(graph);if (state.phase !== 'plan_distill') {const entered = await this.db.transaction(async (tx) => {@@ -154,21 +156,24 @@ export class GoalProbeDistill {/*** Land the plan the main Agent distilled: the plan skill's next version, the* policy's outline every later wave is briefed from, and the Template. The- * round stays in `plan_distill`, marked distilled, for the gate to judge.+ * round stays in `plan_distill`, marked distilled, for the gate to judge β+ * unless the rewrite sends probes back. Those re-open in place on the new+ * plan and the round returns to `probe`; the re-runs form a new probe set, so+ * the round is distilled again when they settle.** The rewrite is claimed under the goal row's lock before the skill is* revised, so overlapping advances that read the same pending rewrite write* one version, not one each.*/- private apply = async (graph: GoalGraphSnapshot) => {+ private apply = async (graph: GoalGraphSnapshot): Promise<GoalTickResult | undefined> => {const goalId = graph.goal.id;const policy = graph.goal.config?.rollout;- await this.db.transaction(async (tx) => {+ const reopened = await this.db.transaction(async (tx) => {const goalModel = new GoalModel(tx, this.userId, this.workspaceId);const current = (await goalModel.lockById(goalId))?.config?.rolloutState;- // Another advance landed it first; the gate is next either way.- if (current?.phase !== 'plan_distill' || !current.pendingDistill) return;- const { reason, recipe: raw } = current.pendingDistill;+ // Another advance landed it first; what it decided is next either way.+ if (current?.phase !== 'plan_distill' || !current.pendingDistill) return [];+ const { reason, recipe: raw, rerun: names } = current.pendingDistill;const recipe = raw.trim();const round = String(current.templateRevision);const skill = recipe ? current.planSkill : undefined;@@ -211,15 +216,51 @@ export class GoalProbeDistill {type: 'system',}).updateNodeDescription(goalId, current.templateNodeId, recipe);}+ const planVersions = version+ ? { ...current.planVersions, [round]: version }+ : current.planVersions;++ const rerun = pickRerunUnits(deliveredUnits(graph, current.probeNodeIds), names, 'none');+ if (!rerun.length) {+ await goalModel.updateRolloutState(goalId, {+ ...current,+ distilledProbes: probeSetKey(current),+ pendingDistill: undefined,+ planSkill,+ planVersions,+ });+ return [];+ }++ // The re-runs replace the probes they continue, so the round's next+ // distillation and its gate read them, not the deliveries sent back.+ const replaced = await reopenRoundUnits(+ new GoalGraphModel(tx, this.userId, this.workspaceId, {+ id: GOAL_COORDINATOR_ACTOR_ID,+ type: 'system',+ }),+ graph,+ current,+ rerun,+ { outline: recipe || policy?.spec?.recipeOutline, skill: planSkill },+ (unit) => rerunUnitNote(reason, unit.delivered, 'agent'),+ );await goalModel.updateRolloutState(goalId, {...current,- distilledProbes: probeSetKey(current),pendingDistill: undefined,+ phase: 'probe',planSkill,- planVersions: version- ? { ...current.planVersions, [round]: version }- : current.planVersions,+ planVersions,+ probeNodeIds: current.probeNodeIds.map((id) => replaced.get(id) ?? id),});+ return rerun.filter((unit) => replaced.has(unit.id)).map((unit) => unit.title);});+ if (!reopened.length) return undefined;+ log('probe distill: re-running %d probe(s) on the distilled plan', reopened.length);+ return {+ goalId,+ message: `The main Agent distilled the plan from the probes and sent ${reopened.length} back to run again on it before the gate judges them: ${reopened.join(', ')}`,+ outcome: 'advanced',+ };};}diff --git a/apps/server/src/services/goal/releaseReview.ts b/apps/server/src/services/goal/releaseReview.tsindex a163e9dc453..16b916e3bb9 100644--- a/apps/server/src/services/goal/releaseReview.ts+++ b/apps/server/src/services/goal/releaseReview.ts@@ -28,7 +28,13 @@ import type { GoalBriefService } from './goalBriefs';import type { GoalService } from './index';import { answeredProblem, GoalManagerService, problemKey } from './manager';import { buildReleaseGateDossier, openReleaseGateAcceptance, reviewedUnitIds } from './releaseGate';-import { carriedUnitBrief, createRecipeUnitTask, rerunUnitNote } from './rolloutBatch';+import {+ createRecipeUnitTask,+ deliveredUnits,+ pickRerunUnits,+ reopenRoundUnits,+ rerunUnitNote,+} from './rolloutBatch';import { describeGateChecks, type RolloutGateResult, withGateVerdict } from './rolloutGate';const log = debug('lobe-server:goal-rollout');@@ -55,37 +61,6 @@ export interface ReleaseReviewHost {const planVersionOf = (state: GoalRolloutState) =>state.planVersions?.[String(state.templateRevision)] ?? state.templateRevision;-/**- * The reviewed units a sent-back plan runs again, with the brief each keeps and- * what it delivered. `names` are the node ids or titles the main Agent chose;- * absent β or naming none of them, which is a slip rather than a choice β- * every reviewed unit runs again, and an empty list runs none.- */-const rerunUnits = (- graph: GoalGraphSnapshot,- state: GoalRolloutState,- waveSize: number,- names: string[] | undefined,-) => {- const units = reviewedUnitIds(state, waveSize).flatMap((id) => {- const node = graph.nodes.find((candidate) => candidate.id === id);- if (!node || node.kind !== 'task') return [];- const delivered = graph.workVersions- .filter((link) => link.nodeId === id && link.work && link.work.type !== 'task')- .map((link) => {- const title = link.work!.title ?? link.work!.identifier ?? '';- return link.work!.url ? `${title} ${link.work!.url}`.trim() : title;- })- .filter(Boolean);- return [- { brief: carriedUnitBrief(node), delivered: [...new Set(delivered)], id, title: node.title },- ];- });- if (!names) return units;- const chosen = units.filter((unit) => names.includes(unit.id) || names.includes(unit.title));- return names.length && !chosen.length ? units : chosen;-};-/*** The batch's release gate as a decision a person (or the main Agent) makes.*@@ -511,7 +486,11 @@ export class GoalReleaseReview {const recipe = pending.revisedRecipe!.trim();const round = String(state.templateRevision);const waveSize = Math.max(1, policy?.waveSize ?? ROLLOUT_WAVE_SIZE_DEFAULT);- const rerun = rerunUnits(graph, state, waveSize, pending.rerun);+ const rerun = pickRerunUnits(+ deliveredUnits(graph, reviewedUnitIds(state, waveSize)),+ pending.rerun,+ 'all',+ );const version = state.planSkill? await new BatchPlanSkillService(this.db, this.userId, this.workspaceId).revise(state.planSkill, {@@ -552,37 +531,15 @@ export class GoalReleaseReview {// Each re-run replaces its earlier run in the round, so the gate judges// the re-runs and the review reports them.- const replaced = new Map<string, string>();- for (const unit of rerun) {- const nodeId = await createRecipeUnitTask(- writer,- goalId,- current.batchNodeId,- unit.title,- { outline: recipe, skill: planSkill },- unit.brief,- rerunUnitNote(pending.correction, unit.delivered),- );- if (!nodeId) continue;- replaced.set(unit.id, nodeId);- reopened.push(unit.title);- await writer.createEdge(goalId, nodeId, unit.id, 'derived_from');- if (current.waveIndex === 0 && current.assayNodeId)- await writer.createEdge(goalId, current.assayNodeId, nodeId, 'depends_on');- }- // A unit that waited on another keeps waiting on it: the order the units- // ran in carries over to their re-runs, so a re-run never starts on the- // output its prerequisite is still redoing.- for (const edge of graph.edges) {- const source = edge.kind === 'depends_on' && replaced.get(edge.sourceNodeId);- if (!source) continue;- await writer.createEdge(- goalId,- source,- replaced.get(edge.targetNodeId) ?? edge.targetNodeId,- 'depends_on',- );- }+ const replaced = await reopenRoundUnits(+ writer,+ graph,+ current,+ rerun,+ { outline: recipe, skill: planSkill },+ (unit) => rerunUnitNote(pending.correction, unit.delivered),+ );+ for (const unit of rerun) if (replaced.has(unit.id)) reopened.push(unit.title);const swap = (ids: string[]) => ids.map((id) => replaced.get(id) ?? id);await goalModel.updateRolloutState(goalId, {...current,diff --git a/apps/server/src/services/goal/rolloutBatch.ts b/apps/server/src/services/goal/rolloutBatch.tsindex c44599c7097..f9282a5db55 100644--- a/apps/server/src/services/goal/rolloutBatch.ts+++ b/apps/server/src/services/goal/rolloutBatch.ts@@ -6,6 +6,7 @@ import {} from '@lobechat/const/goal';import type { LobeChatDatabase } from '@lobechat/database';import type {+ GoalGraphSnapshot,GoalRolloutPlanSkill,GoalRolloutPolicy,GoalRolloutState,@@ -128,18 +129,119 @@ export const createRecipeUnitTask = async (};/**- * Why a unit the owner already saw delivered runs again: the correction its- * plan was rewritten from, and what it delivered, so the run brings that- * delivery up to the revised plan instead of starting a second one beside it.+ * Why a delivered unit runs again: who sent its plan back and why, and what it+ * delivered, so the run brings that delivery up to the revised plan instead of+ * starting a second one beside it. The owner sends a plan back from the release+ * review; the main Agent sends probes back when it distills the plan from them+ * and finds a delivery that falls short of it.*/-export const rerunUnitNote = (correction: string, delivered: string[]) =>+export const rerunUnitNote = (+ correction: string,+ delivered: string[],+ by: 'agent' | 'owner' = 'owner',+) =>[- `The owner reviewed this unit's earlier delivery and sent the plan back with this correction:\n${correction}`,+ by === 'owner'+ ? `The owner reviewed this unit's earlier delivery and sent the plan back with this correction:\n${correction}`+ : `The main Agent checked this probe's earlier delivery against the plan and sent it back, because it falls short of it:\n${correction}`,delivered.length? `Earlier delivery:\n${delivered.map((item) => `- ${item}`).join('\n')}\nContinue on it (same branch / PR) until it meets the revised plan; do not open a second one.`: 'Redo the unit so it meets the revised plan.',].join('\n\n');+/** A delivered unit of the current round, as a re-run would continue it. */+export interface DeliveredUnit {+ /** The per-unit brief the re-run keeps (see {@link carriedUnitBrief}). */+ brief?: string;+ /** What the unit delivered, as `title url` lines. */+ delivered: string[];+ id: string;+ title: string;+}++/** The round's task units among `unitIds`, with what each delivered. */+export const deliveredUnits = (graph: GoalGraphSnapshot, unitIds: string[]): DeliveredUnit[] =>+ unitIds.flatMap((id) => {+ const node = graph.nodes.find((candidate) => candidate.id === id);+ if (!node || node.kind !== 'task') return [];+ const delivered = graph.workVersions+ .filter((link) => link.nodeId === id && link.work && link.work.type !== 'task')+ .map((link) => {+ const title = link.work!.title ?? link.work!.identifier ?? '';+ return link.work!.url ? `${title} ${link.work!.url}`.trim() : title;+ })+ .filter(Boolean);+ return [+ { brief: carriedUnitBrief(node), delivered: [...new Set(delivered)], id, title: node.title },+ ];+ });++/**+ * The units a rewrite names to run again. `names` are node ids or titles; a+ * list naming none of the units is a slip rather than a choice, so every unit+ * runs again, and an empty list runs none. `whenAbsent` is what an omitted list+ * means: the owner's correction covers every unit unless the Agent says+ * otherwise, while a distilled plan re-runs no probe unless it names one.+ */+export const pickRerunUnits = (+ units: DeliveredUnit[],+ names: string[] | undefined,+ whenAbsent: 'all' | 'none',+): DeliveredUnit[] => {+ if (!names) return whenAbsent === 'all' ? units : [];+ const chosen = units.filter((unit) => names.includes(unit.id) || names.includes(unit.title));+ return names.length && !chosen.length ? units : chosen;+};++/**+ * Re-open delivered units of a round on a rewritten plan, in place: each re-run+ * is a new Task in the batch, `derived_from` its earlier run, and on the probe+ * wave the gate (Assay) depends on it. A unit that waited on another keeps+ * waiting on it β the order the units ran in carries over to their re-runs, so+ * a re-run never starts on the output its prerequisite is still redoing.+ *+ * Returns each re-opened unit's new node id by its earlier one; the caller+ * swaps them into the round so the gate judges the re-runs.+ */+export const reopenRoundUnits = async (+ writer: GoalGraphModel,+ graph: GoalGraphSnapshot,+ state: Pick<GoalRolloutState, 'assayNodeId' | 'batchNodeId' | 'waveIndex'>,+ units: DeliveredUnit[],+ plan: { outline?: string; skill?: GoalRolloutPlanSkill },+ noteFor: (unit: DeliveredUnit) => string,+): Promise<Map<string, string>> => {+ const goalId = graph.goal.id;+ const replaced = new Map<string, string>();+ for (const unit of units) {+ const nodeId = await createRecipeUnitTask(+ writer,+ goalId,+ state.batchNodeId,+ unit.title,+ plan,+ unit.brief,+ noteFor(unit),+ );+ if (!nodeId) continue;+ replaced.set(unit.id, nodeId);+ await writer.createEdge(goalId, nodeId, unit.id, 'derived_from');+ if (state.waveIndex === 0 && state.assayNodeId)+ await writer.createEdge(goalId, state.assayNodeId, nodeId, 'depends_on');+ }+ for (const edge of graph.edges) {+ const source = edge.kind === 'depends_on' && replaced.get(edge.sourceNodeId);+ if (!source) continue;+ await writer.createEdge(+ goalId,+ source,+ replaced.get(edge.targetNodeId) ?? edge.targetNodeId,+ 'depends_on',+ );+ }+ return replaced;+};+export interface RolloutBatchProbe {/** 0-based indices of earlier probes this one builds on. */dependsOn?: number[];diff --git a/packages/prompts/src/chains/goalManager.test.ts b/packages/prompts/src/chains/goalManager.test.tsindex 037d2a2d897..b79aa02c4f5 100644--- a/packages/prompts/src/chains/goalManager.test.ts+++ b/packages/prompts/src/chains/goalManager.test.ts@@ -28,7 +28,7 @@ describe('buildGoalManagerPrompt', () => {'keeps supervision language tied to the goal rather than the English control prompt: %s',(requirement) => {const prompt = buildGoalManagerPrompt({ ...base, requirement });- expect(GOAL_MANAGER_PROMPT_VERSION).toBe('v13');+ expect(GOAL_MANAGER_PROMPT_VERSION).toBe('v14');expect(cdataOf(prompt, 'requirement')).toBe(requirement);expect(prompt).toContain('Use the language of the Goal requirement');expect(prompt).toContain(@@ -64,8 +64,9 @@ describe('buildGoalManagerPrompt', () => {});expect(prompt).toContain('Plan distillation:');expect(prompt).toContain('{"action":"revise_plan"');- // Nothing re-runs on a distilled plan, so the turn is not offered `rerun`.- expect(prompt).not.toContain('"rerun"');+ // A probe that falls short of the distilled plan goes back instead of to the gate.+ expect(prompt).toContain('"rerun":["node ids of the probes to run again"]');+ expect(prompt).toContain('definition of done');expect(prompt).not.toContain('Takeover: without you this Goal stops on a person');});@@ -165,7 +166,7 @@ describe('buildGoalManagerPrompt', () => {});expect(prompt.split('\n')[0]).toBe(- '<goalTurn goal="goal_1" maxTurns="12" trigger="settled" turn="3" version="v13">',+ '<goalTurn goal="goal_1" maxTurns="12" trigger="settled" turn="3" version="v14">',);expect(prompt.endsWith('</goalTurn>')).toBe(true);// CommonMark ends an HTML block at a blank line; the client needs one block.diff --git a/packages/prompts/src/chains/goalManager.ts b/packages/prompts/src/chains/goalManager.tsindex fef4fb9ffc9..56424629f21 100644--- a/packages/prompts/src/chains/goalManager.ts+++ b/packages/prompts/src/chains/goalManager.ts@@ -24,8 +24,11 @@ import { GOAL_TURN_TAG } from '@lobechat/const';* v13 hands a round's settled probes to the agent as a `rollout_distill`* takeover before the gate judges them: it rewrites the plan from what the* probes ran into, answered only with `revise_plan`.+ * v14 lets that distill turn send probes back: a probe whose delivery falls+ * short of the distilled plan is named in `rerun` and runs again on it before+ * the gate judges the round.*/-export const GOAL_MANAGER_PROMPT_VERSION = 'v13';+export const GOAL_MANAGER_PROMPT_VERSION = 'v14';export interface GoalManagerFeedbackNote {/** `user`, or `agent <id>` for an agent-written comment. */@@ -174,7 +177,7 @@ export const GOAL_BATCH_REVISE_RULE =/** A takeover whose problem is a round's settled probes: rewrite the plan from them. */export const GOAL_BATCH_DISTILL_RULE =- 'Plan distillation: every probe of the batch has settled, and before the gate judges them the plan skill must learn from them. Read the current plan skill and each probe\'s task, topic, deliverables, review comments and acceptance evidence with lh goal show and lh task view. Then rewrite the whole plan so every remaining unit benefits from what the probes ran into: steps they had to add or reorder, pitfalls and how they were resolved, conventions reviewers enforced, commands and checks that proved the work, and anything a probe got wrong that later units must avoid. Fold each lesson into the step it changes instead of appending a log of what happened; keep what is specific to one probe out unless it generalizes. When the probes taught nothing new, return the current plan unchanged and say so in reason. Answer {"action":"revise_plan","reason":"what the probes taught and where it landed in the plan","recipe":"the full plan, in the language of the Goal requirement"}. The probes are not run again and the owner reviews them with the plan you wrote. No other action is accepted on this turn.';+ 'Plan distillation: every probe of the batch has settled, and before the gate judges them the plan skill must learn from them. Read the current plan skill and each probe\'s task, topic, deliverables, review comments and acceptance evidence with lh goal show and lh task view. Then rewrite the whole plan so every remaining unit benefits from what the probes ran into: steps they had to add or reorder, pitfalls and how they were resolved, conventions reviewers enforced, commands and checks that proved the work, and anything a probe got wrong that later units must avoid. Fold each lesson into the step it changes instead of appending a log of what happened; keep what is specific to one probe out unless it generalizes. When the probes taught nothing new, return the current plan unchanged and say so in reason. Then check every probe\'s delivery against the plan you wrote, its definition of done above all β the state of its PR, CI and review, not only the probe\'s own report or a passed acceptance. A probe that falls short of it (a required step skipped, failing checks, unresolved review findings, a delivery that stopped at "next: review and merge") goes back: name it in "rerun", and say per probe in reason what is missing. It runs again on the plan, continuing its delivery (same branch / PR), and the round comes back to you once it settles, before the gate judges it. Answer {"action":"revise_plan","reason":"what the probes taught, where it landed in the plan, and what each probe sent back is missing","recipe":"the full plan, in the language of the Goal requirement","rerun":["node ids of the probes to run again"]} β omit "rerun" or pass [] when every probe meets the plan; the owner then reviews them with the plan you wrote. No other action is accepted on this turn.';/*** When to declare a batch, and how. The judgement is the planning agent's; thediff --git a/packages/types/src/goalRollout.ts b/packages/types/src/goalRollout.tsindex 5a6cc678b09..b6c86cdf569 100644--- a/packages/types/src/goalRollout.ts+++ b/packages/types/src/goalRollout.ts@@ -274,9 +274,19 @@ export interface GoalRolloutState {/*** The main Agent's plan rewritten from the settled probes, while the phase is* `plan_distill`. The next advance lands it as the plan skill's next version- * and judges the gate in the same step.+ * and judges the gate in the same step β unless it sends probes back.*/- pendingDistill?: { reason: string; recipe: string };+ pendingDistill?: {+ reason: string;+ recipe: string;+ /**+ * Node ids (or titles) of the probes whose delivery falls short of the+ * plan. They run again on it, continuing their delivery, and are distilled+ * again once they settle, before the gate judges the round. Absent or+ * empty, no probe runs again.+ */+ rerun?: string[];+ };/*** The owner's correction a sent-back release waits on, while the phase is* `plan_revision`. The main Agent rewrites the plan from it (`revisedRecipe`)