import type { OpenClawConfig } from "../config/types.openclaw.js"; import { resolveProviderEndpoint } from "./provider-attribution.js"; import { findNormalizedProviderValue } from "./provider-id.js";
export function formatContextWindowWarningMessage(params: {
provider: string;
modelId: string;
guard: ContextWindowGuardResult;
runtimeBaseUrl?: string | null;
}): string { const base = `low context window: ${params.provider}/${params.modelId} ctx=${params.guard.tokens} (warn<${CONTEXT_WINDOW_WARN_BELOW_TOKENS}) source=${params.guard.source}`; const hint = resolveContextWindowGuardHint({ runtimeBaseUrl: params.runtimeBaseUrl }); if (!hint.likelySelfHosted) { return base;
} if (params.guard.source === "agentContextTokens") { return (
`${base}; OpenClaw is capped by agents.defaults.contextTokens, so raise that cap ` +
`if you want to use more of the model context window`
);
} if (params.guard.source === "modelsConfig") { return (
`${base}; OpenClaw is using the configured model context limit forthis model, ` +
`so raise contextWindow/contextTokens if it is set too low`
);
} return (
`${base}; local/self-hosted runs work best at ` +
`${CONTEXT_WINDOW_WARN_BELOW_TOKENS}+ tokens and may show weaker tool use or more compaction until the server/model context limit is raised`
);
}
export function formatContextWindowBlockMessage(params: {
guard: ContextWindowGuardResult;
runtimeBaseUrl?: string | null;
}): string { const base =
`Model context window too small (${params.guard.tokens} tokens; ` +
`source=${params.guard.source}). Minimum is ${CONTEXT_WINDOW_HARD_MIN_TOKENS}.`; const hint = resolveContextWindowGuardHint({ runtimeBaseUrl: params.runtimeBaseUrl }); if (!hint.likelySelfHosted) { return base;
} if (params.guard.source === "agentContextTokens") { return `${base} OpenClaw is capped by agents.defaults.contextTokens. Raise that cap.`;
} if (params.guard.source === "modelsConfig") { return (
`${base} OpenClaw is using the configured model context limit forthis model. ` +
`Raise contextWindow/contextTokens or choose a larger model.`
);
} return (
`${base} This looks like a local model endpoint. ` +
`Raise the server/model context limit or choose a larger model. ` +
`OpenClaw local/self-hosted runs work best at ${CONTEXT_WINDOW_WARN_BELOW_TOKENS}+ tokens.`
);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.