Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: edit an agent's inference in place, and move the resource caps to access

The inference section was one wrapping line of badges, with the CPU and
memory caps among them, and an edit button that opened the same fields in
a dialog. The editor is now the section itself: a line says what the
agent runs on now and where it comes from, and the fields sit in one row
where there is room, with save, reset and clear below. Unsaved edits are
kept per agent. The claude login and API key row stays below. The caps
are not inference settings, so they become a row of the access section.
This commit is contained in:
iris 2026-11-23 18:11:05 +01:00 • committed by mara
commit e4cab003d1
6 changed files with 376 additions and 305 deletions

View file

@ -111,9 +111,9 @@ store has the login, the dialog closes and a short toast in the top-right corner
says so. The credentials go to the agent through the secret store says so. The credentials go to the agent through the secret store
([`claude-login.md`](../../2-handbook/swarm/claude-login.md)). The agent's own ([`claude-login.md`](../../2-handbook/swarm/claude-login.md)). The agent's own
web UI login still works too. The **inference** section of an agent's details web UI login still works too. The **inference** section of an agent's details
has a **claude login** row: when the swarm stored the agent's login, or that has a **claude login** row: when the swarm stored the login, or that none is,
none is, with a **log in** button (**log in again** when the swarm holds one) with a **log in** button (**log in again** when the swarm holds one) that opens
that opens the same dialog, and a **delete login** action that asks first. the same dialog, and a **delete login** action that asks first.
A card shows its freshness when the agent isn't **fresh**: **stale** with how long ago the hive last A card shows its freshness when the agent isn't **fresh**: **stale** with how long ago the hive last
reported it, **never reported**, or **not in swarm identity**. A fresh agent shows nothing, so the reported it, **never reported**, or **not in swarm identity**. A fresh agent shows nothing, so the
@ -199,14 +199,13 @@ starts open, the other five folded:
shows its first five rows with a **show all N** button under them; expanded, shows its first five rows with a **show all N** button under them; expanded,
the rows scroll inside a box and **show fewer** folds them again. the rows scroll inside a box and **show fewer** folds them again.
- **instructions**: the agent's AGENTS.md, as an editor you can type in. - **instructions**: the agent's AGENTS.md, as an editor you can type in.
- **inference**: how the agent thinks and what it costs: its model and effort - **inference**: how the agent thinks and what it costs, as an editor in place:
and the other inference settings, its resource caps, and the claude login and its model and effort, the subagent settings and the two context limits, then
API key (the login's state, **log in**, and **set API key**), since the key is the claude login and API key (the login's state, **log in**, and **set API
how the agent reaches claude. key**), since the key is how the agent reaches claude.
- **access**: what the agent may reach: internet, allowed domains, repositories, - **access**: what the agent may reach and use: internet, allowed domains,
SSH and permissions. Internet, allowed domains, repositories, SSH and repositories, SSH, permissions and its resource caps. Each shows a badge;
permissions show a badge; select it to open the control that changes it select it to open the control that changes it (described below).
(described below).
- **accounts**: the agent's linked external accounts, and the menu that links - **accounts**: the agent's linked external accounts, and the menu that links
another. another.
@ -321,13 +320,13 @@ with no icon keeps the hyperhive mark. Everywhere else the swarm UI shows an age
The tab also has an agent badge, with the agent's icon (carrying the connection The tab also has an agent badge, with the agent's icon (carrying the connection
light) and name, ahead of the state badges. It opens the agent's details in a light) and name, ahead of the state badges. It opens the agent's details in a
popover under the badge: the same identity card and folded **instructions**, popover under the badge: the same identity card and folded **instructions**,
**inference**, **access** and **accounts** sections as the details on `/agents`, **inference**, **access** and **accounts** sections as the
without the terminal and the activity. The popover doesn't dim the page. details on `/agents`, without the terminal and the activity. The popover doesn't
Selecting outside it, or Escape, closes it. From the keyboard, opening a popover dim the page. Selecting outside it, or Escape, closes it. From the keyboard,
moves focus into it, and Escape puts focus back on the badge. The filter opening a popover moves focus into it, and Escape puts focus back on the badge.
popovers on table headers work the same way. You can stop or pause the agent, or The filter popovers on table headers work the same way. You can stop or pause
link an account, without leaving the terminal. A subagent's tab opens its the agent, or link an account, without leaving the terminal. A subagent's tab
agent's details. opens its agent's details.
#### Groups of terminals #### Groups of terminals
@ -882,29 +881,29 @@ text stays.
### Inference settings ### Inference settings
An agent's detail pane shows, in its **inference** section, its model and An agent's detail pane holds, in its **inference** section, the editor itself,
effort, each with where it comes from: the swarm, its agent.nix, its own pick, with no dialog: a line says what the agent runs on now and where the model and
or the default. Below them are the subagent model list the swarm sets, or "its the effort come from (the swarm, its agent.nix, its own pick, or the default),
own" when it sets none, the subagent cap, which reads "no cap" when unset, and and below it the fields sit in one row where there is room, filled with what the
the fresh-session threshold and the soft context limit, which each read "its swarm stores: model, effort, the subagent model list and the subagent cap.
own" when unset. **edit** opens a dialog with the fields, filled with what the **save** does a `PUT /api/agents/{agent}/inference` of the whole value, and is
swarm stores; saving does a `PUT /api/agents/{agent}/inference` of the whole off until a field changes. **reset** puts the boxes back to the stored value.
value. A field you leave empty stays out of it, so the agent keeps its own value Unsaved edits stay when you switch to another agent and come back. A field you
for that field; an empty max subagents is no cap, and the two context limits leave empty stays out of it, so the agent keeps its own value for that field; an
share one slider with two handles on the model's context window, from 5 to 100 empty max subagents is no cap, and the two context limits share one slider with
percent: a turn that finds the prompt cache cold starts a fresh session once the two handles on the model's context window, from 5 to 100 percent: a turn that
context passes the left (green) handle, and the agent compacts at the end of a finds the prompt cache cold starts a fresh session once the context passes the
turn once it passes the right (purple) one, and a turn can run past it. The left (green) handle, and the agent compacts at the end of a turn once it passes
handles can't cross. A handle the swarm hasn't set sits at the harness's own the right (purple) one, and a turn can run past it. The handles can't cross. A
value (50 and 75), dimmed; **use its own** on its line puts it back there, which handle the swarm hasn't set sits at the harness's own value (50 and 75), dimmed;
leaves that field out of the `PUT`. **clear the swarm's setting** sends the **use its own** on its line puts it back there, which leaves that field out of
`DELETE`. The model is a dropdown of the models the swarm already knows (`GET the `PUT`. **clear the swarm's setting** sends the `DELETE`. The model is a
/api/models`: those in any agent's stored settings and those the agents report dropdown of the models the swarm already knows (`GET /api/models`: those in any
running on), with the agent's own as the empty choice; **other…** opens a box agent's stored settings and those the agents report running on), with the
for any other model name, and a stored name the list lacks opens it too. The agent's own as the empty choice; **other…** opens a box for any other model
subagent models stay a typed list. The card reads `GET name, and a stored name the list lacks opens it too. The subagent models stay a
/api/agents/{agent}/inference`; before the agent's first report reaches the typed list. The editor reads `GET /api/agents/{agent}/inference`; before the
controller, it shows the swarm's stored values only. agent's first report reaches the controller, it shows no running line.
[inference](../swarm/inference.md) describes the settings themselves. [inference](../swarm/inference.md) describes the settings themselves.
### Editing an agent's instructions ### Editing an agent's instructions
@ -927,7 +926,7 @@ meanwhile. A reload of the page drops it.
### Resource caps ### Resource caps
An agent's detail pane shows, in its **inference** section, its CPU quota and An agent's detail pane shows, in its **access** section, its CPU quota and
memory max under **resource caps**. A cap is the swarm's, so it follows the memory max under **resource caps**. A cap is the swarm's, so it follows the
agent to whichever hive runs it, and it replaces what the hive says for that agent to whichever hive runs it, and it replaces what the hive says for that
field. A field the swarm leaves out shows as the hive deciding it. **edit** field. A field the swarm leaves out shows as the hive deciding it. **edit**
@ -1164,10 +1163,10 @@ reads back and its box starts with the stored text. The secrets never read back,
so their box starts empty and replaces the stored secrets only when filled and so their box starts empty and replaces the stored secrets only when filled and
saved. saved.
The **claude login** row of an agent's details also sets the API key: **set API key** The **claude login** row of an agent's details also sets the API key: **set API
(or **replace API key**) sends the key as `ANTHROPIC_API_KEY=<key>` to the key** (or **replace API key**) sends the key as `ANTHROPIC_API_KEY=<key>` to the
agent's secrets, **remove API key** deletes them, and **advanced** opens agent's secrets, **remove API key** deletes them, and **advanced** opens the
the form above. The row shows whether the store holds a key and never the key. A form above. The row shows whether the store holds a key and never the key. A
change reaches the agent at its next restart, and an agent with a key tries it change reaches the agent at its next restart, and an agent with a key tries it
instead of waiting for a claude login. instead of waiting for a claude login.

