refactor(agents): hide context window thresholds

This commit is contained in:
Vincent Koc
2026-06-17 10:56:55 +08:00
parent 0da5861e74
commit 80238595ed
3 changed files with 13 additions and 18 deletions

View File

@@ -3,11 +3,9 @@ import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import {
CONTEXT_WINDOW_HARD_MIN_TOKENS,
CONTEXT_WINDOW_WARN_BELOW_TOKENS,
evaluateContextWindowGuard,
formatContextWindowBlockMessage,
formatContextWindowWarningMessage,
resolveContextWindowGuardThresholds,
resolveContextWindowInfo,
} from "./context-window-guard.js";
@@ -297,24 +295,22 @@ describe("context-window-guard", () => {
expect(guard.shouldBlock).toBe(false);
});
it("exports threshold floors as expected", () => {
it("exports the public hard-min floor as expected", () => {
expect(CONTEXT_WINDOW_HARD_MIN_TOKENS).toBe(4_000);
expect(CONTEXT_WINDOW_WARN_BELOW_TOKENS).toBe(8_000);
});
it("derives percentage-based thresholds above the safe floors", () => {
expect(resolveContextWindowGuardThresholds(1_000_000)).toEqual({
hardMinTokens: 100_000,
warnBelowTokens: 200_000,
it("derives percentage-based guard thresholds above the safe floors", () => {
const largeGuard = evaluateContextWindowGuard({
info: { tokens: 1_000_000, source: "model" },
});
expect(resolveContextWindowGuardThresholds(64_000)).toEqual({
hardMinTokens: 6_400,
warnBelowTokens: 12_800,
});
expect(resolveContextWindowGuardThresholds(Number.NaN)).toEqual({
hardMinTokens: 4_000,
warnBelowTokens: 8_000,
expect(largeGuard.hardMinTokens).toBe(100_000);
expect(largeGuard.warnBelowTokens).toBe(200_000);
const mediumGuard = evaluateContextWindowGuard({
info: { tokens: 64_000, source: "model" },
});
expect(mediumGuard.hardMinTokens).toBe(6_400);
expect(mediumGuard.warnBelowTokens).toBe(12_800);
});
it("derives guard thresholds from the reference window when capped", () => {

View File

@@ -9,7 +9,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveProviderEndpoint } from "./provider-attribution.js";
export const CONTEXT_WINDOW_HARD_MIN_TOKENS = 4_000;
export const CONTEXT_WINDOW_WARN_BELOW_TOKENS = 8_000;
const CONTEXT_WINDOW_WARN_BELOW_TOKENS = 8_000;
const CONTEXT_WINDOW_HARD_MIN_RATIO = 0.1;
const CONTEXT_WINDOW_WARN_BELOW_RATIO = 0.2;
@@ -125,7 +125,7 @@ function resolveContextWindowGuardHint(params: {
}
/** Derive warning/block floors from the resolved model context window. */
export function resolveContextWindowGuardThresholds(
function resolveContextWindowGuardThresholds(
contextWindowTokens: number,
): ContextWindowGuardThresholds {
const tokens = normalizePositiveInt(contextWindowTokens) ?? 0;

View File

@@ -701,7 +701,6 @@ export async function loadRunOverflowCompactionHarness(): Promise<{
vi.doMock("../context-window-guard.js", () => ({
CONTEXT_WINDOW_HARD_MIN_TOKENS: 1000,
CONTEXT_WINDOW_WARN_BELOW_TOKENS: 5000,
evaluateContextWindowGuard: mockedEvaluateContextWindowGuard,
formatContextWindowBlockMessage: mockedFormatContextWindowBlockMessage,
formatContextWindowWarningMessage: mockedFormatContextWindowWarningMessage,