Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ if that desktop app is up and running.
accounts or permissions.
- **Sessions.** By default an agent starts a fresh conversation for each
thread. Its settings can make it one per channel or one per community.
- **Auto models.** Some builds add choices such as **Auto Balanced** to the
Model menu of Claude Code, Codex and Goose agents. Before each new turn, the build
picks a model and thinking level for that message, and the turn's activity
says which and why. A message sent while the agent is working keeps its
model, and a model chosen beside Send still wins.
- **While it works**, the agent shows typing dots, and you can stop it. If it
can't finish, it says why and offers **Retry**.
- **Your default agent** (your Bestie) answers new chats and `ask:` searches.
Expand Down
20 changes: 20 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ A bundled plugin can replace the setup per launch with
`ctx.agents.recommend(source)`, for example per team. Buzz waits up to five
seconds for it, then falls back to `BUZZ_RECOMMENDED_AGENT`, so set both.

A bundled plugin can also add **model routes**, such as "Auto Balanced", to the
Claude Code, Codex and Goose Model menus with `ctx.agents.registerModelRouter(router)`.
An agent on a route runs with `route:<id>` as its model, but no copy of its
settings stores that. Its synced settings revision keeps the route beside
`settings`, as `"modelRoute": "<id>"`, with an empty `model`, and its saved
record keeps it beside `config` the same way. A catalog share keeps it as
`model_route` and an exported snapshot as `modelRoute`, with no `model`. Older
versions run the harness's default. A model saved by an older version takes
the agent off the route. Before each turn it starts
while idle in a conversation, Buzz asks `router.select` for one of the
harness's models and a thinking level. A turn that steers a running one keeps
its pick, and a failure or no answer within 30 seconds uses the route's
fallback. The router can ask for the conversation's earlier messages
(`request.history()`) and for what Buzz already holds about the turn
(`request.context()`): what started it, the agent's instructions, skills and
workspace, attached files, and the conversation's last routed pick with when
that turn ended. Buzz runs no git or GitHub calls for either. The router can
also choose the route new agents and Automatic agents use. See
`src/features/agents/model-routes.ts`.

## Federated identity build input

A build trusts a compiled list of sign-in servers. Each community is matched by
Expand Down
42 changes: 42 additions & 0 deletions src/bundled/agents/AgentCreateDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import {
uploadAvatar,
} from "../../features/profiles/avatar-upload";
import { CHECK_MS } from "../../features/agents/recommended";
import {
resetModelRoutesForTests,
setModelRouters,
} from "../../features/agents/model-routes";
import { AgentCreateDialog } from "./AgentCreateDialog";
import {
BuilderlabLogoIcon,
Expand Down Expand Up @@ -2252,6 +2256,44 @@ describe("Recommended setup", () => {
);
});

it("starts Custom on the Automatic route when a plugin offers one", async () => {
setModelRouters([
{
id: "test",
routes: (id) =>
id === "codex"
? {
routes: [{ id: "auto-a", label: "Auto A" }],
automatic: "auto-a",
}
: undefined,
select: async () => undefined,
},
]);
try {
const { agents, dialog, user } = setup([echo, goose, codex]);
await inspectModel(user, dialog, "Auto A");
await chooseCustom(user, dialog);
expect(harnessSelect(dialog)).toHaveTextContent("Codex");
await user.type(within(dialog).getByLabelText("Name"), "Agent A");
await user.click(createButton());
// The route, not the candidate it would have started on.
expect(agents.create).toHaveBeenCalledWith(
expect.objectContaining({
type: "test/codex",
config: {
notes: "start",
instructions: "Be brief.",
model: "route:auto-a",
effort: "",
},
}),
);
} finally {
resetModelRoutesForTests();
}
});

