Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chief): create_bot can copy a bot's instructions, role and model

AdityaUmale9a305ee405b8
diff --git a/server/create-bot-fields.test.ts b/server/create-bot-fields.test.ts
new file mode 100644
index 0000000000..f582b5d05e
--- /dev/null
+++ b/server/create-bot-fields.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from "vitest";
+import { createBotFields, type CopySource } from "./create-bot-fields.ts";
+
+const selection = { instanceId: "claude", model: "claude-fixture" };
+const bot = (id: string, section: string, extra: Partial<CopySource> = {}): CopySource =>
+ ({ id, name: id, title: "Bug fixer", soul: "Fix bugs.", section, modelSelection: selection, ...extra });
+const chief = bot("chief", "Work", { chiefOfStaff: true });
+
+describe("createBotFields", () => {
+ it("keeps the given fields when nothing is copied", () => {
+ expect(createBotFields({ name: " Scout ", role: "Ops", instructions: "Work." }, chief, [chief]))
+ .toEqual({ name: "Scout", role: "Ops", instructions: "Work.", soul: "Work." });
+ });
+
+ it("copies the soul, role and model of a bot the Chief looks after, then adds the handover", () => {
+ const old = bot("old", "Work");
+ expect(createBotFields({ name: "New", copyFromBotId: "old", instructions: "Start with PR 12." }, chief, [chief, old]))
+ .toEqual({ name: "New", role: "Bug fixer", instructions: "Start with PR 12.", soul: "Fix bugs.\n\nStart with PR 12.", modelSelection: selection });
+ expect(createBotFields({ name: "New", role: "Lead", copyFromBotId: "old" }, chief, [chief, old]))
+ .toMatchObject({ role: "Lead", soul: "Fix bugs." });
+ });
+
+ it("refuses a bot outside the Chief's department, an archived bot and an unknown id", () => {
+ const bots = [chief, bot("other", "Sales"), bot("gone", "Work", { hidden: true })];
+ for (const copyFromBotId of ["other", "gone", "missing", 7]) {
+ expect(createBotFields({ name: "New", copyFromBotId }, chief, bots)).toMatchObject({ status: 404 });
+ }
+ });
+
+ it("refuses a copy whose soul would pass the size limit", () => {
+ const big = bot("big", "Work", { soul: "x".repeat(24_000) });
+ expect(createBotFields({ name: "New", copyFromBotId: "big", instructions: "more" }, chief, [chief, big])).toMatchObject({ status: 400 });
+ });
+});
diff --git a/server/create-bot-fields.ts b/server/create-bot-fields.ts
new file mode 100644
index 0000000000..123de3d81c
--- /dev/null
+++ b/server/create-bot-fields.ts
@@ -0,0 +1,32 @@
+// create_bot's copyFromBotId: a Chief replacing a bot starts the new one from that bot's SOUL.md, role and model.
+import { BOT_PROFILE_LIMITS } from "../shared/bot-profile.ts";
+import type { ModelSelection } from "./contracts.ts";
+import { canManage, type RosterMember } from "./peer-roster.ts";
+
+export interface CopySource extends RosterMember {
+ soul?: string;
+ modelSelection: ModelSelection;
+}
+
+export type CreateBotFields =
+ | { name: string; role: string; instructions: string; soul: string; modelSelection?: ModelSelection }
+ | { status: number; error: string };
+
+/** The new bot's name, role and soul; with copyFromBotId, a bot the Chief manages lends its soul, role and model. */
+export function createBotFields(body: Record<string, unknown>, chief: RosterMember, bots: readonly CopySource[]): CreateBotFields {
+ const name = String(body.name ?? "").trim();
+ const role = String(body.role ?? "").trim();
+ const instructions = String(body.instructions ?? "").trim();
+ if (body.copyFromBotId === undefined) return { name, role, instructions, soul: instructions };
+ const id = typeof body.copyFromBotId === "string" ? body.copyFromBotId.trim() : "";
+ const source = bots.find((bot) => bot.id === id);
+ if (!source || !canManage(chief, source)) {
+ return { status: 404, error: "copy_from_bot_id must be the exact id of a bot you look after; use list_bots" };
+ }
+ // Extra instructions come after the copied ones, so a handover note can add to them.
+ const soul = [(source.soul ?? "").trim(), instructions].filter(Boolean).join("\n\n");
+ if (Buffer.byteLength(soul) > BOT_PROFILE_LIMITS.soul) {
+ return { status: 400, error: `the copied instructions plus yours are over ${BOT_PROFILE_LIMITS.soul} bytes; shorten instructions` };
+ }
+ return { name, role: role || source.title?.trim() || "", instructions, soul, modelSelection: source.modelSelection };
+}
diff --git a/server/create-bot-model.e2e.test.ts b/server/create-bot-model.e2e.test.ts
index 643c693b59..0b34b4f41e 100644
--- a/server/create-bot-model.e2e.test.ts
+++ b/server/create-bot-model.e2e.test.ts
@@ -56,7 +56,12 @@ it("Chief creation uses the workspace default or a validated explicit model with
await create("Invalid specialist", invalid, 400);
}
await create("Third specialist");
- await create("Fourth specialist");
+ // A replacement copies a managed bot's soul, role and model; extra instructions come after.
+ const copyOf = (copyFromBotId: string, expected = 201) => api("POST", "/api/internal/create-bot", {
+ fromBotId: chief.id, fromThreadId: chief.threadId, name: "Fourth specialist", copyFromBotId, instructions: "Pick up the open work.",
+ }, expected, token);
+ await copyOf("missing-bot", 404);
+ const copy = applied(await copyOf(second.id));
await create("Fifth specialist", undefined, 429);
writeFileSync(gate, "finish");
await idle();
@@ -72,6 +77,9 @@ it("Chief creation uses the workspace default or a validated explicit model with
soul: "Complete assigned work.",
});
}
+ expect(bots.find((bot: any) => bot.id === copy.id)).toMatchObject({
+ title: "Specialist", modelSelection: explicit, soul: "Complete assigned work.\n\nPick up the open work.",
+ });
await api("PATCH", "/api/config", { defaultModelSelection: explicit });
unlinkSync(gate);
unlinkSync(fixture.fixtureDumpPath);
diff --git a/server/drivers/agents-call.test.ts b/server/drivers/agents-call.test.ts
index 8f575656a8..e1819cee16 100644
--- a/server/drivers/agents-call.test.ts
+++ b/server/drivers/agents-call.test.ts
@@ -98,6 +98,21 @@ describe("create_bot", () => {
});
});
+describe("create_bot copy_from_bot_id", () => {
+ it("creates a copy from just a name and the bot to copy", async () => {
+ const calls: Array<{ path: string; body: unknown }> = [];
+ const result = await callTool("create_bot", { name: "Bugfixer 2", copy_from_bot_id: " bot-old " }, context({
+ client: {
+ api: async (path, init) => { calls.push({ path, body: JSON.parse(String(init?.body)) }); return { id: "b2", name: "Bugfixer 2" }; },
+ apiResponse: async () => ({ ok: true, status: 200, body: {} }),
+ },
+ }));
+ expect(result.isError).toBeFalsy();
+ expect(calls).toEqual([{ path: "/api/internal/create-bot",
+ body: { fromBotId: "bot-voice", fromThreadId: "thread-voice", name: "Bugfixer 2", role: "", instructions: "", copyFromBotId: "bot-old" } }]);
+ });
+});
+
describe("team creation with every optional field filled in", () => {
// Strict tool-calling engines send each optional field, as "" or null, when they mean to leave it out.
const recording = (calls: Array<{ path: string; body: any }>, answer: Record<string, unknown>) => context({
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index 683fe5e17a..f8864fc99a 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -514,8 +514,9 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
const botName = String(args.name ?? "").trim();
const role = String(args.role ?? "").trim();
const instructions = String(args.instructions ?? "").trim();
- if (!botName || !role || !instructions) {
- return { text: "create_bot needs name, role, and instructions.", isError: true };
+ const copyFrom = typeof args.copy_from_bot_id === "string" ? args.copy_from_bot_id.trim() : "";
+ if (!botName || (!copyFrom && (!role || !instructions))) {
+ return { text: "create_bot needs name, role, and instructions, or name and copy_from_bot_id.", isError: true };
}
const r = await api(`/api/internal/create-bot`, {
method: "POST",
@@ -525,6 +526,7 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
name: botName,
role,
instructions,
+ ...(copyFrom ? { copyFromBotId: copyFrom } : {}),
...(args.modelSelection !== undefined ? { modelSelection: args.modelSelection } : {}),
...(typeof args.cwd === "string" ? { cwd: args.cwd.trim() } : {}),
}),
diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json
index eb36d153b6..0c503e8356 100644
--- a/server/drivers/agents-catalog-goldens/full.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json
@@ -626,6 +626,10 @@
"type": "string",
"description": "What this specialist is responsible for and how it should work."
},
+ "copy_from_bot_id": {
+ "type": "string",
+ "description": "To duplicate or replace a bot: its id. Copies its soul, role and model; instructions are added after."
+ },
"modelSelection": {
"type": "object",
"additionalProperties": false,
@@ -654,9 +658,7 @@
}
},
"required": [
- "name",
- "role",
- "instructions"
+ "name"
]
}
},
diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json
index 7041a1ae30..dc797adf4a 100644
--- a/server/drivers/agents-catalog-goldens/profiles.json
+++ b/server/drivers/agents-catalog-goldens/profiles.json
@@ -1,7 +1,7 @@
{
"default": {
- "bytes": 61454,
- "sha256": "045010d682155ec9e4c132bead9c0dac8146b1295d04f2df406f975a151c9bd4",
+ "bytes": 61587,
+ "sha256": "c06159f606dae0fce7254d14f39ee51e1d26a47cf7fa2cdb3048540cf000301a",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -53,8 +53,8 @@
]
},
"voice": {
- "bytes": 62235,
- "sha256": "74e9c935f3543d99a6ec65ee5c8b1d7c86a7f844eb96732267f7f68609837ee8",
+ "bytes": 62368,
+ "sha256": "3e67e52a44be5bdad40b6dd853ddc41048628544203afa36720d6d2a4cf7d8ae",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -107,8 +107,8 @@
]
},
"shared": {
- "bytes": 63719,
- "sha256": "d7bdfd779165ff35fd6eef4a2ded16e74f9f1b676738c0e479460bda6106d5b6",
+ "bytes": 63852,
+ "sha256": "d01bd7afc12cbace189b4f747ad39b7c21981b58db9cc0cd723e68e170997b1d",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -162,8 +162,8 @@
]
},
"shared+voice": {
- "bytes": 64500,
- "sha256": "40c70836b16bfca159cce9cc3893763ff5dd59b747086e34369dc3eeab4091c7",
+ "bytes": 64633,
+ "sha256": "f97aec3e73baac49057421de1a1d656b33921162d47c091d9e6926c3c8573a85",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -218,8 +218,8 @@
]
},
"skills": {
- "bytes": 64530,
- "sha256": "9ee67f915766577488c0e7a0c7339cb7815e332f0e2928287e1bac7e779bb5f5",
+ "bytes": 64663,
+ "sha256": "11a11c8db0e86c1ef8602cbf98c2cde72fd8898b88f75e237db5c9da40bb763f",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -273,8 +273,8 @@
]
},
"skills+voice": {
- "bytes": 65311,
- "sha256": "dfb4f3917aaa8dbdd1d51e1d3211bf79079d6b9c92efb8f2f3dc8a4734845f42",
+ "bytes": 65444,
+ "sha256": "6540792eb8e4a8e72e969edb3a6e4a82faa4ffee7fbd87d7faf96e2edebd4ad1",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -329,8 +329,8 @@
]
},
"skills+shared": {
- "bytes": 66795,
- "sha256": "3f8176fdfc857a1a9cc79f581637ebaa3236ea3a0e80feb17e4dac748814df0d",
+ "bytes": 66928,
+ "sha256": "1fd9e19dba4f68f9c5b0c9534e927eeb1ecf3e7ac2efc58336dd2084e6ab61dc",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -386,8 +386,8 @@
]
},
"skills+shared+voice": {
- "bytes": 67576,
- "sha256": "92e3ae1e88d08549088321caad443b8215aa84b2a10232cf52198b92710492fa",
+ "bytes": 67709,
+ "sha256": "f68202a2f8536f7f4cac19ed8088d5e6a673f7b6f6d026e30b861f9399ed594c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -832,8 +832,8 @@
]
},
"skills+shared+voice+cloud-home": {
- "bytes": 67342,
- "sha256": "b77188d584a585d08b121d95328d0e680292085d026498c9194688916ee01f11",
+ "bytes": 67475,
+ "sha256": "2612d6c3af5537b4d050e0692a2d3c8730a3a98ed1977e2e4db32d8e024fcf29",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -941,8 +941,8 @@
]
},
"skills+shared+voice+x": {
- "bytes": 71415,
- "sha256": "859309309fea2c38eda576a677319398b8f75651e21eadb394014eb989a14f43",
+ "bytes": 71548,
+ "sha256": "458c21a62477ce37fac677c0dcff1a0620ecb442ecdfcfc3571d76ba385fb64c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1003,8 +1003,8 @@
]
},
"skills+shared+voice+x+team": {
- "bytes": 71415,
- "sha256": "859309309fea2c38eda576a677319398b8f75651e21eadb394014eb989a14f43",
+ "bytes": 71548,
+ "sha256": "458c21a62477ce37fac677c0dcff1a0620ecb442ecdfcfc3571d76ba385fb64c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1065,8 +1065,8 @@
]
},
"skills+shared+voice+x+team+images": {
- "bytes": 72188,
- "sha256": "67886d40d01f465a7be8503aa914b7cd1ebd50f40759bfb1b608274f10d45f04",
+ "bytes": 72321,
+ "sha256": "e37df357c15ae9c380aaa6ab6b9804d5ce187972636d6ee53681675b1bfcc422",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1128,8 +1128,8 @@
]
},
"default+legacy-switches": {
- "bytes": 61454,
- "sha256": "045010d682155ec9e4c132bead9c0dac8146b1295d04f2df406f975a151c9bd4",
+ "bytes": 61587,
+ "sha256": "c06159f606dae0fce7254d14f39ee51e1d26a47cf7fa2cdb3048540cf000301a",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1181,8 +1181,8 @@
]
},
"default+mausbot": {
- "bytes": 62105,
- "sha256": "6ed238881df8e394e1fbc6696bd58e2619a6d6325ffd9c04e965a0e23ff6980d",
+ "bytes": 62238,
+ "sha256": "afdd8edfc9b092c6a0c8f275121e20ad7cd79bf267edaf6d0e85ea9b0c0745ed",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1236,8 +1236,8 @@
]
},
"skills+shared+voice+mausbot": {
- "bytes": 68227,
- "sha256": "c6ab39a67adbd922de5471f38e4d9924e608c6d8d1e847a8e8e7173af567fbfd",
+ "bytes": 68360,
+ "sha256": "8ff14af4657b3f1a38c635b93cd3d6d298cd0d14bf0c53424ca821da3775b696",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1296,8 +1296,8 @@
]
},
"default+no-computer-pick": {
- "bytes": 60242,
- "sha256": "262bb5d78739882ee797c124f6e4e0bcd9cb34bf3f2237710c50fb940e1318e9",
+ "bytes": 60375,
+ "sha256": "b2ab804aecec83bf7ced9fc93ae820e0bde415a4a4145ec9b0d1e8033ff31d93",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1348,8 +1348,8 @@
]
},
"default+room": {
- "bytes": 57744,
- "sha256": "fa22da9a89af25905589aac685f2c2cc3d027f5078a335df842331675466da61",
+ "bytes": 57877,
+ "sha256": "d04ceb08132aa4372740afd775b5783ac12d6736604c21c1c0adacce44c6287b",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1437,8 +1437,8 @@
]
},
"default+images": {
- "bytes": 62227,
- "sha256": "48864c5e6d02b4a97e46eafff5cdda0e98ffbf7de7eead845e8d76d2931267e6",
+ "bytes": 62360,
+ "sha256": "bb60fd6d5bb5a03a11f9101285b415e10a054936499ff2d6b133d4c7fd7531f3",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1491,8 +1491,8 @@
]
},
"skills+shared+voice+x+team+images+hosting": {
- "bytes": 74051,
- "sha256": "6948e69c1fe1d59ae5904708079d8015482c7c938bba6a2984a4ca53d28b8096",
+ "bytes": 74184,
+ "sha256": "7d77974a2ae4b46a3c9587ddddedcccda7d69d9d1b53cd0392769297e055d700",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1556,8 +1556,8 @@
]
},
"default+hosting": {
- "bytes": 63317,
- "sha256": "f388ab6116f0904fb2f55d30a8a333cb8054da154990e95dd3ac0b03ecb285eb",
+ "bytes": 63450,
+ "sha256": "f3ed72b1313145f249caf0c9c8b8bf27a3ba973af1be82b8fbdc16268095a73c",
"tools": [
"tool_result_read",
"list_room_targets",
diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts
index c030009ce0..8b7e81215c 100644
--- a/server/drivers/agents-catalog.ts
+++ b/server/drivers/agents-catalog.ts
@@ -388,6 +388,7 @@ const TOOL_DEFINITIONS = [
name: { type: "string", description: "Short, unique display name for the specialist." },
role: { type: "string", description: "The specialist's job title or role." },
instructions: { type: "string", description: "What this specialist is responsible for and how it should work." },
+ copy_from_bot_id: { type: "string", description: "To duplicate or replace a bot: its id. Copies its soul, role and model; instructions are added after." },
modelSelection: { type: "object", additionalProperties: false, properties: {
instanceId: { type: "string" }, model: { type: "string" },
effort: { type: "string" }, variant: { type: "string" },
@@ -398,7 +399,7 @@ const TOOL_DEFINITIONS = [
description: "Absolute path of the folder this specialist's tools read and write in (for example /Users/me/Projects/site). It must already exist. Leave it out for the specialist's private workspace.",
},
},
- required: ["name", "role", "instructions"],
+ required: ["name"],
},
},
{
diff --git a/server/index.ts b/server/index.ts
index f8906fd387..0c0f33f997 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -74,7 +74,7 @@ import { avatarImageStatus } from "./avatar-image.ts";
import { imageGenerationReady } from "./image-generation.ts";
import { createImageToolRoutes } from "./routes/image-tools.ts"; import { createMeetingsHost } from "./host/meetings-host.ts"; import { meetingsUnavailablePrompt } from "./meetings/prompt.ts";
import { createImageSettingsRoutes } from "./routes/image-settings.ts";
-import { fitsOnOneLine, parseBotProfilePatch } from "./bot-profile.ts";
+import { fitsOnOneLine, parseBotProfilePatch } from "./bot-profile.ts"; import { createBotFields } from "./create-bot-fields.ts";
import { routeDirectTurn } from "./turn-route.ts"; import { QuickModelFallback } from "./quick-model-fallback.ts"; import { COMPUTER_JOURNAL_PATH, createSavedSteps, personRequest, savedStepsEnabled } from "./saved-steps/saved-steps.ts";
import { groupTurnCwd } from "./room-cwd.ts";
import { RoomTurnDeadline, RoomTurnStallRegistry, effectiveRoomTurnTimeoutMinutes, parseConversationTurnTimeout, roomTurnTimeoutMessage } from "./room-turn-timeout.ts";
@@ -14153,10 +14153,10 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
if (store.bots.length >= MAX_WORKSPACE_BOTS) {
return json(res, 409, { error: `this workspace is limited to ${MAX_WORKSPACE_BOTS} bots` });
}
- const name = String(body.name ?? "").trim();
- const role = String(body.role ?? "").trim();
- const instructions = String(body.instructions ?? "").trim();
- if (!name || !role || !instructions) {
+ const fields = createBotFields(body, chief, store.bots);
+ if ("error" in fields) return json(res, fields.status, { error: fields.error });
+ const { name, role, instructions, soul } = fields;
+ if (!name || !role || !soul) {
return json(res, 400, { error: "name, role, and instructions are required" });
}
if (name.length > 80) return json(res, 400, { error: "name must be at most 80 characters" });
@@ -14169,7 +14169,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
}
let selection: ModelSelection;
if (body.modelSelection === undefined) {
- selection = await defaultSelection();
+ const copied = fields.modelSelection && checkedModelSelection(fields.modelSelection, undefined, true); selection = copied && copied.ok ? copied.selection : await defaultSelection();
} else {
const checked = checkedModelSelection(body.modelSelection, undefined, true);
if (!checked.ok) return json(res, checked.status, refusalBody(checked));
@@ -14199,7 +14199,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
if (duplicate) {
return json(res, 409, { error: `@${duplicate.name} already exists in this section; use list_bots` });
}
- const summary = instructions.split("\n").find((line) => line.trim())?.trim() ?? "";
+ const summary = soul.split("\n").find((line) => line.trim())?.trim() ?? "";
const setup = {
botId: chief.id,
threadId: fromThreadId,
@@ -14214,7 +14214,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
name,
title: role,
description: summary.length > 200 ? `${summary.slice(0, 199).trimEnd()}…` : summary,
- soul: instructions,
+ soul,
modelSelection: selection,
...(cwd !== undefined ? { cwd } : {}),
},