From 239f33f1b4e87e68cf5c5001b2c7118d0d8ca4fb Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Sat, 31 Oct 2026 04:27:22 +0200 Subject: [PATCH 1/2] feat(server): t3_workflow_run takes templates and shows grown agents as they are added t3_workflow_run checks every template's target before it starts, and its description names templates, dry, addAgents, rerun and {{input.x}} (+115 B of tool list). A service test grows a run to 20 agents: the 17 grown rows show queued under their phase and round before round 2 starts, and every row update stays within 2 KB. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/WorkflowRuns.test.ts | 93 +++++++++++++++++++ apps/server/src/mcp/WorkflowRuns.ts | 10 +- .../src/mcp/toolkits/orchestrator/tools.ts | 2 +- .../src/provider/agentContextBudget.json | 2 +- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/apps/server/src/mcp/WorkflowRuns.test.ts b/apps/server/src/mcp/WorkflowRuns.test.ts index c3a2608724af..46bee00ca977 100644 --- a/apps/server/src/mcp/WorkflowRuns.test.ts +++ b/apps/server/src/mcp/WorkflowRuns.test.ts @@ -565,6 +565,99 @@ it.layer(layerTest)("t3_workflow_run", (it) => { }), ); + it.effect( + "shows a judge's grown agents queued under their phase and round, within 2 KB per update", + () => + Effect.gen(function* () { + const runs = yield* workflowRunsIn(yield* Effect.scope); + const parent = yield* seedParent("grow"); + const growing = { + name: "grow", + stages: [ + { + id: "loop", + repeat: { + stages: [ + { id: "draft", agents: [{ id: "poet", task: "Write." }] }, + { + id: "critique", + agents: [ + { + id: "critic", + task: "Judge {{draft}}.", + resultSchema: { type: "object", required: ["ok"] }, + }, + ], + }, + ], + judge: "critic", + until: { path: "ok", equals: true }, + max: 2, + templates: { probe: { task: "Probe {{input.angle}}." } }, + }, + }, + ], + }; + const { subagentId } = yield* runs.run(parent.scope, growing); + yield* parent.endTurn; + const settled = new Set(); + const settleNext = (count: number, text: string) => + Effect.gen(function* () { + const children = yield* childrenOf(parent.threadId, subagentId, settled.size + count); + for (const child of children.filter((c) => !settled.has(c.id))) { + settled.add(child.id); + yield* settleChild(child, text); + } + return children; + }); + const addAgents = Array.from({ length: 17 }, (_, index) => ({ + key: `probe-${index + 1}`, + template: "probe", + input: { angle: `angle ${index + 1}` }, + })); + yield* settleNext(1, "Draft."); + yield* settleNext( + 1, + `\`\`\`json\n${JSON.stringify({ ok: false, addAgents, rerun: ["critique"] })}\n\`\`\``, + ); + + const grown = yield* (yield* parentEvents(parent.threadId)).pipe( + Stream.filter(({ payload }) => + (payload.workflow?.agents ?? []).some((agent) => agent.label === "probe-17"), + ), + Stream.runHead, + Effect.map((event) => Option.getOrThrow(event).payload.workflow!), + ); + assert.deepEqual( + grown.phases.map((phase) => phase.title), + ["draft", "critique"], + ); + // Every grown row is there before round 2 starts anything. + const rows = grown.agents.filter((agent) => agent.attempt === 2); + assert.deepEqual( + rows.map((row) => row.label), + addAgents.map((add) => add.key), + ); + for (const row of rows) { + assert.deepEqual([row.state, row.phaseIndex, row.attempt], ["queued", 0, 2]); + } + + const probes = yield* settleNext(17, "Probed."); + assert.include( + probes.find((child) => child.title === "draft.probe-3#2")?.prompt ?? "", + "Probe angle 3.", + ); + yield* settleNext(1, '```json\n{"ok":true}\n```'); + assert.equal((yield* ended(parent.threadId, subagentId))?.status, "completed"); + const status = yield* runs.status(parent.scope, subagentId); + assert.deepInclude(status.stages[0], { exit: "accepted" }); + + const sized = yield* largestUpdate(parent.threadId, subagentId); + assert.lengthOf(sized.agents, 20); + assert.isAtMost(sized.largest, 2048); + }), + ); + it.effect("resumes after a restart without relaunching a child and still wakes once", () => Effect.gen(function* () { const projections = yield* ProjectionStore.ProjectionStoreV2; diff --git a/apps/server/src/mcp/WorkflowRuns.ts b/apps/server/src/mcp/WorkflowRuns.ts index 8a7a749c3fc1..3a0e293c8b51 100644 --- a/apps/server/src/mcp/WorkflowRuns.ts +++ b/apps/server/src/mcp/WorkflowRuns.ts @@ -288,7 +288,15 @@ const make = Effect.gen(function* () { ) { const scope = yield* requireThreadScope(callerScope, "t3_workflow_run"); const spec = yield* decodeWorkflowSpec(input); - for (const agent of agentStages(spec).flatMap((stage) => stage.agents)) { + const templates = spec.stages.flatMap((stage) => + "agents" in stage + ? [] + : Object.entries(stage.repeat.templates ?? {}).map(([id, template]) => ({ + ...template, + id, + })), + ); + for (const agent of [...agentStages(spec).flatMap((stage) => stage.agents), ...templates]) { if (agent.target?.environmentId !== undefined) { return yield* failure( "invalid_request", diff --git a/apps/server/src/mcp/toolkits/orchestrator/tools.ts b/apps/server/src/mcp/toolkits/orchestrator/tools.ts index 9aab62c70592..451334bdaf91 100644 --- a/apps/server/src/mcp/toolkits/orchestrator/tools.ts +++ b/apps/server/src/mcp/toolkits/orchestrator/tools.ts @@ -136,7 +136,7 @@ const WorkflowStage = Schema.Struct({ const WorkflowRunTool = Tool.make("t3_workflow_run", { description: - "Run agents in stages; returns at once and wakes you when done. Stages run in order: `{id, agents:[{id, task, target?, role?, isolation?, resultSchema?}]}` in parallel, or `{id, repeat:{stages, judge, until:{path, equals}, max, onExhausted?}}`. `{{stage}}`, `{{stage.agent}}`, `{{feedback}}` in a task insert results.", + "Run agents in stages; returns at once and wakes you when done. Stages run in order: `{id, agents:[{id, task, target?, role?, isolation?, resultSchema?}]}` in parallel, or `{id, repeat:{stages, judge, until:{path, equals}, max, onExhausted?, dry?, templates?:{name:{task}}}}`, whose judge may return `addAgents:[{key, template, input}]`, `rerun:[stage]`. `{{stage}}`, `{{stage.agent}}`, `{{feedback}}`, `{{input.x}}` insert results.", parameters: Schema.Struct({ name: TrimmedNonEmptyString, stages: Schema.Array(WorkflowStage), diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 0f9ad7d1fad0..09f1a37f42e8 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5135, "codexAdditionalContextBytes": 6865, - "mcpToolListJsonBytes": 46990 + "mcpToolListJsonBytes": 47105 } From 0d53251e2a0134fd40d21fa655736475dbace331 Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Sat, 31 Oct 2026 04:46:13 +0200 Subject: [PATCH 2/2] fix(server): t3_workflow_run says what dry does and that a grown agent can name its stage The description advertised dry? without its meaning and left out addAgents' stage?. It now says dry:N ends the loop after N rounds that add no agents and ask for no rerun, within the same tool-list budget (47,106 B, +1 B over the previous text). Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/toolkits/orchestrator/tools.ts | 2 +- apps/server/src/provider/agentContextBudget.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/mcp/toolkits/orchestrator/tools.ts b/apps/server/src/mcp/toolkits/orchestrator/tools.ts index 451334bdaf91..93bd155d034c 100644 --- a/apps/server/src/mcp/toolkits/orchestrator/tools.ts +++ b/apps/server/src/mcp/toolkits/orchestrator/tools.ts @@ -136,7 +136,7 @@ const WorkflowStage = Schema.Struct({ const WorkflowRunTool = Tool.make("t3_workflow_run", { description: - "Run agents in stages; returns at once and wakes you when done. Stages run in order: `{id, agents:[{id, task, target?, role?, isolation?, resultSchema?}]}` in parallel, or `{id, repeat:{stages, judge, until:{path, equals}, max, onExhausted?, dry?, templates?:{name:{task}}}}`, whose judge may return `addAgents:[{key, template, input}]`, `rerun:[stage]`. `{{stage}}`, `{{stage.agent}}`, `{{feedback}}`, `{{input.x}}` insert results.", + "Run stages in order; returns at once, wakes you when done. Stage: `{id,agents:[{id,task,target?,role?,isolation?,resultSchema?}]}` (parallel) or `{id,repeat:{stages,judge,until:{path,equals},max,onExhausted?,dry?,templates?:{name:{task}}}}`. Its judge may return `addAgents:[{key,template,input,stage?}]`, `rerun:[stage]`; `dry:N` ends after N rounds of neither. {{stage}}, {{stage.agent}}, {{feedback}}, {{input.x}} insert results.", parameters: Schema.Struct({ name: TrimmedNonEmptyString, stages: Schema.Array(WorkflowStage), diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 09f1a37f42e8..1d99b2763b8b 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5135, "codexAdditionalContextBytes": 6865, - "mcpToolListJsonBytes": 47105 + "mcpToolListJsonBytes": 47106 }