View file

@ -2,11 +2,11 @@
// is doing, `AgentIdentity`), then folded sections (`sections.ts`), one for // is doing, `AgentIdentity`), then folded sections (`sections.ts`), one for
// each question an operator comes with: the terminal, what it is working on // each question an operator comes with: the terminal, what it is working on
// (activity), its instructions, how it thinks (inference, which holds the // (activity), its instructions, how it thinks (inference, which holds the
// claude login and API key), what it may reach (access) and which accounts it // claude login and API key), what it may reach and use (access, which holds
// is linked to. Each section builds when first opened. In the details popover // the CPU and memory caps) and which accounts it is linked to. Each section
// on a terminal page (`AgentDetailPopover`) it is the identity card without // builds when first opened. In the details popover on a terminal page
// the name, then the four settings sections, since the page is already beside // (`AgentDetailPopover`) it is the identity card without the name, then the
// a terminal. // four settings sections, since the page is already beside a terminal.
// //
// Takes the agent's *live* row and the shared `AgentActions`, so a state // Takes the agent's *live* row and the shared `AgentActions`, so a state
// change or a link made here shows wherever else the same row is drawn. // change or a link made here shows wherever else the same row is drawn.
@ -15,7 +15,11 @@ import { Hint } from "../../ui/hint/Hint.js";
import type { AgentActions } from "../roster/AgentActions.js"; import type { AgentActions } from "../roster/AgentActions.js";
import { AgentApiKey } from "./AgentApiKey.js"; import { AgentApiKey } from "./AgentApiKey.js";
import { AgentClaudeLogin } from "./AgentClaudeLogin.js"; import { AgentClaudeLogin } from "./AgentClaudeLogin.js";
import { AgentInference } from "./AgentInference.js"; import {
AgentInference,
InferencePair,
InferenceRows,
} from "./AgentInference.js";
import { AgentInstructions } from "./AgentInstructions.js"; import { AgentInstructions } from "./AgentInstructions.js";
import { AgentLimits } from "./AgentLimits.js"; import { AgentLimits } from "./AgentLimits.js";
import { AgentSsh } from "./AgentSsh.js"; import { AgentSsh } from "./AgentSsh.js";
@ -43,27 +47,17 @@ import { BashTasks } from "../terminal/BashTasks.js";
import { SubagentTerms } from "../terminal/SubagentTerms.js"; import { SubagentTerms } from "../terminal/SubagentTerms.js";
import "./AgentDetail.css"; import "./AgentDetail.css";
function InferenceRows({ // How the agent signs in to claude: the login and, on a hive, its API key.
agent, function ClaudeRows({ agent, hive }: { agent: string; hive: string | null }) {
hive,
}: {
agent: string;
hive: string | null;
}) {
return ( return (
<> <InferenceRows>
<dt>resource caps</dt> <InferencePair label="claude login">
<dd>
<AgentLimits key={agent} agent={agent} />
</dd>
<dt>claude login</dt>
<dd>
<AgentClaudeLogin key={agent} agent={agent} /> <AgentClaudeLogin key={agent} agent={agent} />
{hive ? ( {hive ? (
<AgentApiKey key={`${hive}/${agent}`} hive={hive} agent={agent} /> <AgentApiKey key={`${hive}/${agent}`} hive={hive} agent={agent} />
) : null} ) : null}
</dd> </InferencePair>
</> </InferenceRows>
); );
} }
@ -168,15 +162,17 @@ function SectionBody({
return ( return (
<> <>
<AgentInference key={row.name} agent={row.name} /> <AgentInference key={row.name} agent={row.name} />
<dl class="ui-agent-detail-fields"> <ClaudeRows agent={row.name} hive={row.hive} />
<InferenceRows agent={row.name} hive={row.hive} />
</dl>
</> </>
); );
case "access": case "access":
return ( return (
<dl class="ui-agent-detail-fields"> <dl class="ui-agent-detail-fields">
<GrantRows key={row.name} agent={row.name} /> <GrantRows key={row.name} agent={row.name} />
<dt>resource caps</dt>
<dd>
<AgentLimits key={row.name} agent={row.name} />
</dd>
</dl> </dl>
); );
case "accounts": case "accounts":

View file

@ -1,22 +1,42 @@
/* <AgentInference> — the settings in one wrapping line: each badge, then where it comes from. */ /* <AgentInference> — the settings as labelled values, two to a line where there
is room, each value followed by where it comes from. */
.ui-agent-inference { .ui-agent-inference {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: flex-start; align-items: flex-start;
gap: 0.3em; gap: 0.5em;
} }
.ui-agent-inference-list { .ui-agent-inference-rows {
display: contents; display: grid;
list-style: none; grid-template-columns: repeat(auto-fit, minmax(22em, 1fr));
gap: 0.3em 2em;
align-self: stretch;
margin: 0; margin: 0;
padding: 0;
} }
.ui-agent-inference-list li { .ui-agent-inference-pair {
display: contents; display: grid;
grid-template-columns: 12em minmax(0, 1fr);
gap: 0 1em;
} }
.ui-agent-inference-source { .ui-agent-inference-pair dt {
margin-left: -0.25em; color: var(--muted);
}
.ui-agent-inference-pair dd {
margin: 0;
} }
.ui-agent-inference-source { .ui-agent-inference-source {
color: var(--muted); color: var(--muted);
} }
.ui-agent-inference-now {
margin: 0;
}
.ui-agent-inference .ui-form-stack {
align-items: stretch;
align-self: stretch;
max-width: 60em;
margin-top: 0;
}
/* The claude login row under the editor. */
.ui-agent-inference + .ui-agent-inference-rows {
margin-top: 1em;
}

View file

@ -1,29 +1,28 @@
// <AgentInference> — one agent's inference settings in an agent's details: the // <AgentInference> — one agent's inference settings in an agent's details, as
// model and effort it runs on now, with where each came from, and an editor // the editor itself: boxes filled with the value the swarm stores, and above
// for the value the swarm sets. // them the model and effort the agent runs on now, with where each came from.
// //
// Reads `GET /api/agents/{name}/inference`, which answers // Reads `GET /api/agents/{name}/inference`, which answers
// `{ configured, effective }`: `configured` is the swarm's stored value (null // `{ configured, effective }`: `configured` is the swarm's stored value (null
// when none), `effective` what the agent reported running on (null until its // when none), `effective` what the agent reported running on (null until its
// first report reaches the controller). The editor PUTs the whole value and // first report reaches the controller). Save PUTs the whole value and the clear
// the clear action DELETEs it; a cleared field puts the agent back on its own // action DELETEs it; a cleared field puts the agent back on its own value,
// value, which is why an empty field is left out of the body rather than sent. // which is why an empty field is left out of the body rather than sent. Unsaved
// edits are kept per agent, so switching to another agent and back keeps them.
// //
// Its state belongs to one agent: callers key it by agent name, so switching // Its state belongs to one agent: callers key it by agent name, so switching
// agents remounts it instead of showing the previous agent's settings. // agents remounts it instead of showing the previous agent's settings.
import { useEffect, useState } from "preact/hooks"; import type { ComponentChildren } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js"; import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
import { Badge } from "@hive/shared/badge.js";
import { ActionRow } from "../../ui/action-row/ActionRow.js"; import { ActionRow } from "../../ui/action-row/ActionRow.js";
import { Dialog } from "../../ui/dialog/Dialog.js"; import { FieldGrid, FieldGridFull } from "../../ui/field-grid/FieldGrid.js";
import { Hint } from "../../ui/hint/Hint.js"; import { Hint } from "../../ui/hint/Hint.js";
import { Panel } from "../../ui/panel/Panel.js";
import { SelectField } from "../../ui/select-field/SelectField.js"; import { SelectField } from "../../ui/select-field/SelectField.js";
import { TextField } from "../../ui/text-field/TextField.js"; import { TextField } from "../../ui/text-field/TextField.js";
import { Button } from "../../ui/button/Button.js"; import { Button } from "../../ui/button/Button.js";
import { FormStack } from "../../ui/form-stack/FormStack.js"; import { FormStack } from "../../ui/form-stack/FormStack.js";
import "../../ui/badge-row/BadgeRow.css";
import "./AgentInference.css"; import "./AgentInference.css";
import { ContextLimits } from "./ContextLimits.js"; import { ContextLimits } from "./ContextLimits.js";
import { import {
@ -33,6 +32,13 @@ import {
modelSelectValue, modelSelectValue,
useKnownModels, useKnownModels,
} from "./model-choice.js"; } from "./model-choice.js";
import {
draftOf,
EMPTY_INFERENCE_DRAFT,
rememberDraft,
sameDraft,
type InferenceDraft,
} from "./inference-draft.js";
import { MAX_SUBAGENTS, maxSubagentsValue } from "./max-subagents.js"; import { MAX_SUBAGENTS, maxSubagentsValue } from "./max-subagents.js";
import { import {
MAX_SOFT_CONTEXT_PERCENT, MAX_SOFT_CONTEXT_PERCENT,
@ -97,25 +103,7 @@ function inferenceUrl(agent: string): string {
return `/api/agents/${encodeURIComponent(agent)}/inference`; return `/api/agents/${encodeURIComponent(agent)}/inference`;
} }
// The inference boxes as typed. Shared by the editor here and the export { EMPTY_INFERENCE_DRAFT, type InferenceDraft };
// create-agent form, which send what `draftBody` makes of them.
export interface InferenceDraft {
model: string;
effort: string;
subagents: string;
maxSubagents: string;
softContext: string;
freshSession: string;
}
export const EMPTY_INFERENCE_DRAFT: InferenceDraft = {
model: "",
effort: "",
subagents: "",
maxSubagents: "",
softContext: "",
freshSession: "",
};
// Why the draft would be refused, or null when it is fine to send. // Why the draft would be refused, or null when it is fine to send.
export function draftProblem(d: InferenceDraft): string | null { export function draftProblem(d: InferenceDraft): string | null {
@ -220,6 +208,7 @@ export function InferenceFields({
const problem = draftProblem(draft); const problem = draftProblem(draft);
return ( return (
<> <>
<FieldGrid>
<ModelField <ModelField
id={`${idPrefix}-model`} id={`${idPrefix}-model`}
value={draft.model} value={draft.model}
@ -247,23 +236,70 @@ export function InferenceFields({
pattern="[0-9]*" pattern="[0-9]*"
onInput={(maxSubagents) => onChange({ ...draft, maxSubagents })} onInput={(maxSubagents) => onChange({ ...draft, maxSubagents })}
/> />
<FieldGridFull>
<ContextLimits <ContextLimits
idPrefix={idPrefix} idPrefix={idPrefix}
fresh={draft.freshSession} fresh={draft.freshSession}
soft={draft.softContext} soft={draft.softContext}
onChange={(limits) => onChange({ ...draft, ...limits })} onChange={(limits) => onChange({ ...draft, ...limits })}
/> />
</FieldGridFull>
</FieldGrid>
{problem ? <Hint tone="error">{problem}</Hint> : null} {problem ? <Hint tone="error">{problem}</Hint> : null}
</> </>
); );
} }
/** Labelled values, two to a line where there is room. */
export function InferenceRows({ children }: { children: ComponentChildren }) {
return <dl class="ui-agent-inference-rows">{children}</dl>;
}
/** One label and its value. */
export function InferencePair({
label,
title,
valueTitle,
children,
}: {
label: string;
/** What the setting does, on the label. */
title?: string;
/** Why the value is what it is, on the value. */
valueTitle?: string;
children: ComponentChildren;
}) {
return (
<div class="ui-agent-inference-pair">
<dt title={title}>{label}</dt>
<dd title={valueTitle}>{children}</dd>
</div>
);
}
// Where a value came from, after the value.
function Source({ source }: { source: Source }) {
return (
<span class="ui-agent-inference-source"> ({SOURCE_LABEL[source]})</span>
);
}
// The unsaved edits of this visit, by agent: switching to another agent and
// back keeps what was typed. Read once when an agent's editor mounts and
// written as the draft changes.
const drafts = new Map<string, InferenceDraft>();
export function AgentInference({ agent }: { agent: string }) { export function AgentInference({ agent }: { agent: string }) {
const [view, setView] = useState<View | null>(null); const [view, setView] = useState<View | null>(null);
const [error, setError] = useState<ProblemDetails | null>(null); const [error, setError] = useState<ProblemDetails | null>(null);
// Bumped after a save or a clear, so the settings are fetched again. // Bumped after a save or a clear, so the settings are fetched again.
const [reload, setReload] = useState(0); const [reload, setReload] = useState(0);
const [editing, setEditing] = useState(false); const [draft, setDraft] = useState<InferenceDraft | null>(null);
const [busy, setBusy] = useState(false);
const [problem, setProblem] = useState<ProblemDetails | null>(null);
// Set by a save or a clear: the next read replaces the boxes with the stored
// value instead of keeping the typed one.
const resetOnLoad = useRef(false);
useEffect(() => { useEffect(() => {
let cancelled = false; let cancelled = false;
@ -275,9 +311,14 @@ export function AgentInference({ agent }: { agent: string }) {
} }
const body = (await r.json()) as Partial<View>; const body = (await r.json()) as Partial<View>;
if (cancelled) return; if (cancelled) return;
setView({ const configured = body.configured ?? null;
configured: body.configured ?? null, setView({ configured, effective: body.effective ?? null });
effective: body.effective ?? null, setDraft((current) => {
if (resetOnLoad.current || current === null) {
resetOnLoad.current = false;
return drafts.get(agent) ?? draftOf(configured);
}
return current;
}); });
setError(null); setError(null);
})().catch((e: unknown) => { })().catch((e: unknown) => {
@ -288,6 +329,13 @@ export function AgentInference({ agent }: { agent: string }) {
}; };
}, [agent, reload]); }, [agent, reload]);
const base = view === null ? null : draftOf(view.configured);
const dirty = draft !== null && base !== null && !sameDraft(draft, base);
useEffect(() => {
if (draft === null || base === null) return;
rememberDraft(drafts, agent, draft, base);
}, [agent, draft, base]);
// Shown as text, not a hover title. Settings already loaded stay under a // Shown as text, not a hover title. Settings already loaded stay under a
// failed refetch, so a save that worked is not hidden by a read that did not. // failed refetch, so a save that worked is not hidden by a read that did not.
const errorPanel = error ? ( const errorPanel = error ? (
@ -296,155 +344,25 @@ export function AgentInference({ agent }: { agent: string }) {
problem={error} problem={error}
/> />
) : null; ) : null;
if (view === null) { if (view === null || draft === null || base === null) {
return errorPanel ?? <Hint as="span">…</Hint>; return errorPanel ?? <Hint as="span">…</Hint>;
} }
const { configured, effective } = view; const { configured, effective } = view;
const swarmModels = configured?.subagent_models ?? [];
return (
<div class="ui-agent-inference">
{errorPanel}
<div class="ui-badge-row">
<ul class="ui-agent-inference-list">
<li>
{effective ? (
<>
<Badge label="model" value={effective.model} />
<span class="ui-agent-inference-source">
{SOURCE_LABEL[effective.model_source]}
</span>
</>
) : (
<Badge
label="model"
value={configured?.model ?? "its own"}
title="the agent has not reported what it runs on yet"
/>
)}
</li>
<li>
{effective ? (
<>
<Badge label="effort" value={effective.effort} />
<span class="ui-agent-inference-source">
{SOURCE_LABEL[effective.effort_source]}
</span>
</>
) : (
<Badge
label="effort"
value={configured?.effort ?? "its own"}
title="the agent has not reported what it runs on yet"
/>
)}
</li>
<li>
<Badge
label="subagent models"
value={
swarmModels.length > 0 ? swarmModels.join(", ") : "its own"
}
/>
</li>
<li>
<Badge
label="max subagents"
value={
configured?.max_subagents === 0
? "0 (no subagents)"
: String(configured?.max_subagents ?? "no cap")
}
/>
</li>
<li>
<Badge
label="fresh-session threshold"
value={
configured?.fresh_session_percent === undefined
? "its own"
: `${configured.fresh_session_percent}%`
}
title="a turn that finds the prompt cache cold starts a fresh session once the context is past this share of the window"
/>
</li>
<li>
<Badge
label="soft context limit"
value={
configured?.soft_context_percent === undefined
? "its own"
: `${configured.soft_context_percent}%`
}
title="the agent compacts at the end of a turn once its context passes this share of the window; a turn can run past it"
/>
</li>
</ul>
<Badge
variant="quiet"
value="edit"
ariaLabel={`edit ${agent}'s inference settings`}
title={`set the swarm's model, effort, subagent models, subagent cap and context limits for ${agent}`}
onClick={() => setEditing(true)}
/>
</div>
<Dialog
open={editing}
onClose={() => setEditing(false)}
label="edit inference settings"
plain
>
{/* Remounted per open, so a cancelled edit leaves nothing behind. */}
{editing ? (
<InferenceForm
agent={agent}
configured={configured}
onClose={() => setEditing(false)}
onSaved={() => {
setEditing(false);
setReload((n) => n + 1);
}}
/>
) : null}
</Dialog>
</div>
);
}
function InferenceForm({
agent,
configured,
onClose,
onSaved,
}: {
agent: string;
configured: Settings | null;
onClose: () => void;
onSaved: () => void;
}) {
const [draft, setDraft] = useState<InferenceDraft>({
model: configured?.model ?? "",
effort: configured?.effort ?? "",
subagents: (configured?.subagent_models ?? []).join(", "),
maxSubagents: configured?.max_subagents?.toString() ?? "",
softContext: configured?.soft_context_percent?.toString() ?? "",
freshSession: configured?.fresh_session_percent?.toString() ?? "",
});
const [busy, setBusy] = useState(false);
const [problem, setProblem] = useState<ProblemDetails | null>(null);
const formProblem = draftProblem(draft); const formProblem = draftProblem(draft);
const empty = draftIsEmpty(draft);
async function send(init: RequestInit) { async function send(init: RequestInit) {
setBusy(true); setBusy(true);
setProblem(null);
try { try {
const r = await fetch(inferenceUrl(agent), init); const r = await fetch(inferenceUrl(agent), init);
if (!r.ok) { if (!r.ok) {
setProblem(await readApiError(r)); setProblem(await readApiError(r));
return; return;
} }
onSaved(); drafts.delete(agent);
resetOnLoad.current = true;
setReload((n) => n + 1);
} catch (e: unknown) { } catch (e: unknown) {
setProblem({ detail: String(e) }); setProblem({ detail: String(e) });
} finally { } finally {
@ -457,23 +375,20 @@ function InferenceForm({
void send({ void send({
method: "PUT", method: "PUT",
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
body: JSON.stringify(draftBody(draft)), body: JSON.stringify(draftBody(draft as InferenceDraft)),
}); });
} }
return ( return (
<Panel title={`inference — ${agent}`} icon="🧠" onClose={onClose}> <div class="ui-agent-inference">
<p> {errorPanel}
Sets what the swarm makes {agent} run on. A field left empty stays the {effective ? (
agent's own value; an empty max subagents is no cap. The two context <Hint class="ui-agent-inference-now">
limits are shares of the context window: a turn that finds the prompt running {effective.model}
cache cold starts a fresh session once the context is past the <Source source={effective.model_source} />, effort {effective.effort}
fresh-session threshold, and the agent compacts at the end of a turn <Source source={effective.effort_source} />
once it is past the soft limit (a turn can run past it). The agent picks </Hint>
a change up within seconds; a turn already running finishes on what it ) : null}
started with, and subagents already running past a lowered cap keep
running.
</p>
<FormStack onSubmit={save}> <FormStack onSubmit={save}>
<InferenceFields draft={draft} onChange={setDraft} /> <InferenceFields draft={draft} onChange={setDraft} />
{problem ? ( {problem ? (
@ -483,18 +398,28 @@ function InferenceForm({
<Button <Button
variant="primary" variant="primary"
type="submit" type="submit"
disabled={busy || empty || formProblem !== null} busy={busy}
disabled={
busy || !dirty || draftIsEmpty(draft) || formProblem !== null
}
> >
{busy ? "saving…" : "save"} save
</Button> </Button>
{dirty ? (
<Button disabled={busy} onClick={() => setDraft(base)}>
reset
</Button>
) : null}
{configured !== null ? (
<Button <Button
disabled={busy || configured === null} disabled={busy}
onClick={() => void send({ method: "DELETE" })} onClick={() => void send({ method: "DELETE" })}
> >
clear the swarm's setting clear the swarm's setting
</Button> </Button>
) : null}
</ActionRow> </ActionRow>
</FormStack> </FormStack>
</Panel> </div>
); );
} }

View file

@ -0,0 +1,72 @@
// The inference boxes as typed, and the bookkeeping around them, without a DOM:
// what a stored value fills them with, whether they differ from it, and which
// unsaved drafts are kept while the operator looks at another agent. Shared by
// the editor in an agent's details and the create-agent form.
/** The inference boxes as typed; every one is text, empty for "its own". */
export interface InferenceDraft {
model: string;
effort: string;
subagents: string;
maxSubagents: string;
softContext: string;
freshSession: string;
}
export const EMPTY_INFERENCE_DRAFT: InferenceDraft = {
model: "",
effort: "",
subagents: "",
maxSubagents: "",
softContext: "",
freshSession: "",
};
/** The swarm's stored value, every field optional. */
export interface StoredInference {
model?: string;
effort?: string;
subagent_models?: string[];
max_subagents?: number;
soft_context_percent?: number;
fresh_session_percent?: number;
}
/** The boxes as a stored value fills them; none stored fills them empty. */
export function draftOf(stored: StoredInference | null): InferenceDraft {
return {
model: stored?.model ?? "",
effort: stored?.effort ?? "",
subagents: (stored?.subagent_models ?? []).join(", "),
maxSubagents: stored?.max_subagents?.toString() ?? "",
softContext: stored?.soft_context_percent?.toString() ?? "",
freshSession: stored?.fresh_session_percent?.toString() ?? "",
};
}
/** Whether two drafts hold the same text in every box. */
export function sameDraft(a: InferenceDraft, b: InferenceDraft): boolean {
return (
a.model === b.model &&
a.effort === b.effort &&
a.subagents === b.subagents &&
a.maxSubagents === b.maxSubagents &&
a.softContext === b.softContext &&
a.freshSession === b.freshSession
);
}
/**
* Keeps `draft` as this agent's unsaved edit while it differs from `base`
* (what the swarm stores), and drops the kept one when it doesn't, so an agent
* with nothing unsaved leaves nothing behind.
*/
export function rememberDraft(
kept: Map<string, InferenceDraft>,
agent: string,
draft: InferenceDraft,
base: InferenceDraft,
): void {
if (sameDraft(draft, base)) kept.delete(agent);
else kept.set(agent, draft);
}

View file

@ -0,0 +1,59 @@
// The inference boxes and the drafts kept per agent. Run by `npm test`, which
// Node runs with its built-in test runner and type stripping.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
EMPTY_INFERENCE_DRAFT,
draftOf,
rememberDraft,
sameDraft,
} from "../src/agent/detail/inference-draft.ts";
const stored = {
model: "sonnet",
effort: "high",
subagent_models: ["haiku", "sonnet"],
max_subagents: 0,
soft_context_percent: 70,
fresh_session_percent: 40,
};
test("a stored value fills the boxes, and none stored fills them empty", () => {
assert.deepEqual(draftOf(stored), {
model: "sonnet",
effort: "high",
subagents: "haiku, sonnet",
maxSubagents: "0",
softContext: "70",
freshSession: "40",
});
assert.deepEqual(draftOf(null), EMPTY_INFERENCE_DRAFT);
assert.deepEqual(draftOf({}), EMPTY_INFERENCE_DRAFT);
});
test("drafts are the same only when every box matches", () => {
const base = draftOf(stored);
assert.ok(sameDraft(base, { ...base }));
for (const box of Object.keys(base)) {
assert.ok(!sameDraft(base, { ...base, [box]: base[box] + "x" }), box);
}
});
test("an edited draft is kept for its agent, and dropped once it matches again", () => {
const kept = new Map();
const base = draftOf(stored);
const edited = { ...base, effort: "low" };
rememberDraft(kept, "iris", edited, base);
assert.deepEqual(kept.get("iris"), edited);
rememberDraft(kept, "iris", { ...base }, base);
assert.equal(kept.has("iris"), false);
});
test("one agent's draft does not touch another's", () => {
const kept = new Map();
const base = draftOf(stored);
rememberDraft(kept, "iris", { ...base, model: "opus" }, base);
rememberDraft(kept, "argus", { ...base }, base);
assert.equal(kept.size, 1);
assert.equal(kept.get("iris").model, "opus");
});