Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(team-setup): blank optional fields from strict tool calls no longer break team creation
AdityaUmale7239eeed3b58
diff --git a/server/drivers/agents-blank-arguments.ts b/server/drivers/agents-blank-arguments.tsnew file mode 100644index 0000000000..b60ebbe5de--- /dev/null+++ b/server/drivers/agents-blank-arguments.ts@@ -0,0 +1,57 @@+/** Drops arguments a model filled with a blank when it meant to leave them out, before the call is checked. */+import type { Json } from "./agents-client.ts";++function jsonRecord(value: unknown): value is Json {+ return value !== null && typeof value === "object" && !Array.isArray(value);+}++/** The top-level arguments a model may fill with `""` (or spaces) when it means to leave them out, per tool. Only these:+ * elsewhere a blank can be the value itself, such as a cleared room bulletin or a bot's private folder. */+const BLANK_MEANS_LEFT_OUT: Readonly<Record<string, readonly string[]>> = {+ coordinate_bots: ["group_id", "reason", "thread", "title", "reply", "done_when", "answers"],+ session_search: ["thread_id", "message_id", "query", "since", "until", "scope"],+ show_html: ["html", "jsx", "path"],+ // A blank text or old_text is a mistake the schema names, not "not given".+ memory_update: ["until"],+};++const blankText = (value: unknown) => typeof value === "string" && !value.trim();+const blankOrNull = (value: unknown) => value === null || blankText(value);++/** A copy of `record` without the given keys where `blank` says they were left out. */+function withoutBlank(record: Json, keys: readonly string[], blank: (value: unknown) => boolean = blankOrNull): Json {+ const out: Json = { ...record };+ for (const key of keys) if (blank(out[key])) delete out[key];+ return out;+}++/** Strict tool-calling engines fill every optional field, so a model choice arrives with effort and variant both set to+ * "" or null; the receiver reads either as a choice and refuses ("choose either a model variant or an effort level"). */+function withoutBlankModelChoice(selection: unknown): unknown {+ return jsonRecord(selection) ? withoutBlank(selection, ["effort", "variant"]) : selection;+}++/** Same for team setup: a create also carries a blank botId and an update a blank key, which the receiver refuses as+ * unrecognized keys. A non-blank one is kept, so a real mistake is still named. */+function withoutBlankTeamSetupFields(input: Json): Json {+ if (!Array.isArray(input.operations)) return input;+ return {+ ...input,+ operations: input.operations.map((operation) => {+ if (!jsonRecord(operation)) return operation;+ const out = withoutBlank(operation, operation.action === "create" ? ["botId"] : operation.action === "update" ? ["key"] : []);+ if (jsonRecord(out.fields) && out.fields.modelSelection !== undefined) {+ out.fields = { ...out.fields, modelSelection: withoutBlankModelChoice(out.fields.modelSelection) };+ }+ return out;+ }),+ };+}++export function dropBlankArguments(name: string, input: Json): Json {+ if (!jsonRecord(input)) return input;+ if (name === "propose_team_setup") return withoutBlankTeamSetupFields(input);+ if (name === "create_bot" && input.modelSelection !== undefined) return { ...input, modelSelection: withoutBlankModelChoice(input.modelSelection) };+ const keys = Object.hasOwn(BLANK_MEANS_LEFT_OUT, name) ? BLANK_MEANS_LEFT_OUT[name] : undefined;+ return keys ? withoutBlank(input, keys, blankText) : input;+}diff --git a/server/drivers/agents-call.test.ts b/server/drivers/agents-call.test.tsindex a3f024117a..15ca8bad36 100644--- a/server/drivers/agents-call.test.ts+++ b/server/drivers/agents-call.test.ts@@ -98,6 +98,46 @@ describe("create_bot", () => {});});+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({+ client: {+ api: async (path, init) => { calls.push({ path, body: JSON.parse(String(init?.body)) }); return answer; },+ apiResponse: async () => ({ ok: true, status: 200, body: {} }),+ },+ });++ it("propose_team_setup drops a blank botId on create, a blank key on update and blank effort/variant", async () => {+ const calls: Array<{ path: string; body: any }> = [];+ const selection = { instanceId: "codex", model: "gpt-5", effort: "", variant: null };+ await callTool("propose_team_setup", {+ reason: "Shop team",+ operations: [+ { action: "create", key: "buyer", botId: "", fields: { name: "Buyer", title: "Buyer", soul: "Buy.", modelSelection: selection } },+ { action: "update", key: " ", botId: "b-1", fields: { modelSelection: { instanceId: "codex", model: "gpt-5", effort: "high", variant: "" } } },+ ],+ }, recording(calls, { state: "applied", title: "Team" }));+ expect(calls[0].body.plan.operations).toEqual([+ { action: "create", key: "buyer", fields: { name: "Buyer", title: "Buyer", soul: "Buy.", modelSelection: { instanceId: "codex", model: "gpt-5" } } },+ { action: "update", botId: "b-1", fields: { modelSelection: { instanceId: "codex", model: "gpt-5", effort: "high" } } },+ ]);+ });++ it("propose_team_setup keeps a real botId on create so the receiver still names the mistake", async () => {+ const calls: Array<{ path: string; body: any }> = [];+ const operations = [{ action: "create", key: "buyer", botId: "b-9", fields: { name: "Buyer" } }];+ await callTool("propose_team_setup", { reason: "r", operations }, recording(calls, { state: "applied" }));+ expect(calls[0].body.plan.operations).toEqual(operations);+ });++ it("create_bot drops blank effort and variant from the model choice", async () => {+ const calls: Array<{ path: string; body: any }> = [];+ await callTool("create_bot", { name: "Scout", role: "Ops", instructions: "Work.", modelSelection: { instanceId: "codex", model: "gpt-5", effort: "", variant: " " } },+ recording(calls, { id: "b1", name: "Scout" }));+ expect(calls[0].body.modelSelection).toEqual({ instanceId: "codex", model: "gpt-5" });+ });+});+describe("mcp_server", () => {it("posts the action and fields and returns the route's text for the model", async () => {const calls: Array<{ path: string; method?: string; body: unknown }> = [];diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.tsindex de223bffa5..85dbe570bd 100644--- a/server/drivers/agents-call.ts+++ b/server/drivers/agents-call.ts@@ -15,6 +15,7 @@ import type { HarnessClient, Json } from "./agents-client.ts";import { memorySearchText } from "./memory-search-text.ts";import { boundedAgentResult } from "./agents-result.ts";import { outOfBounds } from "./agents-schema.ts";+import { dropBlankArguments } from "./agents-blank-arguments.ts";import { callResearchTool, RESEARCH_TOOL_NAMES } from "./agents-research-tools.ts";import { callHelperTool, HELPER_TOOL_NAMES } from "./agents-helper-tools.ts";import { callUsageLimitsTool, USAGE_LIMITS_TOOL } from "./agents-usage-tool.ts";@@ -208,27 +209,6 @@ function recallWhen(at: unknown, dateOnly: boolean): string {return dateOnly ? day : `${day} ${pad(said.getHours())}:${pad(said.getMinutes())}`;}-/** The top-level arguments a model may fill with `""` (or spaces) when it means to leave them out, per tool. Only these:- * elsewhere a blank can be the value itself, such as a cleared room bulletin or a bot's private folder. */-const BLANK_MEANS_LEFT_OUT: Readonly<Record<string, readonly string[]>> = {- coordinate_bots: ["group_id", "reason", "thread", "title", "reply", "done_when", "answers"],- session_search: ["thread_id", "message_id", "query", "since", "until", "scope"],- show_html: ["html", "jsx", "path"],- // A blank text or old_text is a mistake the schema names, not "not given".- memory_update: ["until"],-};--function dropBlankArguments(name: string, input: Json): Json {- const keys = Object.hasOwn(BLANK_MEANS_LEFT_OUT, name) ? BLANK_MEANS_LEFT_OUT[name] : undefined;- if (!keys || !input || typeof input !== "object" || Array.isArray(input)) return input;- const out: Json = { ...input };- for (const key of keys) {- const value = out[key];- if (typeof value === "string" && !value.trim()) delete out[key];- }- return out;-}-export async function callTool(called: string, input: Json, context: ToolCallContext): Promise<ToolCallResult> {const { name, arguments: given } = resolveAgentsCall(called, input);const args = dropBlankArguments(name, given);