it("lets the owner choose manually while the pick is still running, even with one harness", async () => {
let finish = (_ready: boolean) => {};
const slow = harness(
Expand Down
46 changes: 34 additions & 12 deletions src/bundled/agents/AgentCreateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ import {
import {
AISettings,
Checking,
RouteLine,
UsesLine,
} from "../../features/agents/AISettings";
import {
activeRoute,
routeModel,
useModelRoutes,
} from "../../features/agents/model-routes";
import {
bounded,
followRecommended,
Expand Down Expand Up @@ -357,6 +363,9 @@ export function AgentCreateDialog({
const [asked, setAsked] = useState(0);
const recommendation = useRecommendedPick(types, recommendable, asked);
const { pick } = recommendation.status === "found" ? recommendation : {};
// A plugin's route that Automatic runs on for the pick's harness.
useModelRoutes(pick?.type.id ?? "");
const automaticRoute = pick && activeRoute(pick.type.id, "", true);
// No local harness can run an Automatic agent here: one thing to set up.
const nothingSetUp =
automatic && recommendable && recommendation.status === "none";
Expand Down Expand Up @@ -458,15 +467,20 @@ export function AgentCreateDialog({
// While the pick runs, its effect takes the harness once known.
if (on && pick && pick.type.key !== type?.key)
chooseModel(pick.type, carried(pick.type));
// Manual starts from what Automatic picked.
if (!on && pick && pick.type.key === type?.key)
// Manual starts from what Automatic picked: its route, when a plugin
// offers one, on the candidate's provider.
if (!on && pick && pick.type.key === type?.key) {
const picked = followRecommended(
withRecommended(config as object),
config as { model: string; effort: string },
pick.candidate,
);
setConfig(
followRecommended(
withRecommended(config as object),
config as { model: string; effort: string },
pick.candidate,
),
automaticRoute
? { ...picked, model: routeModel(automaticRoute.id), effort: "" }
: picked,
);
}
};
// Automatic has nothing to create with until, and unless, a pick is found.
const waiting = automatic && !type?.remote && !pick;
Expand Down Expand Up @@ -805,7 +819,7 @@ export function AgentCreateDialog({
<AISettings
automatic={automatic}
harnessIcon={automatic ? pick?.type.icon : type?.icon}
modelName={pick?.candidate.label}
modelName={automaticRoute?.label ?? pick?.candidate.label}
disabled={pending}
onChange={chooseAutomatic}
summary={
Expand All @@ -814,13 +828,21 @@ export function AgentCreateDialog({
) : undefined
}
model={
pick && (
<UsesLine
automaticRoute ? (
<RouteLine
icon={pick.type.icon}
title={pick.type.title}
candidate={pick.candidate}
skipped={pick.skipped[0]?.title}
route={automaticRoute}
/>
) : (
pick && (
<UsesLine
icon={pick.type.icon}
title={pick.type.title}
candidate={pick.candidate}
skipped={pick.skipped[0]?.title}
/>
)
)
}
>
Expand Down
1 change: 1 addition & 0 deletions src/bundled/agents/AgentsPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ function setup(
controlAttention: () => {},
recommend: () => {},
gatewayHarnesses: () => {},
registerModelRouter: () => {},
registerSessionRouter: () => {},
registerExecution: () => {},
bindExecution: async () => {},
Expand Down
15 changes: 12 additions & 3 deletions src/bundled/claude-code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ClaudeLogoIcon } from "../../shared/design-system/icons";
import { claudeRun, TYPE_ID } from "./run";
import {
followRecommended,
onAutomatic,
recommendedRun,
} from "../../features/agents/recommended";
import type { AgentHandle } from "../../features/agents/service";
Expand All @@ -25,6 +26,7 @@ import { ClaudeRuntime, type Config, config, DEFAULT_CONFIG } from "./runtime";
import { ClaudeSetup, withScript } from "./setup";
import { createTabs } from "./tabs";
import { targetKey } from "../../features/navigation/targets";
import { activeRoute, routeLabel } from "../../features/agents/model-routes";
import type { ClaudeConnection } from "./ClaudeSettings";
import { readUsage } from "./usage";
import { usageOn } from "../../features/agents/standalone-sessions";
Expand Down Expand Up @@ -296,12 +298,19 @@ export const apply: PluginModule["apply"] = (ctx) => {
{ id: "thinking", label: "Thinking", isOverride: Boolean(effort) },
];
},
summary: (agent) =>
followRecommended(
summary: (agent) => {
const { model } = followRecommended(
agent.config,
config(agent.config),
recommended.current(),
).model || "Claude",
);
return (
activeRoute(TYPE_ID, model, onAutomatic(agent.config, TYPE_ID))
?.label ??
routeLabel(TYPE_ID, model) ??
(model || "Claude")
);
},
...(spawn &&
readFile && {
usage: async (agent, { since, signal }) => {
Expand Down
15 changes: 13 additions & 2 deletions src/bundled/claude-code/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "../../features/agent-harness/session-scope";
import { protectionTranscript } from "./protection-transcript";
import { compactAt } from "../../features/agents/compact-at";
import { launchModel, routeOf } from "../../features/agents/model-routes";
import type { PRESET } from "../../features/agents/recommended";
import { fileStore } from "../../features/agents/state";
import type { AgentExecution } from "../../features/agents/execution";
Expand Down Expand Up @@ -271,9 +272,11 @@ type Entry = {
* compaction. */
const where = ({ workspace, model, effort, ...config }: Config) => {
const tokens = compactAt(config.compactAt);
// A saved model route picks per turn; the process starts on the default.
const launch = launchModel(model.trim());
return {
cwd: workspace,
...(model.trim() ? { model: model.trim() } : {}),
...(launch ? { model: launch } : {}),
...(effort ? { effort } : {}),
...(tokens ? { compactAt: tokens } : {}),
};
Expand Down Expand Up @@ -761,7 +764,8 @@ export class ClaudeRuntime {
/** `models`, saying whether Claude itself lists the current model. */
private async catalog(agent: AgentKey) {
const entry = this.agents.get(agent);
const configured = entry?.config.model.trim();
const saved = entry?.config.model.trim();
const configured = saved && launchModel(saved);
const {
models: listed,
model: reported,
Expand All @@ -781,6 +785,9 @@ export class ClaudeRuntime {
...resting(offeredEfforts),
};
});
// A saved route is the current choice; the agents service lists it.
if (saved && routeOf(saved))
return { current: saved, models, listed: true };
const current =
offered.find(
(model) => own === model.value || own === model.resolvedModel,
Expand Down Expand Up @@ -1277,6 +1284,7 @@ export class ClaudeRuntime {
channelId,
model,
effort,
route: chooseModel,
synced,
team,
workingUntil,
Expand Down Expand Up @@ -1632,6 +1640,7 @@ export class ClaudeRuntime {
...(model ? { model } : {}),
...(effort ? { effort } : {}),
},
...(chooseModel ? { route: chooseModel } : {}),
admit,
// Mentions already show the host's fallback under the request.
...this.turnAttribution(
Expand Down Expand Up @@ -1986,6 +1995,8 @@ export class ClaudeRuntime {
private async refusal(agent: AgentKey, kept: string | undefined) {
if (!kept) return undefined;
const { current, models, listed } = await this.catalog(agent);
// A route picks its own effort each turn.
if (routeOf(current)) return undefined;
const own = models.find((model) => model.id === current);
// A model Claude doesn't list has no levels to check the effort against.
if (!listed || !own)
Expand Down
30 changes: 30 additions & 0 deletions src/bundled/claude-code/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,36 @@ it("runs a turn with the model and effort it was delivered with, starting over i
expect(fresh?.efforts).toEqual(["low", "high"]);
});

it("asks a model route for a new turn's pick, and not for a steer", async () => {
const { pool, claudes } = sessions({ hold: true });
const route = vi.fn(async () => ({ model: "haiku", effort: "low" }));
const first = pool.deliver("c/root", "first", 1, { route });
await flush();
const process = claudes()[0];
if (!process) throw new Error("no process");
const steer = vi.fn(async () => ({ model: "sonnet" }));
const second = pool.deliver("c/root", "plain", 2, {
steer: "steer",
route: steer,
});
await flush();
expect(process.prompts).toEqual(["first", "steer"]);
expect(process.models).toEqual(["haiku", "haiku"]);
expect(route).toHaveBeenCalledTimes(1);
expect(steer).not.toHaveBeenCalled();
process.finish();
await expect(first).resolves.toEqual({ ok: true });
await expect(second).resolves.toEqual({ ok: true });
});

it("sends nothing when a model route's choice was stopped", async () => {
const { pool, claudes } = sessions();
await expect(
pool.deliver("c/root", "hello", 1, { route: async () => undefined }),
).resolves.toEqual({ ok: true, undelivered: true });
expect(claudes().flatMap((process) => process.prompts)).toEqual([]);
});

it("runs any number of conversations at once", async () => {
const { pool, live } = sessions({ hold: true });
for (let index = 0; index < 12; index++)
Expand Down
11 changes: 11 additions & 0 deletions src/bundled/claude-code/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ type DeliveryOptions = Readonly<{
refresh?: (fresh?: boolean) => Promise<string>;
fresh?: () => Promise<string>;
pick?: TurnPick;
/** Chooses `pick` for a turn this message starts, asked once a process
* would take it as a new turn (`Delivery.route`); a steer asks nothing.
* Undefined sends nothing. */
route?: () => Promise<TurnPick | undefined>;
/** The thread whose history was supplied to a shared channel session. */
contextRoot?: string;
/** Rejects a turn the current settings can't start, asked after every
Expand Down Expand Up @@ -362,6 +366,7 @@ export class AgentSessions {
refresh,
fresh,
pick = {},
route,
contextRoot,
admit,
attribute,
Expand Down Expand Up @@ -414,6 +419,12 @@ export class AgentSessions {
}
if (attribute && !live.process.busy)
await this.attribute(key, live, attribute);
// Its model route chooses for a new turn only.
if (route && !live.process.busy) {
const chosen = await route();
if (!chosen) return { ok: true, undelivered: true };
pick = chosen;
}
if (current && !current()) return { ok: true, undelivered: true };
if (this.disposed)
return { ok: false, error: "Claude was stopped", undelivered: true };
Expand Down
Loading
Loading