Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(swarm): sub-agents start their own only when their task says so

Samrat Talukdar64045183193b
diff --git a/apps/server/src/omnirush-agent-prompt.ts b/apps/server/src/omnirush-agent-prompt.ts
index a126e5d2..064cd61c 100644
--- a/apps/server/src/omnirush-agent-prompt.ts
+++ b/apps/server/src/omnirush-agent-prompt.ts
@@ -40,7 +40,7 @@ Hard rule: never copy private memory into repo files. Store only redacted summar
- Write long files in chunks: create a file with its first section, then append the rest in a few smaller edit (or patch) calls instead of one very large write. A single multi-thousand-token patch is the write most likely to be cut off in transit; if a write is interrupted, re-issue only the missing part.
- Do simple work yourself: a question a few tool calls can answer needs no sub-agent. Use the subagent tool only when the user asks for sub-agents or the work clearly splits into independent parts that each take real effort.
- When the user asks for a specific number of agents, make exactly that many subagent calls, no more and no fewer, and start them all in one message so they run in parallel. Use the general subagent unless a more specialized subagent is clearly better. Never replace an explicit delegation request with a simulated multi-role answer, and never claim subagents are unavailable while the subagent tool is present.
-- Write each sub-agent's prompt yourself: self-contained, limited to that sub-agent's part, saying what to return. Never paste the user's whole message, or the user's instructions about sub-agents, into a sub-agent's prompt: the sub-agent would follow them again.
+- Write each sub-agent's prompt yourself: self-contained, limited to that sub-agent's part, saying what to return. Never paste the user's whole message, or the user's instructions about sub-agents, into a sub-agent's prompt: the sub-agent would follow them again. Tell a sub-agent to start its own sub-agents only when the user explicitly asked for nested sub-agents.
- Wait for every delegated task, then synthesize their actual results before answering; keep delegated activity visible in the session.
- If steps repeat, capture them as a skill following the \`Skill creation:\` instruction in this prompt.
- Prefer clear, practical steps over abstract explanations.
diff --git a/apps/server/src/omnirush-swarm.ts b/apps/server/src/omnirush-swarm.ts
index e432e1aa..3ac068ab 100644
--- a/apps/server/src/omnirush-swarm.ts
+++ b/apps/server/src/omnirush-swarm.ts
@@ -121,7 +121,7 @@ The board is \`${OMNIRUSH_SWARM_FILE}\` in the workspace, never a file in the pr
1. Before delegating, create \`${OMNIRUSH_SWARM_FILE}\` (replace it if one exists) with: \`# Goal\` (at most 3 sentences), \`## Tasks\` (a table: id, task, owner, status, result; ids like T1, T2, and T1.1 for a sub-task of T1; status is todo, running, done or blocked; every cell one short line), \`## Findings\` (empty) and \`## Decisions\` (choices every agent must follow, one line each).
2. Give each sub-agent one task id. Its subagent-tool prompt names the id and only its own part of the work (never the user's whole message or instructions about sub-agents), and says: use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id (it shows your row and the Decisions, and sets your status, one-line result and at most ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} one-line findings); do not read or edit the board file; report back briefly.
-3. Sub-agents do their own task themselves. Only a large task that splits into clearly independent parts is split further: its sub-agent adds sub-task rows (T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` and gives the same instructions to its own sub-agents. Sub-agents nest at most ${OMNIRUSH_SUBAGENT_DEPTH} layers deep. Start as many sub-agents as the work needs, and no more.
+3. Sub-agents do their own task themselves, even long ones. Split a task further only when the user explicitly asked for nested sub-agents: then its prompt tells that sub-agent to add sub-task rows (T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` and gives the same instructions to its own sub-agents. Sub-agents nest at most ${OMNIRUSH_SUBAGENT_DEPTH} layers deep. Start as many sub-agents as the work needs, and no more.
4. Launch independent tasks in parallel (several subagent calls in one message); give tasks that edit the same files to one agent.
5. When every task is done, read \`${OMNIRUSH_SWARM_FILE}\` once, check the results against the task reports, and answer the user. Do not move, copy or archive the board: omnirush.ai does that when the turn ends. Board cells over ${OMNIRUSH_SWARM_CELL_MAX_CHARS} characters, lines over ${OMNIRUSH_SWARM_LINE_MAX_CHARS} and findings past ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} per task are cut.`;
@@ -147,9 +147,9 @@ export function omnirushSwarmArchiveName(date: Date = new Date()): string {
export function omnirushSubagentNote(depth: number): string {
return [
`You are a sub-agent (layer ${depth} of at most ${OMNIRUSH_SUBAGENT_DEPTH}). Do your task yourself.`,
- "Instructions about sub-agents in your task text (how many agents to use, what to delegate) were meant for the main session, not you: do not follow them.",
+ "Instructions about sub-agents that the user wrote (how many agents to use, what to delegate) were meant for the main session, which already carried them out: do not repeat them.",
depth < OMNIRUSH_SUBAGENT_DEPTH
- ? "Delegate with the subagent tool only if your task is large and splits into clearly independent parts that would take much longer alone; never re-delegate your whole task."
+ ? "Start sub-agents with the subagent tool only if your task explicitly tells you to; otherwise do the whole task yourself, even when it is long. Never re-delegate your whole task."
: "You cannot delegate further: do the work yourself.",
].join("\n");
}
diff --git a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts b/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
index fda10525..07c0cb93 100644
--- a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
+++ b/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
@@ -135,13 +135,14 @@ describe("omnirush swarm plugin", () => {
expect(await system("ses_main")).toBe("");
const child = await system("ses_child");
expect(child).toContain("Do your task yourself.");
- expect(child).toContain("Instructions about sub-agents in your task text");
- expect(child).toContain("were meant for the main session, not you");
- expect(child).toContain("never re-delegate your whole task");
+ expect(child).toContain("Instructions about sub-agents that the user wrote");
+ expect(child).toContain("were meant for the main session, which already carried them out");
+ expect(child).toContain("only if your task explicitly tells you to");
+ expect(child).toContain("Never re-delegate your whole task");
expect(await system("ses_grand")).toContain("layer 2 of at most 3");
const great = await system("ses_great");
expect(great).toContain("You cannot delegate further");
- expect(great).not.toContain("Delegate with the subagent tool");
+ expect(great).not.toContain("Start sub-agents with the subagent tool");
// Same text on every step (prompt cache).
expect(await system("ses_child")).toBe(child);
});