
























@@ -745,26 +745,58 @@ function formatContextWindowLabel(tokens: number): string {
745745return `${Math.round(tokens / 1024)}k`;
746746}
747747748+function normalizePositiveContextTokens(value: unknown): number | undefined {
749+if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
750+return undefined;
751+}
752+return Math.floor(value);
753+}
754+755+function resolveAgentContextTokensForHint(params: {
756+cfg: FollowupRun["run"]["config"];
757+agentId?: string;
758+}): number | undefined {
759+const defaultContextTokens = normalizePositiveContextTokens(
760+params.cfg.agents?.defaults?.contextTokens,
761+);
762+const agentId = normalizeLowercaseStringOrEmpty(params.agentId);
763+const agentContextTokens = agentId
764+ ? normalizePositiveContextTokens(
765+params.cfg.agents?.list?.find(
766+(entry) => normalizeLowercaseStringOrEmpty(entry?.id) === agentId,
767+)?.contextTokens,
768+)
769+ : undefined;
770+return agentContextTokens ?? defaultContextTokens;
771+}
772+748773function resolveContextWindowForHint(params: {
749774cfg: FollowupRun["run"]["config"];
775+agentId?: string;
750776ref: ModelRefLike;
751777activeSessionEntry?: SessionEntry;
752778}) {
753-const activeContextTokens =
754-typeof params.activeSessionEntry?.contextTokens === "number" &&
755-Number.isFinite(params.activeSessionEntry.contextTokens) &&
756-params.activeSessionEntry.contextTokens > 0
757- ? Math.floor(params.activeSessionEntry.contextTokens)
758- : undefined;
759-return (
760-activeContextTokens ??
761-resolveContextTokensForModel({
762-cfg: params.cfg,
763-provider: params.ref.provider,
764-model: params.ref.model,
765-allowAsyncLoad: false,
766-})
779+const sessionContextTokens = normalizePositiveContextTokens(
780+params.activeSessionEntry?.contextTokens,
767781);
782+const modelContextTokens = resolveContextTokensForModel({
783+cfg: params.cfg,
784+provider: params.ref.provider,
785+model: params.ref.model,
786+allowAsyncLoad: false,
787+});
788+const contextTokens = modelContextTokens ?? sessionContextTokens;
789+if (contextTokens === undefined) {
790+return undefined;
791+}
792+793+const agentContextTokens = resolveAgentContextTokensForHint({
794+cfg: params.cfg,
795+agentId: params.agentId,
796+});
797+return agentContextTokens !== undefined
798+ ? Math.min(agentContextTokens, contextTokens)
799+ : contextTokens;
768800}
769801770802function resolveHeartbeatBleedHint(params: {
@@ -809,14 +841,14 @@ function resolveHeartbeatBleedHint(params: {
809841810842const runtimeWindow = resolveContextWindowForHint({
811843cfg: params.cfg,
844+agentId: params.agentId,
812845ref: runtimeRef,
813846activeSessionEntry: params.activeSessionEntry,
814847});
815-const primaryWindow = resolveContextTokensForModel({
848+const primaryWindow = resolveContextWindowForHint({
816849cfg: params.cfg,
817-provider: primaryRef.provider,
818-model: primaryRef.model,
819-allowAsyncLoad: false,
850+agentId: params.agentId,
851+ref: primaryRef,
820852});
821853if (
822854typeof runtimeWindow === "number" &&
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。