Repository navigation
feat(agent): 256K default context window capped per model; compaction scales with the window; MAX_STEPS 12, configurable - #228
Merged
Conversation
…n scales with the window; MAX_STEPS 12 and configurable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做了什么
上下文窗口从写死 64k 改成默认 256K(262144),按模型封顶;压缩阈值随窗口按比例走;MAX_STEPS 默认 12 且可配置。
packages/core/src/llm-context.ts(新):DEFAULT_CONTEXT_WINDOW_TOKENS = 262144;KNOWN_CONTEXT_LIMITS模型上限表(去网关前缀、小写匹配,覆盖全部内置预设模型);resolveContextWindow/agentContextWindow= min(服务context_window→ 全局agent_context_window→ 256K, 模型已知上限)。未知模型用配置值,溢出仍走原有「报超长 → 狠压一次重试」。compaction.ts:compactionPolicyFor(window),预留 = 窗口 × 1/8、保留最近 = 窗口 × 1/4(旧 64k/8k/16k 的比例);DEFAULT_COMPACTION= 256K 那一点(预留 32768、保留 65536)。host.ts:每个 Run 按所选模型算窗口,compaction默认compactionPolicyFor(contextWindow);llm_runtime记context_window/max_steps。新 depscontextWindow/defaultMaxSteps(只改了常量、startRun 的 maxSteps 一行和 llm 解析后两行,没碰 emit / reasoning 分支)。agent/limits.ts:MAX_STEPS = 12、normalizeMaxSteps(1–40);请求max_steps> 设置agent_max_steps> 12。config.ts:设置 JSON 加agent_context_window(0 = 默认)、agent_max_steps(默认 12)、llm_api_configs[].context_window(0 = 未设)。只是设置 JSON 字段,不动 SQLite 表结构。GET /api/agent/runtime/models:每个模型多context_limit(已知上限 / null)和context_window(当前设置下的实际窗口)。测试
backend-ts/test/agent-context-window.test.ts(10 个):默认 / 封顶 / 配置优先级、预设模型全有上限、目录字段、比例、40K token 输入在 256K 不压而 32K 模型会压、提示词「最多调用 12 轮工具」、设置归一化、经 /api/config 的 run 实际窗口与步数。agent-models.test.ts更新目录断言。tsc --noEmit✅;vitest run29 files / 216 tests 全过。