allow a max_subagents of 0: no subagents for the agent
This commit is contained in:
parent
7539ef82f7
commit
a1f99c77f8
7 changed files with 85 additions and 31 deletions
|
|
@ -21,6 +21,7 @@ import { SelectField } from "../../ui/select-field/SelectField.js";
|
|||
import { TextField } from "../../ui/text-field/TextField.js";
|
||||
import { Button } from "../../ui/button/Button.js";
|
||||
import "./AgentInference.css";
|
||||
import { MAX_SUBAGENTS, maxSubagentsValue } from "./max-subagents.js";
|
||||
|
||||
type Source = "swarm" | "agent_nix" | "local_file" | "default";
|
||||
|
||||
|
|
@ -67,18 +68,6 @@ function modelNameProblem(name: string): string | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
// The highest `max_subagents` the swarm accepts.
|
||||
const MAX_SUBAGENTS = 32;
|
||||
|
||||
// `max_subagents` as typed: empty is no cap, else a whole number in range.
|
||||
function maxSubagentsValue(text: string): number | null | undefined {
|
||||
const t = text.trim();
|
||||
if (t === "") return undefined;
|
||||
if (!/^\d+$/.test(t)) return null;
|
||||
const n = Number(t);
|
||||
return n >= 1 && n <= MAX_SUBAGENTS ? n : null;
|
||||
}
|
||||
|
||||
// Subagent models are typed as one list, split on commas and whitespace.
|
||||
function parseModels(text: string): string[] {
|
||||
return text.split(/[\s,]+/).filter((m) => m !== "");
|
||||
|
|
@ -112,7 +101,7 @@ export function draftProblem(d: InferenceDraft): string | null {
|
|||
.map(modelNameProblem)
|
||||
.find((p) => p !== null) ??
|
||||
(maxSubagentsValue(d.maxSubagents) === null
|
||||
? `max subagents is a whole number from 1 to ${MAX_SUBAGENTS}, or empty for no cap`
|
||||
? `max subagents is a whole number from 0 (no subagents) to ${MAX_SUBAGENTS}, or empty for no cap`
|
||||
: null)
|
||||
);
|
||||
}
|
||||
|
|
@ -273,7 +262,11 @@ export function AgentInference({ agent }: { agent: string }) {
|
|||
<li>
|
||||
<Badge
|
||||
label="max subagents"
|
||||
value={String(configured?.max_subagents ?? "no cap")}
|
||||
value={
|
||||
configured?.max_subagents === 0
|
||||
? "0 (no subagents)"
|
||||
: String(configured?.max_subagents ?? "no cap")
|
||||
}
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
17
frontend/packages/swarm-ui/src/agent/detail/max-subagents.ts
Normal file
17
frontend/packages/swarm-ui/src/agent/detail/max-subagents.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// The create form's and the inference dialog's `max_subagents` field, kept out
|
||||
// of the component so `npm test` can run it.
|
||||
|
||||
/** The highest `max_subagents` the swarm accepts. */
|
||||
export const MAX_SUBAGENTS = 32;
|
||||
|
||||
/**
|
||||
* `max_subagents` as typed: `undefined` for empty (no cap), the number for a
|
||||
* whole number from 0 (no subagents) to [`MAX_SUBAGENTS`], else `null`.
|
||||
*/
|
||||
export function maxSubagentsValue(text: string): number | null | undefined {
|
||||
const t = text.trim();
|
||||
if (t === "") return undefined;
|
||||
if (!/^\d+$/.test(t)) return null;
|
||||
const n = Number(t);
|
||||
return n <= MAX_SUBAGENTS ? n : null;
|
||||
}
|
||||
26
frontend/packages/swarm-ui/test/max-subagents.test.mjs
Normal file
26
frontend/packages/swarm-ui/test/max-subagents.test.mjs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// The max-subagents field: empty is no cap, 0 is no subagents, and anything
|
||||
// that is not a whole number up to the limit is refused. Run by `npm test`.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import {
|
||||
MAX_SUBAGENTS,
|
||||
maxSubagentsValue,
|
||||
} from "../src/agent/detail/max-subagents.ts";
|
||||
|
||||
test("empty is no cap, and 0 is a cap of none rather than empty", () => {
|
||||
assert.equal(maxSubagentsValue(""), undefined);
|
||||
assert.equal(maxSubagentsValue(" "), undefined);
|
||||
assert.equal(maxSubagentsValue("0"), 0);
|
||||
});
|
||||
|
||||
test("a whole number up to the limit is taken as typed", () => {
|
||||
assert.equal(maxSubagentsValue("1"), 1);
|
||||
assert.equal(maxSubagentsValue(" 3 "), 3);
|
||||
assert.equal(maxSubagentsValue(String(MAX_SUBAGENTS)), MAX_SUBAGENTS);
|
||||
});
|
||||
|
||||
test("above the limit, negative, fractional or not a number is refused", () => {
|
||||
for (const text of [String(MAX_SUBAGENTS + 1), "-1", "1.5", "abc", "1e1"]) {
|
||||
assert.equal(maxSubagentsValue(text), null, text);
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue