swarm ui: one slider for the fresh-session threshold and the soft context limit
This commit is contained in:
parent
5175d3663e
commit
b16074e76b
1 changed files with 450 additions and 18 deletions
|
|
@ -1,5 +1,9 @@
|
|||
// The create form's and the inference dialog's `soft_context_percent` field,
|
||||
// kept out of the component so `npm test` can run it.
|
||||
// The create form's and the inference dialog's context limits, kept out of the
|
||||
// components so `npm test` can run them: the `soft_context_percent` field (the
|
||||
// agent compacts above it) and the `fresh_session_percent` field (above it, a
|
||||
// turn that finds the prompt cache cold starts a fresh session), and the slider
|
||||
// that moves both. Each is the text of its box, where empty keeps the agent's
|
||||
// own value.
|
||||
|
||||
/** The lowest `soft_context_percent` the swarm accepts. */
|
||||
export const MIN_SOFT_CONTEXT_PERCENT = 5;
|
||||
|
|
@ -20,3 +24,75 @@ export function softContextValue(text: string): number | null | undefined {
|
|||
? n
|
||||
: null;
|
||||
}
|
||||
|
||||
/** What the harness uses for the fresh-session threshold when none is set. */
|
||||
export const DEFAULT_FRESH_SESSION_PERCENT = 50;
|
||||
/** What the harness uses for the soft limit when none is set. */
|
||||
export const DEFAULT_SOFT_CONTEXT_PERCENT = 75;
|
||||
|
||||
/** The two limits as the slider draws them. */
|
||||
export interface Limits {
|
||||
/** Where the fresh-session handle sits. */
|
||||
fresh: number;
|
||||
/** Where the soft-limit handle sits. */
|
||||
soft: number;
|
||||
/** Whether the swarm sets the fresh-session threshold, or the agent's own applies. */
|
||||
freshSet: boolean;
|
||||
/** Whether the swarm sets the soft limit. */
|
||||
softSet: boolean;
|
||||
}
|
||||
|
||||
function percentOf(text: string): number | undefined {
|
||||
const v = softContextValue(text);
|
||||
return typeof v === "number" ? v : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the handles sit: a set value where there is one, else the harness's own
|
||||
* default. An unset fresh-session threshold never sits above the soft limit
|
||||
* (the agent compacts there, so the context would not get past it), and a
|
||||
* typed value that is not a valid percent counts as unset.
|
||||
*/
|
||||
export function limitsOf(freshText: string, softText: string): Limits {
|
||||
const freshValue = percentOf(freshText);
|
||||
const softValue = percentOf(softText);
|
||||
const soft = softValue ?? DEFAULT_SOFT_CONTEXT_PERCENT;
|
||||
const fresh = freshValue ?? Math.min(DEFAULT_FRESH_SESSION_PERCENT, soft);
|
||||
return {
|
||||
fresh,
|
||||
soft,
|
||||
freshSet: freshValue !== undefined,
|
||||
softSet: softValue !== undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/** Where the fresh-session handle may go: not past the soft handle. */
|
||||
export function clampFresh(to: number, limits: Limits): number {
|
||||
return Math.min(
|
||||
Math.max(Math.round(to), MIN_SOFT_CONTEXT_PERCENT),
|
||||
limits.soft,
|
||||
);
|
||||
}
|
||||
|
||||
/** Where the soft handle may go: not below the fresh-session handle. */
|
||||
export function clampSoft(to: number, limits: Limits): number {
|
||||
return Math.min(
|
||||
Math.max(Math.round(to), limits.fresh, MIN_SOFT_CONTEXT_PERCENT),
|
||||
MAX_SOFT_CONTEXT_PERCENT,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Why the two boxes are refused together: a fresh-session threshold above the
|
||||
* soft limit, both set. Each box's own range is `draftProblem`'s.
|
||||
*/
|
||||
export function crossProblem(
|
||||
freshText: string,
|
||||
softText: string,
|
||||
): string | null {
|
||||
const fresh = percentOf(freshText);
|
||||
const soft = percentOf(softText);
|
||||
return fresh !== undefined && soft !== undefined && fresh > soft
|
||||
? `the fresh-session threshold (${fresh}%) is above the soft limit (${soft}%): the agent compacts at the soft limit, so a fresh start above it would never happen`
|
||||
: null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue